-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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: BoundRegion { var: 0, kind: BrNamed(DefId(0:9 ~ rust_bug[3fc9]::or::'a), 'a) } is a region but value is Type(_) #91801
Comments
fn or<'a>(first: &'static (dyn Fn(&'a i32))) -> dyn Fn(&'a i32) {
return Box::new(panic!());
} This ICEs in the playground, but interestingly, this does not fn or<'a>(first: &'static (dyn Fn(&'a i32))) -> dyn Fn(&'a i32) {
Box::new(panic!())
} Also, the |
also... trait Foo<'a> {}
fn or<'a>(first: &'static dyn Foo<'a>) -> dyn Foo<'a> {
return Box::new(panic!());
} also ICEs but it's a different ICE. Fun! I'll go report that. |
Reported that ICE as #91803, the root cause might be similar. |
Thanks for all the help @5225225! |
Bisected this Looks like
is the new error. |
Fix late-bound ICE in `dyn` return type suggestion This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (`let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };`) makes sure we're grabbing the _right_ return type for this suggestion to check the `dyn` predicates with. Fixes rust-lang#91801 Fixes rust-lang#91803 This fix also includes some drive-by changes, specifically: 1. Don't suggest boxing when we have `-> dyn Trait` and are already returning `Box<T>` where `T: Trait` (before we always boxed the value). 2. Suggestion applies even when the return type is a type alias (e.g. `type Foo = dyn Trait`). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial. 3. Split up the multipart suggestion because there's a 6-line max in the printed output... I am open to splitting out the above changes, if we just want to fix the ICE first. cc: `@terrarier2111` and rust-lang#92289
Fix late-bound ICE in `dyn` return type suggestion This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (`let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };`) makes sure we're grabbing the _right_ return type for this suggestion to check the `dyn` predicates with. Fixes rust-lang#91801 Fixes rust-lang#91803 This fix also includes some drive-by changes, specifically: 1. Don't suggest boxing when we have `-> dyn Trait` and are already returning `Box<T>` where `T: Trait` (before we always boxed the value). 2. Suggestion applies even when the return type is a type alias (e.g. `type Foo = dyn Trait`). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial. 3. Split up the multipart suggestion because there's a 6-line max in the printed output... I am open to splitting out the above changes, if we just want to fix the ICE first. cc: ``@terrarier2111`` and rust-lang#92289
I don't have much context on this, was doing some thinkering on what would be the best way to do something not really interesting, and got this ICE. This bug happens on both Nightly and Stable.
Code
This is the original code I managed to replicate the issue:
This code fails with the ICE error. Removing the
return
on the Box of theor
function turns it from an ICE to a normal compiler error.A member on the Rust discord (@5225225) also reported that this, more minimal test case also returns the same error:
Meta
rustc +nightly --version --verbose
:rustc +stable --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: