-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Treat vars created for opaque subtyping as live everywhere #161151
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
Merged
rust-bors
merged 1 commit into
rust-lang:main
from
jackh726:issue-160669-subtyping-live
Aug 18, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
69 changes: 69 additions & 0 deletions
69
tests/ui/nll/polonius/opaque-multiple-defining-uses-160669.next.stderr
This file contains hidden or 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,69 @@ | ||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:31:16 | ||
| | | ||
| LL | let local = String::from("dangling"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
| LL | s | ||
| LL | } | ||
| | - borrow later used here | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:41:16 | ||
| | | ||
| LL | let local = String::from("dangling0"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
| ... | ||
| LL | } | ||
| | - borrow later used here | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:45:16 | ||
| | | ||
| LL | let local = String::from("dangling1"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
| LL | s | ||
| LL | } | ||
| | - borrow later used here | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:57:5 | ||
| | | ||
| LL | let local = String::from("dangling"); | ||
| | ----- binding `local` declared here | ||
| LL | &local | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | -- borrow later used here | ||
| | | | ||
| | `local` dropped here while still borrowed | ||
|
|
||
| error[E0597]: `short` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:64:16 | ||
| | | ||
| LL | fn minimal(short: (), out: &'static ()) -> impl Sized { | ||
| | ----- binding `short` declared here | ||
| LL | if true { | ||
| LL | return &short; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| ... | ||
| LL | } | ||
| | - | ||
| | | | ||
| | `short` dropped here while still borrowed | ||
| | borrow later used here | ||
|
|
||
| error: aborting due to 5 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0597`. |
80 changes: 80 additions & 0 deletions
80
tests/ui/nll/polonius/opaque-multiple-defining-uses-160669.nll.stderr
This file contains hidden or 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,80 @@ | ||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:31:16 | ||
| | | ||
| LL | fn two_uses<'a>(s: &'a String, flag: bool) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| LL | if flag { | ||
| LL | let local = String::from("dangling"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
| LL | s | ||
| | - opaque type requires that `local` is borrowed for `'a` | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:41:16 | ||
| | | ||
| LL | fn three_uses<'a>(s: &'a String, flag: u8) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| LL | if flag == 0 { | ||
| LL | let local = String::from("dangling0"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
| ... | ||
| LL | return &local; | ||
| | ------ opaque type requires that `local` is borrowed for `'a` | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:45:16 | ||
| | | ||
| LL | fn three_uses<'a>(s: &'a String, flag: u8) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| ... | ||
| LL | let local = String::from("dangling1"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ | ||
| | | | ||
| | borrowed value does not live long enough | ||
| | opaque type requires that `local` is borrowed for `'a` | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:57:5 | ||
| | | ||
| LL | fn reversed_order<'a>(s: &'a String, flag: bool) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| ... | ||
| LL | let local = String::from("dangling"); | ||
| | ----- binding `local` declared here | ||
| LL | &local | ||
| | ^^^^^^ | ||
| | | | ||
| | borrowed value does not live long enough | ||
| | opaque type requires that `local` is borrowed for `'a` | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
|
|
||
| error[E0597]: `short` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:64:16 | ||
| | | ||
| LL | fn minimal(short: (), out: &'static ()) -> impl Sized { | ||
| | ----- binding `short` declared here | ||
| LL | if true { | ||
| LL | return &short; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| LL | out | ||
| | --- opaque type requires that `short` is borrowed for `'static` | ||
| LL | } | ||
| | - `short` dropped here while still borrowed | ||
|
|
||
| error: aborting due to 5 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0597`. |
80 changes: 80 additions & 0 deletions
80
tests/ui/nll/polonius/opaque-multiple-defining-uses-160669.polonius.stderr
This file contains hidden or 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,80 @@ | ||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:31:16 | ||
| | | ||
| LL | fn two_uses<'a>(s: &'a String, flag: bool) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| LL | if flag { | ||
| LL | let local = String::from("dangling"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
| LL | s | ||
| | - opaque type requires that `local` is borrowed for `'a` | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:41:16 | ||
| | | ||
| LL | fn three_uses<'a>(s: &'a String, flag: u8) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| LL | if flag == 0 { | ||
| LL | let local = String::from("dangling0"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
| ... | ||
| LL | return &local; | ||
| | ------ opaque type requires that `local` is borrowed for `'a` | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:45:16 | ||
| | | ||
| LL | fn three_uses<'a>(s: &'a String, flag: u8) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| ... | ||
| LL | let local = String::from("dangling1"); | ||
| | ----- binding `local` declared here | ||
| LL | return &local; | ||
| | ^^^^^^ | ||
| | | | ||
| | borrowed value does not live long enough | ||
| | opaque type requires that `local` is borrowed for `'a` | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
|
|
||
| error[E0597]: `local` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:57:5 | ||
| | | ||
| LL | fn reversed_order<'a>(s: &'a String, flag: bool) -> impl Display + use<'a> { | ||
| | -- lifetime `'a` defined here | ||
| ... | ||
| LL | let local = String::from("dangling"); | ||
| | ----- binding `local` declared here | ||
| LL | &local | ||
| | ^^^^^^ | ||
| | | | ||
| | borrowed value does not live long enough | ||
| | opaque type requires that `local` is borrowed for `'a` | ||
| LL | } | ||
| | - `local` dropped here while still borrowed | ||
|
|
||
| error[E0597]: `short` does not live long enough | ||
| --> $DIR/opaque-multiple-defining-uses-160669.rs:64:16 | ||
| | | ||
| LL | fn minimal(short: (), out: &'static ()) -> impl Sized { | ||
| | ----- binding `short` declared here | ||
| LL | if true { | ||
| LL | return &short; | ||
| | ^^^^^^ borrowed value does not live long enough | ||
| LL | } | ||
| LL | out | ||
| | --- opaque type requires that `short` is borrowed for `'static` | ||
| LL | } | ||
| | - `short` dropped here while still borrowed | ||
|
|
||
| error: aborting due to 5 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0597`. |
69 changes: 69 additions & 0 deletions
69
tests/ui/nll/polonius/opaque-multiple-defining-uses-160669.rs
This file contains hidden or 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,69 @@ | ||
| // An opaque type has a single hidden type, and the opaque type storage only keeps a | ||
| // single hidden type per key. So, a second defining use replaces the first. | ||
| // | ||
| // In the old solver, MIR is built with unnormalized opaques; and, a defining use | ||
| // is generalized prior to being registered as the hidden type, to allow for | ||
| // subtyping. | ||
| // | ||
| // During this generalization, any regions created were previously not | ||
| // considered live, which means that under Polonius Alpha, outlives constraints | ||
| // were not propogated between a previous hidden type and a new one. | ||
| // | ||
| // We now consider all these lifetimes live at all points. | ||
| // | ||
| // In the new solver, this is all moot, because MIR has *normalized* opaques, | ||
| // and so there is no special subtyping code. | ||
| // | ||
| // Regression test for #160669. | ||
|
|
||
| //@ ignore-compare-mode-polonius (explicit revisions) | ||
| //@ ignore-compare-mode-next-solver (explicit revisions) | ||
| //@ revisions: nll polonius next | ||
| //@ [nll] compile-flags: -Z polonius=off | ||
| //@ [polonius] compile-flags: -Z polonius=next | ||
| //@ [next] compile-flags: -Z next-solver -Z polonius=next | ||
|
|
||
| use std::fmt::Display; | ||
|
|
||
| fn two_uses<'a>(s: &'a String, flag: bool) -> impl Display + use<'a> { | ||
| if flag { | ||
| let local = String::from("dangling"); | ||
| return &local; //~ ERROR `local` does not live long enough | ||
| } | ||
| s | ||
| } | ||
|
|
||
| // The same, with a borrow of a local in multiple branchs, to check that we | ||
| // don't only report the defining use which happens to be last in MIR order. | ||
| fn three_uses<'a>(s: &'a String, flag: u8) -> impl Display + use<'a> { | ||
| if flag == 0 { | ||
| let local = String::from("dangling0"); | ||
| return &local; //~ ERROR `local` does not live long enough | ||
| } | ||
| if flag == 1 { | ||
| let local = String::from("dangling1"); | ||
| return &local; //~ ERROR `local` does not live long enough | ||
| } | ||
| s | ||
| } | ||
|
|
||
| // Control for the order dependence: here the bad defining use is the last one in MIR order, | ||
| // so it stayed anchored and was caught even before the fix. | ||
| fn reversed_order<'a>(s: &'a String, flag: bool) -> impl Display + use<'a> { | ||
| if flag { | ||
| return s; | ||
| } | ||
| let local = String::from("dangling"); | ||
| &local //~ ERROR `local` does not live long enough | ||
| } | ||
|
|
||
| // This is a much more minimal MIR representation of the same bug. Useful for | ||
| // debugging. | ||
| fn minimal(short: (), out: &'static ()) -> impl Sized { | ||
| if true { | ||
| return &short; //~ ERROR `short` does not live long enough | ||
| } | ||
| out | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.