-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Handle regions equivalent to 'static in non_local_bounds #139668
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
matthewjasper
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
matthewjasper:upper-bound-fix
base: master
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.
+226
−15
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
tests/ui/borrowck/unconstrained-closure-lifetime-generic.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,22 @@ | ||
// Regression test for #122704 | ||
use std::any::Any; | ||
|
||
pub struct Foo { | ||
bar: Box<dyn for<'a> Fn(&'a usize) -> Box<dyn Any + 'a>>, | ||
} | ||
|
||
impl Foo { | ||
pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I>) { | ||
self.bar = Box::new(|baz| Box::new(f(baz))); | ||
//~^ ERROR the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
//~| ERROR the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
//~| ERROR the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
//~| ERROR the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
//~| ERROR the parameter type `I` may not live long enough | ||
//~| ERROR the parameter type `I` may not live long enough | ||
//~| ERROR the parameter type `I` may not live long enough | ||
//~| ERROR `f` does not live long enough | ||
} | ||
} | ||
|
||
fn main() {} |
119 changes: 119 additions & 0 deletions
119
tests/ui/borrowck/unconstrained-closure-lifetime-generic.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,119 @@ | ||
error[E0310]: the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:9 | ||
| | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| ^^^^^^^^ | ||
| | | ||
| the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` must be valid for the static lifetime... | ||
| ...so that the type `impl for<'a> Fn(&'a usize) -> Box<I>` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I> + 'static) { | ||
| +++++++++ | ||
|
||
error[E0310]: the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:9 | ||
| | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| ^^^^^^^^ | ||
| | | ||
| the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` must be valid for the static lifetime... | ||
| ...so that the type `impl for<'a> Fn(&'a usize) -> Box<I>` will meet its required lifetime bounds | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I> + 'static) { | ||
| +++++++++ | ||
|
||
error[E0310]: the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:20 | ||
| | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| ^^^^^^^^ | ||
| | | ||
| the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` must be valid for the static lifetime... | ||
| ...so that the type `impl for<'a> Fn(&'a usize) -> Box<I>` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I> + 'static) { | ||
| +++++++++ | ||
|
||
error[E0310]: the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:20 | ||
| | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| the parameter type `impl for<'a> Fn(&'a usize) -> Box<I>` must be valid for the static lifetime... | ||
| ...so that the type `impl for<'a> Fn(&'a usize) -> Box<I>` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I> + 'static) { | ||
| +++++++++ | ||
|
||
error[E0310]: the parameter type `I` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:35 | ||
| | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| ^^^^^^^^^^^^^^^^ | ||
| | | ||
| the parameter type `I` must be valid for the static lifetime... | ||
| ...so that the type `I` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | pub fn ack<I: 'static>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I>) { | ||
| +++++++++ | ||
|
||
error[E0310]: the parameter type `I` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:35 | ||
| | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| ^^^^^^^^^^^^^^^^ | ||
| | | ||
| the parameter type `I` must be valid for the static lifetime... | ||
| ...so that the type `I` will meet its required lifetime bounds | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | pub fn ack<I: 'static>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I>) { | ||
| +++++++++ | ||
|
||
error[E0311]: the parameter type `I` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:35 | ||
| | ||
LL | pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I>) { | ||
| --------- the parameter type `I` must be valid for the anonymous lifetime defined here... | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| ^^^^^^^^^^^^^^^^ ...so that the type `I` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | pub fn ack<'a, I: 'a>(&'a mut self, f: impl for<'a> Fn(&'a usize) -> Box<I>) { | ||
| +++ ++++ ++ | ||
|
||
error[E0597]: `f` does not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-generic.rs:10:44 | ||
| | ||
LL | pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I>) { | ||
| - binding `f` declared here | ||
LL | self.bar = Box::new(|baz| Box::new(f(baz))); | ||
| -------- ----- ^ borrowed value does not live long enough | ||
| | | | ||
| | value captured here | ||
| coercion requires that `f` is borrowed for `'static` | ||
... | ||
LL | } | ||
| - `f` dropped here while still borrowed | ||
| | ||
= note: due to object lifetime defaults, `Box<dyn for<'a> Fn(&'a usize) -> Box<(dyn Any + 'a)>>` actually means `Box<(dyn for<'a> Fn(&'a usize) -> Box<(dyn Any + 'a)> + 'static)>` | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0310, E0311, E0597. | ||
For more information about an error, try `rustc --explain E0310`. |
11 changes: 11 additions & 0 deletions
11
tests/ui/borrowck/unconstrained-closure-lifetime-trait-object.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,11 @@ | ||
// Regression test for #139004 | ||
use std::any::Any; | ||
|
||
type B = Box<dyn for<'a> Fn(&(dyn Any + 'a)) -> Box<dyn Any + 'a>>; | ||
|
||
fn foo<E>() -> B { | ||
Box::new(|e| Box::new(e.is::<E>())) | ||
//~^ ERROR the parameter type `E` may not live long enough | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/borrowck/unconstrained-closure-lifetime-trait-object.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,17 @@ | ||
error[E0310]: the parameter type `E` may not live long enough | ||
--> $DIR/unconstrained-closure-lifetime-trait-object.rs:7:29 | ||
| | ||
LL | Box::new(|e| Box::new(e.is::<E>())) | ||
| ^^ | ||
| | | ||
| the parameter type `E` must be valid for the static lifetime... | ||
| ...so that the type `E` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | fn foo<E: 'static>() -> B { | ||
| +++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0310`. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we not find such an element? In other words, what's the justification for the
map_or
, over anunwrap
? Shouldn't all free regions be represented inTransitiveRelations
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Borrowck will always have this as a reflexive relation, but the data structure doesn't require that (maybe it should though).