-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Attempting to store function callback of a particular incorrect type produces ICE #140823
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
Comments
Confirmed #134977 is the culprit. Specifically the following in rust/compiler/rustc_hir_typeck/src/demand.rs Lines 826 to 827 in 16244bc
Looking at the rustc logs this is the original error which is being expanded upon:
so here
and crashes because
ICE Backtrace
I'm not sure if there are other scenarios that could reliably trigger this behavior. At least for the example in this issue it appears to center around lifetimes with HRTB. Can make the lifetimes more explicit like so: //! This will reproduce the same ICE
trait MyFn<P> {}
struct Container<T> {
data: T,
}
struct Desugared {
// ICE also reproduces with for <'a, 'b>
callback: Box<dyn for<'a> MyFn<&'a Container<&'a u8>>>,
}
fn ice(callback: Box<dyn for<'a> MyFn<Container<&'a u8>>>) -> Desugared {
Desugared { callback }
} Compare this to a version that does not reproduce the error by removing the HRTB on the initial value struct Desugared {
callback: Box<dyn for<'a> MyFn<&'a Container<&'a u8>>>,
}
fn no_ice<'a>(callback: Box<dyn MyFn<Container<&'a u8>>>) -> Desugared {
Desugared { callback }
} In this case it doesn't trigger the issue because it doesn't have a rolled back lifetime variable in
|
Rollup merge of rust-lang#141236 - jagunter:issue-140823, r=compiler-errors Resolved issue with mismatched types triggering ICE in certain scenarios ## Background The function `annotate_mut_binding_to_immutable_binding` called in `emit_coerce_suggestions` performs a type comparison between the `expected` and `found` types from `ExpectedFound` in the `TypeError`. This can fail if the `found` type contains a region variable that's been rolled back. ## What is being changed? This updates `annotate_mut_binding_to_immutable_binding` to use `expr_ty` and `expected` from the parent function instead of the types from the `TypeError`. This sidesteps the issue of using `found` from `TypeError` which may leak lingering inference region variables. This does change the diagnostic behavior to _only_ support cases where the expected outermost type is `&T`, but that seems to be the intended functionality. Also fixed the example in the `annotate_mut_binding_to_immutable_binding` rustdocs. r? rust-lang/types Fixes rust-lang#140823
Code
Notes:
&Container<...>
vsContainer<....>
)Container
needs to take a generic argument to repro, and the argument value needs to be a reference. UsingContainer<u8>
orContainer<Vec<u8>>
does not repro.fails
andcallback
not repro.Container
with real containers likeVec
orVecDeque
Meta
rustc --version --verbose
:Confirmed bug reproduces on nightly. Traces are from stable.
Error output
Backtrace
Without RUST_BACKTRACE=1
Including since there's a stacktrace here that doesn't appear otherwise
With RUST_BACKTRACE=1
The text was updated successfully, but these errors were encountered: