-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix type of const params in assoc fns. #70276
Conversation
} | ||
|
||
fn main() { | ||
let _err = <S as T<0usize>>::f(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<S as T<123>>::f::<456>()
should also work, if you added a const param to f
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will add a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean you'll need to implement it, it won't work with the current approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for whatever reason adding a const param to f actually prevents the ice. not quite sure why, but this is new behavior so lets add a test for it
The following works on the current nightly.
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
trait T<const A: usize> {
fn l<const N: usize>() -> usize;
fn r<const N: usize>() -> usize;
}
struct S;
impl<const N: usize> T<N> for S {
fn l<const M: usize>() -> usize { N }
fn r<const M: usize>() -> usize { M }
}
fn main() {
assert_eq!(<S as T<123>>::l::<456>(), 123);
assert_eq!(<S as T<123>>::r::<456>(), 456);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, oops, it's because both the trait and the method have the exact same number of parameters and the same types. Make one of them a bool
instead of usize
, then you should see how it thinks the method segment has the trait's parameter (which is wrong).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jup. Quite surprisingly, using usize and u16 works 🤔
but using bool
and usize
does not work on nightly rn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because the integer literals will work with any integer type.
I am going to experiment with using the res of the segment instead of the path. Closing this for now as I don't know how long this will take. |
…r=eddyb correctly handle const params in type_of extends rust-lang#70223, retry of rust-lang#70276 fixes rust-lang#70273 r? @eddyb cc @varkor
…r=eddyb correctly handle const params in type_of extends rust-lang#70223, retry of rust-lang#70276 fixes rust-lang#70273 r? @eddyb cc @varkor
…r=eddyb correctly handle const params in type_of extends rust-lang#70223, retry of rust-lang#70276 fixes rust-lang#70273 r? @eddyb cc @varkor
extends and blocked on #70223
fixes #70273
r? @eddyb cc @varkor