GCC Rust Weekly Status Report 46

Thanks again to Open Source Security, inc and Embecosm for their ongoing support for this project.

Milestone Progress

We have achieved a major step this week by merging the work required to get slices working. This long battle has exposed many flaws in our implementation of generics which have now been fixed, and is bringing us closer and closer to compiling an early version of the core Rust library. We are still going through a first dive into a privacy/visibility set of visitors, which will allow us to report privacy errors properly. Finally, we have also started looking into metadata exports which will allow us to use items from multiple crates compiled together. As a side note, our OSX support was broken and is now fixed thanks to a new contributor. The system has been added as a target to our CI to make sure it does not happen again.

Completed Activities

  • Move `cfg!()` macro to builtins. Fixes #1039 PR1116
  • rust: Use -Otarget when building and logging warnings PR1114
  • macros: Add env! macro PR1113
  • rust: Clang/macOS Testing PR1112
  • Add AST Private Visibilities PR1111
  • Add Reachability visitors for items with generics PR1110
  • rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++ PR1109
  • Add missing unify rules for inference variables PR1108
  • macros: fix an infinite loop in `concat!` macro parser PR1106
  • Lower AST::Visibility to HIR::Visibility properly PR1103
  • Add helper as_string for DefIds PR1101
  • Add known lang item const_slice_ptr mappings PR1100
  • Fix bad inherent overlap error PR1099
  • Ensure unsize method resolutions actually unsize PR1098
  • Support mangling \*const ptr and slices like \*const [T] PR1097
  • Add -frust-edition flag and possible values PR1091
  • macros: add concat! macro PR1090
  • rust-session-manager: better crate name handling logic PR1088
  • Slice support PR1086
  • Add base for privacy visitor PR1082

Contributors this week

Overall Task Status

CategoryLast WeekThis WeekDelta
In Progress2423-1
GitHub Issues

Test Cases

CategoryLast WeekThis WeekDelta
make check-rust


CategoryLast WeekThis WeekDelta
In Progress1013+2
GitHub Bugs

Milestones Progress

MilestoneLast WeekThis WeekDeltaStart DateCompletion DateTarget
Data Structures 1 – Core100%100%30th Nov 202027th Jan 202129th Jan 2021
Control Flow 1 – Core100%100%28th Jan 202110th Feb 202126th Feb 2021
Data Structures 2 – Generics100%100%11th Feb 202114th May 202128th May 2021
Data Structures 3 – Traits100%100%20th May 202117th Sept 202127th Aug 2021
Control Flow 2 – Pattern Matching100%100%20th Sept 20219th Dec 202129th Nov 2021
Macros and cfg expansion100100%1st Dec 202131st Mar 202228th Mar 2022
Imports and Visibility0%35%+3529th Mar 202227th May 2022
Const Generics0%0%30th May 202225th Jul 2022
Intrinsics0%0%6th Sept 202130th Sept 2022
GitHub Milestones


RiskImpact (1-3)Likelihood (0-10)Risk (I * L)Mitigation
Rust Language Changes3721Keep up to date with the Rust language on a regular basis
Going over target dates2510Maintain status reports and issue tracking to stakeholders

Planned Activities

  • Continue work into privacy pass
  • Continue work on metadata exports

Detailed changelog

Slices support

We finally got slice generation support merged, this is the extracted code from Rustc libcore 1.49.0. The key thing here is that this test case exposed lots of bugs in our type resolution system so working through this was pretty key. We are working on a blog post to explain how this works, as slice generation is actually implemented via the trick of unsized method resolution and clever use of libcore. For now please review the code below and you can see the slice generation via passing a range to the array index expression kicks off the array index operator overload for a Range<usize> as the entry point which uses the generic higher-ranked trait bound.

// { dg-additional-options "-w" }
extern "rust-intrinsic" {
    pub fn offset<T>(dst: *const T, offset: isize) -> *const T;

struct FatPtr<T> {
    data: *const T,
    len: usize,

union Repr<T> {
    rust: *const [T],
    rust_mut: *mut [T],
    raw: FatPtr<T>,

#[lang = "Range"]
pub struct Range<Idx> {
    pub start: Idx,
    pub end: Idx,

#[lang = "const_slice_ptr"]
impl<T> *const [T] {
    pub const fn len(self) -> usize {
        let a = unsafe { Repr { rust: self }.raw };

    pub const fn as_ptr(self) -> *const T {
        self as *const T

#[lang = "const_ptr"]
impl<T> *const T {
    pub const unsafe fn offset(self, count: isize) -> *const T {
        unsafe { offset(self, count) }

    pub const unsafe fn add(self, count: usize) -> Self {
        unsafe { self.offset(count as isize) }

    pub const fn as_ptr(self) -> *const T {
        self as *const T

const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
    unsafe {
        Repr {
            raw: FatPtr { data, len },

#[lang = "index"]
trait Index<Idx> {
    type Output;

    fn index(&self, index: Idx) -> &Self::Output;

pub unsafe trait SliceIndex<T> {
    type Output;

    unsafe fn get_unchecked(self, slice: *const T) -> *const Self::Output;

    fn index(self, slice: &T) -> &Self::Output;

unsafe impl<T> SliceIndex<[T]> for Range<usize> {
    type Output = [T];

    unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] {
        unsafe {
            let a: *const T = slice.as_ptr();
            let b: *const T = a.add(self.start);
            slice_from_raw_parts(b, self.end - self.start)

    fn index(self, slice: &[T]) -> &[T] {
        unsafe { &*self.get_unchecked(slice) }

impl<T, I> Index<I> for [T]
    I: SliceIndex<[T]>,
    type Output = I::Output;

    fn index(&self, index: I) -> &I::Output {

fn main() -> i32 {
    let a = [1, 2, 3, 4, 5];
    let b = &a[1..3];


see: https://godbolt.org/z/csn8hMej8

More built-in macros

Our first builtin macro, cfg!, has been moved with the rest of the builtin macros: It can now benefit from the other helper functions we have developed in this module to help consuming tokens and generating AST fragments. Two new macros have also been added:

  1. concat!, which allows the concatenation of literal tokens at compile-time
concat!("hey", 'n', 0, "w"); // expands to "heyn0w"
  1. env!, which allows fetching environment variables during compilation.
let path = env!("PATH");
// expands to the content of the user's path when they invoked `gccrs`

env! is interesting as it is one of the first built-in with an optional extra argument: You can specify an extra error message to display if the variable is not present.

macro_rules! env {
    ($name:expr $(,)?) => { ... };
    ($name:expr, $error_msg:expr $(,)?) => { ... };

This enables us to start looking into properly checking for multiple “matchers” in builtins, and parse and fetch them accordingly.

A lot of built-in macros remain to implement, and we’d love for you to have a go at them if you’re interested! Feel free to drop by our Zulip or ask on GitHub for any question you might have.

Leave a Reply

Your email address will not be published.