forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closure-requirements: add regression tests
- Loading branch information
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
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