-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #115384 - lqd:default-universe-info, r=matthewjasper
Work around ICE in diagnostics for local super-universes missing `UniverseInfo`s In issue #114907, canonicalization of liveness dropck-outlives results (IIUC) encounters universes absent from the original query. Some local universes [are created](https://github.com/lqd/rust/blob/f3a1bae88c617330b8956818da3cea256336c1cf/compiler/rustc_infer/src/infer/canonical/query_response.rs#L417-L425) for the mapping, but importantly, they won't have associated causes. These missing `UniverseInfo`s can be [needed](https://github.com/lqd/rust/blob/f3a1bae88c617330b8956818da3cea256336c1cf/compiler/rustc_borrowck/src/diagnostics/region_errors.rs#L376) during diagnostics, [causing the `IndexMap: key not found` ICE](https://github.com/lqd/rust/blob/d55522aad87c5605d7edd5dd4b37926e8b446117/compiler/rustc_borrowck/src/region_infer/mod.rs#L2252) seen in the issue. This PR works around this by returning the suboptimal catch-all cause, to avoid the ICE. It does results in suboptimal diagnostics right now, but it's better than an ICE. r? `@matthewjasper.` Let me know if there's a good easy-ish way to fix this, but I believe that for some of these erroneous cases and diagnostics, that inference/canonicalization/higher-ranked subtyping/etc may not behave exactly the same with the new trait solver? If that's the case then it'd probably be best to wait a bit more to do the correct fix. Fixes #114907. cc `@aliemjay`
- Loading branch information
Showing
5 changed files
with
132 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// This is a non-regression test for issue #114907 where an ICE happened because of missing | ||
// `UniverseInfo`s accessed during diagnostics. | ||
// | ||
// A couple notes: | ||
// - the `FnOnce` bounds need an arg that is a reference | ||
// - a custom `Drop` is needed somewhere in the type that `accept` returns, to create universes | ||
// during liveness and dropck outlives computation | ||
|
||
// check-fail | ||
|
||
trait Role { | ||
type Inner; | ||
} | ||
|
||
struct HandshakeCallback<C>(C); | ||
impl<C: FnOnce(&())> Role for HandshakeCallback<C> { | ||
type Inner = (); | ||
} | ||
|
||
struct Handshake<R: Role> { | ||
_inner: Option<R::Inner>, | ||
} | ||
impl<R: Role> Drop for Handshake<R> { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
fn accept<C: FnOnce(&())>(_: C) -> Handshake<HandshakeCallback<C>> { | ||
todo!() | ||
} | ||
|
||
fn main() { | ||
let callback = |_| {}; | ||
accept(callback); | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
//~| ERROR implementation of `FnOnce` is not general enough | ||
//~| ERROR implementation of `FnOnce` is not general enough | ||
//~| ERROR higher-ranked subtype error | ||
//~| ERROR higher-ranked subtype error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/missing-universe-cause-issue-114907.rs:33:5 | ||
| | ||
LL | accept(callback); | ||
| ^^^^^^^^^^^^^^^^ one type is more general than the other | ||
| | ||
= note: expected trait `for<'a> FnOnce<(&'a (),)>` | ||
found trait `FnOnce<(&(),)>` | ||
note: this closure does not fulfill the lifetime requirements | ||
--> $DIR/missing-universe-cause-issue-114907.rs:32:20 | ||
| | ||
LL | let callback = |_| {}; | ||
| ^^^ | ||
note: the lifetime requirement is introduced here | ||
--> $DIR/missing-universe-cause-issue-114907.rs:27:14 | ||
| | ||
LL | fn accept<C: FnOnce(&())>(_: C) -> Handshake<HandshakeCallback<C>> { | ||
| ^^^^^^^^^^^ | ||
help: consider specifying the type of the closure parameters | ||
| | ||
LL | let callback = |_: &_| {}; | ||
| ~~~~~~~ | ||
|
||
error: implementation of `FnOnce` is not general enough | ||
--> $DIR/missing-universe-cause-issue-114907.rs:33:5 | ||
| | ||
LL | accept(callback); | ||
| ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough | ||
| | ||
= note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`... | ||
= note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2` | ||
|
||
error: implementation of `FnOnce` is not general enough | ||
--> $DIR/missing-universe-cause-issue-114907.rs:33:5 | ||
| | ||
LL | accept(callback); | ||
| ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough | ||
| | ||
= note: closure with signature `fn(&'2 ())` must implement `FnOnce<(&'1 (),)>`, for any lifetime `'1`... | ||
= note: ...but it actually implements `FnOnce<(&'2 (),)>`, for some specific lifetime `'2` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/missing-universe-cause-issue-114907.rs:33:5 | ||
| | ||
LL | accept(callback); | ||
| ^^^^^^^^^^^^^^^^ one type is more general than the other | ||
| | ||
= note: expected trait `for<'a> FnOnce<(&'a (),)>` | ||
found trait `FnOnce<(&(),)>` | ||
note: this closure does not fulfill the lifetime requirements | ||
--> $DIR/missing-universe-cause-issue-114907.rs:32:20 | ||
| | ||
LL | let callback = |_| {}; | ||
| ^^^ | ||
note: the lifetime requirement is introduced here | ||
--> $DIR/missing-universe-cause-issue-114907.rs:20:21 | ||
| | ||
LL | struct Handshake<R: Role> { | ||
| ^^^^ | ||
help: consider specifying the type of the closure parameters | ||
| | ||
LL | let callback = |_: &_| {}; | ||
| ~~~~~~~ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/missing-universe-cause-issue-114907.rs:33:21 | ||
| | ||
LL | accept(callback); | ||
| ^ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/missing-universe-cause-issue-114907.rs:33:21 | ||
| | ||
LL | accept(callback); | ||
| ^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |