-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Better closure requirement propagation. #148329
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
Open
LorrensP-2158466
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
LorrensP-2158466:closure-prop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Some comments aren't visible on the classic Files Changed page.
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
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
79 changes: 79 additions & 0 deletions
79
tests/ui/nll/closure-requirements/propagate-approximated-both-lower-bounds.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,79 @@ | ||
| note: external requirements | ||
| --> $DIR/propagate-approximated-both-lower-bounds.rs:43:9 | ||
| | | ||
| LL | |_outlives1, _outlives2, _outlives3, x, y| { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: defining type: supply::{closure#0} with closure args [ | ||
| i16, | ||
| for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 &'^0 u32>, std::cell::Cell<&'?2 &'^0 u32>, std::cell::Cell<&'^1 &'?3 u32>, std::cell::Cell<&'^0 u32>, std::cell::Cell<&'^1 u32>)), | ||
| (), | ||
| ] | ||
| = note: late-bound region is '?7 | ||
| = note: late-bound region is '?8 | ||
| = note: late-bound region is '?4 | ||
| = note: late-bound region is '?5 | ||
| = note: late-bound region is '?6 | ||
| = note: number of external vids: 7 | ||
| = note: where '?2: '?3 | ||
| = note: where '?1: '?3 | ||
|
|
||
| note: no external requirements | ||
| --> $DIR/propagate-approximated-both-lower-bounds.rs:36:1 | ||
| | | ||
| LL | fn supply<'a, 'b, 'c>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>, cell_c: Cell<&'c u32>) { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: defining type: supply | ||
|
|
||
| error: lifetime may not live long enough | ||
| --> $DIR/propagate-approximated-both-lower-bounds.rs:39:5 | ||
| | | ||
| LL | fn supply<'a, 'b, 'c>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>, cell_c: Cell<&'c u32>) { | ||
| | -- -- lifetime `'c` defined here | ||
| | | | ||
| | lifetime `'a` defined here | ||
| ... | ||
| LL | / establish_relationships( | ||
| LL | | cell_a, | ||
| LL | | cell_b, | ||
| LL | | cell_c, | ||
| ... | | ||
| LL | | }, | ||
| LL | | ); | ||
| | |_____^ argument requires that `'a` must outlive `'c` | ||
| | | ||
| = help: consider adding the following bound: `'a: 'c` | ||
| = note: requirement occurs because of the type `Cell<&'?10 u32>`, which makes the generic argument `&'?10 u32` invariant | ||
| = note: the struct `Cell<T>` is invariant over the parameter `T` | ||
| = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance | ||
|
|
||
| error: lifetime may not live long enough | ||
| --> $DIR/propagate-approximated-both-lower-bounds.rs:39:5 | ||
| | | ||
| LL | fn supply<'a, 'b, 'c>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>, cell_c: Cell<&'c u32>) { | ||
| | -- -- lifetime `'c` defined here | ||
| | | | ||
| | lifetime `'b` defined here | ||
| ... | ||
| LL | / establish_relationships( | ||
| LL | | cell_a, | ||
| LL | | cell_b, | ||
| LL | | cell_c, | ||
| ... | | ||
| LL | | }, | ||
| LL | | ); | ||
| | |_____^ argument requires that `'b` must outlive `'c` | ||
| | | ||
| = help: consider adding the following bound: `'b: 'c` | ||
| = note: requirement occurs because of the type `Cell<&'?10 u32>`, which makes the generic argument `&'?10 u32` invariant | ||
| = note: the struct `Cell<T>` is invariant over the parameter `T` | ||
| = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance | ||
|
|
||
| help: the following changes may resolve your lifetime errors | ||
| | | ||
| = help: add bound `'a: 'c` | ||
| = help: add bound `'b: 'c` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
42 changes: 0 additions & 42 deletions
42
tests/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
| //@ check-pass | ||
| // This checks that the compiler does not require that 'a: 'b. '_ has 'a and 'b as non-local | ||
| // upper bounds, but the compiler should not propagate 'a: 'b OR 'b: 'a when checking | ||
| // the closures. If it did, this would fail to compile, eventhough it's a valid program. | ||
| // PR #148329 explains this in detail. | ||
|
|
||
| struct MyTy<'x, 'a, 'b>(std::cell::Cell<(&'x &'a u8, &'x &'b u8)>); | ||
| fn wf<T>(_: T) {} | ||
| fn test<'a, 'b>() { | ||
| |_: &'a u8, x: MyTy<'_, 'a, 'b>| wf(x); | ||
| |x: MyTy<'_, 'a, 'b>, _: &'a u8| wf(x); | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| //@ check-pass | ||
| // This test checks that the compiler propagates outlives requirements for both | ||
| // non-local lower bounds ['a, 'b] of '_, instead of conservatively finding a post-dominiting one | ||
| // from those 2. | ||
|
|
||
| struct MyTy<'a, 'b, 'x>(std::cell::Cell<(&'a &'x str, &'b &'x str)>); | ||
| fn wf<T>(_: T) {} | ||
| fn test<'a, 'b, 'x>() { | ||
| |x: MyTy<'a, 'b, '_>| wf(x); | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //@ check-pass | ||
| // This test checks that the compiler does not propagate 'd: 'c when propagating region errors | ||
| // for the closure argument. If it did, this would fail to compile, eventhough it's a valid program. | ||
| // It should only propagate 'd: 'b. | ||
| // PR #148329 explains this in detail. | ||
|
|
||
| #[derive(Clone, Copy)] | ||
| struct Inv<'a>(*mut &'a ()); | ||
| impl<'a> Inv<'a> { | ||
| fn outlived_by<'b: 'a>(self, _: Inv<'b>) {} | ||
| } | ||
| struct OutlivedBy<'a, 'b: 'a>(Inv<'a>, Inv<'b>); | ||
|
|
||
| fn closure_arg<'b, 'c, 'd>( | ||
| _: impl for<'a> FnOnce(Inv<'a>, OutlivedBy<'a, 'b>, OutlivedBy<'a, 'c>, Inv<'d>), | ||
| ) { | ||
| } | ||
| fn foo<'b, 'c, 'd: 'b>() { | ||
| closure_arg::<'b, 'c, 'd>(|a, b, c, d| { | ||
| a.outlived_by(b.1); | ||
| a.outlived_by(c.1); | ||
| b.1.outlived_by(d); | ||
| }); | ||
| } | ||
|
|
||
| fn main() {} |
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.