-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
ICE with Const Generics cast of self in supertrait list #70167
Comments
minimized: #![feature(const_generics)]
pub trait Trait<const N: usize>: From<<Self as Trait<N>>::Item> {
type Item;
} @rustbot claim |
Looks like maybe constants in trait paths don't get their type correctly? |
Initially I thought this was about bounds but no, this also fails: (playground) #![feature(const_generics)]
pub trait Trait<const N: usize> {
type Item;
const VAL: <Self as Trait<N>>::Item;
} |
I believe this code is responsible: rust/src/librustc_typeck/collect/type_of.rs Lines 285 to 287 in 5f13820
And the problem is that this doesn't handle associated types which need the same treatment: rust/src/librustc_typeck/collect/type_of.rs Lines 259 to 261 in 5f13820
|
Alternatively, instead of using Actually, I expect #![feature(const_generics)]
struct Struct<const N: usize>;
impl<const N: usize> Struct<N> {
fn method<const M: usize>(&self) {}
}
fn test<const N: usize, const M: usize>(x: Struct<N>) {
Struct::<N>::method::<M>(&x);
x.method::<N>();
} EDIT: took a second look and that Maybe we should disallow passing explicit generic args to methods for now? |
fix type of const params in associated types. fixes rust-lang#66906 fixes rust-lang#70167 r? @eddyb
@varkor @yodaldevoid If you look at this later btw, my comment above (#70167 (comment)) still isn't addressed, but I haven't made an issue yet about it. |
I was writing some generic code over vectors using the under-construction feature of const generics, and had a circular chain of super-traits that required me to cast the Self type to the trait as can be seen in the
Div
supertrait requirement. I believe that is causing the MIR error.I think this may be related to #66906 but it is subtly different so I'm putting the issue up regardless.
Code
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=3856486297085a463f98c2fc9f9a99c6
Meta
rustc --version --verbose
:I updated my rust version on nightly right before I ran this so hopefully it is up to date:
Error output
Backtrace
This issue has been assigned to @lcnr via this comment.
The text was updated successfully, but these errors were encountered: