-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix type of const params in assoc fns. #70276
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// check-pass | ||
|
||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash | ||
|
||
trait T<const A: usize> { | ||
fn f(); | ||
} | ||
struct S; | ||
|
||
impl T<0usize> for S { | ||
fn f() {} | ||
} | ||
|
||
fn main() { | ||
let _err = <S as T<0usize>>::f(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jup. Quite surprisingly, using usize and u16 works 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because the integer literals will work with any integer type. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/issue70273-assoc-fn.rs:3:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
Uh oh!
There was an error while loading. Please reload this page.