-
Notifications
You must be signed in to change notification settings - Fork 13k
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: "Missing value for constant, but no error reported?" with uncomputable layout due to trivial bounds #135138
Comments
I was investigating this ICE. |
This should probably just fail to compile, similar to how it fails to compile when the layout of a local variable in a constant cannot be computed for some other reason. For example this fn return_str() {
[(); { let _a: Option<[u8; usize::MAX]> = None; 0 }];
} fails with
so the code from the issue could report something like this for example
|
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
…or, r=FedericoBruzzone,oli-obk fix ICE with references to infinite structs in consts fixes rust-lang#114484 Normalizing `<Type as Pointee>::Metadata` may emit a (non-fatal) error during trait selection if finding the struct tail of `Type` hits the recursion limit. When this happens, prior this PR, we would treat the projection as rigid, i.e. don't normalize it further. This PR changes it so that we normalize to `ty::Error` instead. This is important, because to compute the layout of `&Type` we need to compute the layout of `<Type as Pointee>::Metadata` https://github.com/rust-lang/rust/blob/2ae9916816a448fcaab3b2da461de754eda0055a/compiler/rustc_ty_utils/src/layout.rs#L247-L273 and computing the layout of a rigid alias will (correctly) fail and needs to report an error to the user. For example: ```rust trait Project { type Assoc; } fn foo<T: Project>() { [(); { let _: Option<T::Assoc> = None; // ^^^^^^^^ this projection is rigid, so we can't know it's layout 0 }]; } ``` ``` error: constant expression depends on a generic parameter --> src/lib.rs:6:10 | 6 | [(); { | __________^ 7 | | let _: Option<T::Assoc> = None; 8 | | // ^^^^^^^^ this projection is rigid, so we can't know it's layout 9 | | 0 10 | | }]; | |_____^ | = note: this may fail depending on what value the parameter takes ``` For non-generic rigid projections we will currently ICE, because we incorrectly assume that `LayoutError::Unknown` means that a const must be generic (rust-lang#135138). This is being fixed and turned into a proper error in rust-lang#135158. ```rust #![feature(trivial_bounds)] trait Project { type Assoc; } fn foo() where u8: Project, { [(); { let _: Option<<u8 as Project>::Assoc> = None; // ICEs currently, but will be an error 0 }]; } ``` However, if we hit the recursion limit when normalizing `<Type as Pointee>::Metadata` we don't want to report a layout error, because we already emitted the recursion error. So by normalizing to `ty::Error` here, we get a `LayoutError::ReferencesError` instead of a `LayoutError::Unknown` and don't report the layout error to the user.
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
Rollup merge of rust-lang#135464 - lukas-code:project-infinite-to-error, r=FedericoBruzzone,oli-obk fix ICE with references to infinite structs in consts fixes rust-lang#114484 Normalizing `<Type as Pointee>::Metadata` may emit a (non-fatal) error during trait selection if finding the struct tail of `Type` hits the recursion limit. When this happens, prior this PR, we would treat the projection as rigid, i.e. don't normalize it further. This PR changes it so that we normalize to `ty::Error` instead. This is important, because to compute the layout of `&Type` we need to compute the layout of `<Type as Pointee>::Metadata` https://github.com/rust-lang/rust/blob/2ae9916816a448fcaab3b2da461de754eda0055a/compiler/rustc_ty_utils/src/layout.rs#L247-L273 and computing the layout of a rigid alias will (correctly) fail and needs to report an error to the user. For example: ```rust trait Project { type Assoc; } fn foo<T: Project>() { [(); { let _: Option<T::Assoc> = None; // ^^^^^^^^ this projection is rigid, so we can't know it's layout 0 }]; } ``` ``` error: constant expression depends on a generic parameter --> src/lib.rs:6:10 | 6 | [(); { | __________^ 7 | | let _: Option<T::Assoc> = None; 8 | | // ^^^^^^^^ this projection is rigid, so we can't know it's layout 9 | | 0 10 | | }]; | |_____^ | = note: this may fail depending on what value the parameter takes ``` For non-generic rigid projections we will currently ICE, because we incorrectly assume that `LayoutError::Unknown` means that a const must be generic (rust-lang#135138). This is being fixed and turned into a proper error in rust-lang#135158. ```rust #![feature(trivial_bounds)] trait Project { type Assoc; } fn foo() where u8: Project, { [(); { let _: Option<<u8 as Project>::Assoc> = None; // ICEs currently, but will be an error 0 }]; } ``` However, if we hit the recursion limit when normalizing `<Type as Pointee>::Metadata` we don't want to report a layout error, because we already emitted the recursion error. So by normalizing to `ty::Error` here, we get a `LayoutError::ReferencesError` instead of a `LayoutError::Unknown` and don't report the layout error to the user.
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
- `check-pass` test for a MRE of rust-lang#135020 - fail test for rust-lang#135138 - switch to `TooGeneric` for checking CMSE fn signatures - switch to `TooGeneric` for compute `SizeSkeleton` (for transmute) - fix broken tests
Code
playground
Meta
rustc --version --verbose
:Error output
Backtrace
Analysis
This happens, because after #129970, computing the layout of
Option<str>
will returnLayoutError::Unknown
...rust/compiler/rustc_ty_utils/src/layout.rs
Lines 103 to 113 in 3323bbe
... which is turned into
ErrorHandled::TooGeneric
...rust/compiler/rustc_const_eval/src/const_eval/error.rs
Lines 143 to 145 in 3323bbe
... which is turned into
EvaluateConstErr::HasGenericsOrInfers
...rust/compiler/rustc_trait_selection/src/traits/mod.rs
Line 640 in 3323bbe
... wich will cause a delayed bug, because the const doesn't actually have generics or infers:
rust/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Lines 126 to 140 in 3323bbe
The text was updated successfully, but these errors were encountered: