forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#133798 - lcnr:nested-bodies-opaques, r=comp…
…iler-errors stop replacing bivariant args with `'static` when computing closure requirements It is unnecessary, these get constrained when checking that the opaque type is well-formed. It also results in the opaque type no longer being well formed. If you've got `fn foo<'a>() -> impl Sized + 'a` the opaque is `type Opaque<'a, 'aDummy> where 'a: 'aDummy, 'aDummy: 'a` where `'aDummy` is bivariant. If we call `foo::<'b>()` inside of a closure and its return type ends up in a type test, we start out with the WF `Opaque<'b, 'b>`, and then replace the bivariant `'b` with `'static`. `Opaque<'b, 'static>` is no longer well-formed. Given how these type tests are used, I don't think this caused any practical issues. r? types
- Loading branch information
Showing
6 changed files
with
70 additions
and
46 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
23 changes: 23 additions & 0 deletions
23
tests/ui/nll/closure-requirements/thread_scope_correct_implied_bound.rs
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,23 @@ | ||
// This example broke while refactoring the way closure | ||
// requirements are handled. The setup here matches | ||
// `thread::scope`. | ||
|
||
//@ check-pass | ||
|
||
struct Outlives<'hr, 'scope: 'hr>(*mut (&'scope (), &'hr ())); | ||
impl<'hr, 'scope> Outlives<'hr, 'scope> { | ||
fn outlives_hr<T: 'hr>(self) {} | ||
} | ||
|
||
fn takes_closure_implied_bound<'scope>(f: impl for<'hr> FnOnce(Outlives<'hr, 'scope>)) {} | ||
|
||
fn requires_external_outlives_hr<T>() { | ||
// implied bounds: | ||
// - `T: 'scope` as `'scope` is local to this function | ||
// - `'scope: 'hr` as it's an implied bound of `Outlives` | ||
// | ||
// need to prove `T: 'hr` :> | ||
takes_closure_implied_bound(|proof| proof.outlives_hr::<T>()); | ||
} | ||
|
||
fn main() {} |
21 changes: 21 additions & 0 deletions
21
tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.rs
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,21 @@ | ||
// This example incorrectly compiled while refactoring the way | ||
// closure requirements are handled. | ||
|
||
struct Outlives<'hr: 'scope, 'scope>(*mut (&'scope (), &'hr ())); | ||
impl<'hr, 'scope> Outlives<'hr, 'scope> { | ||
fn outlives_hr<T: 'hr>(self) {} | ||
} | ||
|
||
fn takes_closure_implied_bound<'scope>(f: impl for<'hr> FnOnce(Outlives<'hr, 'scope>)) {} | ||
|
||
fn requires_external_outlives_hr<T>() { | ||
// implied bounds: | ||
// - `T: 'scope` as `'scope` is local to this function | ||
// - `'hr: 'scope` as it's an implied bound of `Outlives` | ||
// | ||
// need to prove `T: 'hr` :< | ||
takes_closure_implied_bound(|proof| proof.outlives_hr::<T>()); | ||
//~^ ERROR the parameter type `T` may not live long enough | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.stderr
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,17 @@ | ||
error[E0310]: the parameter type `T` may not live long enough | ||
--> $DIR/thread_scope_incorrect_implied_bound.rs:17:47 | ||
| | ||
LL | takes_closure_implied_bound(|proof| proof.outlives_hr::<T>()); | ||
| ^^^^^^^^^^^ | ||
| | | ||
| the parameter type `T` must be valid for the static lifetime... | ||
| ...so that the type `T` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | fn requires_external_outlives_hr<T: 'static>() { | ||
| +++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0310`. |
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