diff options
Diffstat (limited to 'tests')
5 files changed, 62 insertions, 3 deletions
diff --git a/tests/ui/nll/closure-requirements/thread_scope_correct_implied_bound.rs b/tests/ui/nll/closure-requirements/thread_scope_correct_implied_bound.rs new file mode 100644 index 00000000000..e2b3b051ea8 --- /dev/null +++ b/tests/ui/nll/closure-requirements/thread_scope_correct_implied_bound.rs @@ -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() {} diff --git a/tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.rs b/tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.rs new file mode 100644 index 00000000000..cfc8980410a --- /dev/null +++ b/tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.rs @@ -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() {} diff --git a/tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.stderr b/tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.stderr new file mode 100644 index 00000000000..e22673c249f --- /dev/null +++ b/tests/ui/nll/closure-requirements/thread_scope_incorrect_implied_bound.stderr @@ -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`. diff --git a/tests/ui/nll/ty-outlives/projection-implied-bounds.rs b/tests/ui/nll/ty-outlives/projection-implied-bounds.rs index 7d983adfe88..c6572d60bb0 100644 --- a/tests/ui/nll/ty-outlives/projection-implied-bounds.rs +++ b/tests/ui/nll/ty-outlives/projection-implied-bounds.rs @@ -1,8 +1,6 @@ // Test that we can deduce when projections like `T::Item` outlive the // function body. Test that this does not imply that `T: 'a` holds. -//@ compile-flags:-Zverbose-internals - use std::cell::Cell; fn twice<F, T>(mut value: T, mut f: F) diff --git a/tests/ui/nll/ty-outlives/projection-implied-bounds.stderr b/tests/ui/nll/ty-outlives/projection-implied-bounds.stderr index 2aab03ee7b7..5d5b890151d 100644 --- a/tests/ui/nll/ty-outlives/projection-implied-bounds.stderr +++ b/tests/ui/nll/ty-outlives/projection-implied-bounds.stderr @@ -1,5 +1,5 @@ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/projection-implied-bounds.rs:30:36 + --> $DIR/projection-implied-bounds.rs:28:36 | LL | twice(value, |value_ref, item| invoke2(value_ref, item)); | ^^^^^^^^^^^^^^^^^^^^^^^^ |
