-
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 using const_generics_defaults #83938
Comments
Issue: rust-lang/rust#83938
while still ICE'ing, the error output is different now: #![feature(const_evaluatable_checked, const_generics, const_generics_defaults)]
#![allow(incomplete_features)]
pub struct Bar<const N: usize, const M: usize = { N + 1 }>;
pub fn foo<const N1: usize>() -> Bar<N1> { loop {} }
fn main() {} output:
I believe the issue here is that when we build the substs for @rustbot claim |
dont provide fwd declared params to cg defaults Fixes rust-lang#83938 ```rust #![feature(const_evaluatable_checked, const_generics, const_generics_defaults)] #![allow(incomplete_features)] pub struct Bar<const N: usize, const M: usize = { N + 1 }>; pub fn foo<const N1: usize>() -> Bar<N1> { loop {} } fn main() {} ``` This PR makes this code no longer ICE, it was ICE'ing previously because when building substs for `Bar<N1>` we would subst the anon ct: `ConstKind::Unevaluated({N + 1}, substs: [N, M])` with substs of `[N1]`. the anon const has forward declared params supplied though so we end up trying to substitute the provided `M` param which causes the ICE. This PR doesn't handle the predicates of the const so ```rust trait Foo<const N: usize> { const Assoc: usize; } pub struct Bar<const N: usize = { <()>::Assoc }> where (): Foo<N>; ``` Resolves to `<() as Foo<N>>::Assoc` which can allow for using fwd declared params indirectly. ```rust trait Foo<const N: usize> {} struct Bar<const N: usize = { 2 + 3 }> where (): Foo<N>; ``` This code also ICEs under this PR because instantiating the default's predicates causes an ICE as predicates_of contains predicates with fwd declared params PR was briefly discussed [in this zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/evil.20preds.20in.20param.20env.20.2386580)
Code
(Playground link)
I'm not sure how to treat this. It seems that we can sneakily misuse defaults in type definitions to insert a dependent computation on a const parameter which definitely should be forbidden at the moment.
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: