Skip to content

gccrs: This is an utterly insane rustc shim needed for stdarch - #4889

Open
philberty wants to merge 1 commit into
masterfrom
phil/legacy-const-generics
Open

gccrs: This is an utterly insane rustc shim needed for stdarch#4889
philberty wants to merge 1 commit into
masterfrom
phil/legacy-const-generics

Conversation

@philberty

Copy link
Copy Markdown
Member

This doesnt fully implement the legacy const generics attribute but its the starting point.

What we actually need to do is understand:

#[rustc_legacy_const_generics(1)]
fn foo<const N: usize>(x: i32) -> i32 {
    x + N as i32
}

fn main() {
    let a = foo(10, 3);
}

So you can see the call to foo has a 2nd param but its not a real 2nd param its meant to be turned into:

foo::<3>(10)

Honestly this is just silly they probably implemented a bit of const generics wanted to use it in core and put this work around in to get away with it. Dumb.

Addresses #3868

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules): fix bad const cast
* util/rust-attribute-values.h: add attribute
* util/rust-attributes.cc: likewise

This doesnt fully implement the legacy const generics attribute but its
the starting point.

What we actually need to do is understand:

    #[rustc_legacy_const_generics(1)]
    fn foo<const N: usize>(x: i32) -> i32 {
        x + N as i32
    }

    fn main() {
        let a = foo(10, 3);
    }

So you can see the call to foo has a 2nd param but its not a real 2nd param
its meant to be turned into:

    foo::<3>(10)

Honestly this is just silly they probably implemented a bit of const
generics wanted to use it in core and put this work around in to get away
with it. Dumb.

Addresses #3868

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): fix bad const cast
	* util/rust-attribute-values.h: add attribute
	* util/rust-attributes.cc: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty added the core Issue related to the compilation of the `core` crate label Sep 11, 2026

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM, just the issue number in the commit and it's all good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issue related to the compilation of the `core` crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants