diff options
| author | bors <bors@rust-lang.org> | 2022-05-28 04:04:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-28 04:04:29 +0000 |
| commit | ed76b773b57cf0aa48ec4e2fc6d6a3f7a9079491 (patch) | |
| tree | 3ec0e6ff4813c0970206a5ef9b3b86bcb4f65d06 /src/test/ui | |
| parent | 764b8615e9149431d8790e3c07cb663642fe393d (diff) | |
| parent | 3c6c8d5a8dbf4db20450ed5793ef35f29c13466c (diff) | |
| download | rust-ed76b773b57cf0aa48ec4e2fc6d6a3f7a9079491.tar.gz rust-ed76b773b57cf0aa48ec4e2fc6d6a3f7a9079491.zip | |
Auto merge of #97284 - b-naber:constraint-dyn-impl-suggestion, r=estebank
Add suggestion for relaxing static lifetime bounds on dyn trait impls in NLL This PR introduces suggestions for relaxing static lifetime bounds on impls of dyn trait items for NLL similar to what is already available in lexical region diagnostics. Fixes https://github.com/rust-lang/rust/issues/95701 r? `@estebank`
Diffstat (limited to 'src/test/ui')
8 files changed, 82 insertions, 31 deletions
diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.krisskross.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.krisskross.stderr index 231e98cf841..09119ea2bb5 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.krisskross.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.krisskross.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/project-fn-ret-invariant-nll.rs:63:5 + --> $DIR/project-fn-ret-invariant-nll.rs:64:5 | LL | fn transmute<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) { | -- -- lifetime `'b` defined here @@ -15,7 +15,7 @@ LL | (a, b) = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance error: lifetime may not live long enough - --> $DIR/project-fn-ret-invariant-nll.rs:63:5 + --> $DIR/project-fn-ret-invariant-nll.rs:64:5 | LL | fn transmute<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) { | -- -- lifetime `'b` defined here diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.oneuse.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.oneuse.stderr index 1dbfff6a8cd..266f3b99f9f 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.oneuse.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.oneuse.stderr @@ -15,19 +15,19 @@ LL | let a = bar(f, x); = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance error: lifetime may not live long enough - --> $DIR/project-fn-ret-invariant-nll.rs:47:13 + --> $DIR/project-fn-ret-invariant-nll.rs:46:13 | LL | fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) { | -- -- lifetime `'b` defined here | | | lifetime `'a` defined here -... -LL | let b = bar(f, y); +LL | let f = foo; // <-- No consistent type can be inferred for `f` here. +LL | let a = bar(f, x); | ^^^^^^^^^ argument requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant - = note: the struct `Type<'a>` is invariant over the parameter `'a` + = note: requirement occurs because of a function pointer to `foo` + = note: the function `foo` is invariant over the parameter `'a` = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance help: `'a` and `'b` must be the same: replace one with the other diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.rs b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.rs index 6cd5c6417a9..15bf38dabc0 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.rs +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.rs @@ -44,7 +44,8 @@ fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) { fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) { let f = foo; // <-- No consistent type can be inferred for `f` here. let a = bar(f, x); //[oneuse]~ ERROR lifetime may not live long enough - let b = bar(f, y); //[oneuse]~ ERROR lifetime may not live long enough + //[oneuse]~^ ERROR lifetime may not live long enough + let b = bar(f, y); (a, b) } diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.transmute.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.transmute.stderr index 352914f020c..56f08152999 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.transmute.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant-nll.transmute.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/project-fn-ret-invariant-nll.rs:56:5 + --> $DIR/project-fn-ret-invariant-nll.rs:57:5 | LL | fn baz<'a, 'b>(x: Type<'a>) -> Type<'static> { | -- lifetime `'a` defined here diff --git a/src/test/ui/async-await/issues/issue-72312.nll.stderr b/src/test/ui/async-await/issues/issue-72312.nll.stderr index 53b2c931cce..02e47721e0c 100644 --- a/src/test/ui/async-await/issues/issue-72312.nll.stderr +++ b/src/test/ui/async-await/issues/issue-72312.nll.stderr @@ -1,5 +1,5 @@ error[E0521]: borrowed data escapes outside of associated function - --> $DIR/issue-72312.rs:20:24 + --> $DIR/issue-72312.rs:20:9 | LL | pub async fn start(&self) { | ----- @@ -7,18 +7,17 @@ LL | pub async fn start(&self) { | `self` is a reference that is only valid in the associated function body | let's call the lifetime of this reference `'1` ... -LL | require_static(async move { - | ________________________^ +LL | / require_static(async move { LL | | LL | | LL | | LL | | LL | | &self; LL | | }); - | | ^ - | | | - | |_________`self` escapes the associated function body here - | argument requires that `'1` must outlive `'static` + | | ^ + | | | + | |__________`self` escapes the associated function body here + | argument requires that `'1` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index 30ef343b261..3ab55b370c2 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -72,14 +72,15 @@ LL | | } error[E0597]: `a` does not live long enough --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26 | -LL | let cell = Cell::new(&a); - | ----------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `a` is borrowed for `'static` +LL | let cell = Cell::new(&a); + | ^^ borrowed value does not live long enough ... -LL | } - | - `a` dropped here while still borrowed +LL | / foo(cell, |cell_a, cell_x| { +LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error +LL | | }) + | |______- argument requires that `a` is borrowed for `'static` +LL | } + | - `a` dropped here while still borrowed error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr b/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr index bb703412228..3326fa521fc 100644 --- a/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr +++ b/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr @@ -1,14 +1,14 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:33:41 | -LL | SomeEnum::SomeVariant(Cell::new(&c)), - | ----------^^- - | | | - | | borrowed value does not live long enough - | argument requires that `c` is borrowed for `'static` -... -LL | } - | - `c` dropped here while still borrowed +LL | / combine( +LL | | SomeEnum::SomeVariant(Cell::new(&c)), + | | ^^ borrowed value does not live long enough +LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>, +LL | | ); + | |_____- argument requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:41:41 diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-nll.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-nll.stderr index 38731ea8955..5d9c7077fa1 100644 --- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-nll.stderr +++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-nll.stderr @@ -10,6 +10,18 @@ LL | val.use_self::<T>() | | | `val` escapes the function body here | argument requires that `'a` must outlive `'static` + | +note: the used `impl` has a `'static` requirement + --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-nll.rs:19:32 + | +LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> { + | ^^^^^^^^^^^^^^ this has an implicit `'static` lifetime requirement +LL | fn use_self<K>(&self) -> &() { panic!() } + | -------- calling this method introduces the `impl`'s 'static` requirement +help: consider relaxing the implicit `'static` requirement + | +LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> + '_ { + | ++++ error[E0521]: borrowed data escapes outside of function --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-nll.rs:74:9 @@ -23,6 +35,18 @@ LL | val.use_self() | | | `val` escapes the function body here | argument requires that `'a` must outlive `'static` + | +note: the used `impl` has a `'static` requirement + --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-nll.rs:69:14 + | +LL | impl dyn ObjectTrait { + | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement +LL | fn use_self(&self) -> &() { panic!() } + | -------- calling this method introduces the `impl`'s 'static` requirement +help: consider relaxing the implicit `'static` requirement + | +LL | impl dyn ObjectTrait + '_ { + | ++++ error[E0521]: borrowed data escapes outside of function --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-nll.rs:94:9 @@ -36,6 +60,19 @@ LL | val.use_self() | | | `val` escapes the function body here | argument requires that `'a` must outlive `'static` + | +note: the used `impl` has a `'static` requirement + --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-nll.rs:91:26 + | +LL | fn use_self(&self) -> &() { panic!() } + | -------- calling this method introduces the `impl`'s 'static` requirement +... +LL | impl MyTrait for dyn ObjectTrait {} + | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement +help: consider relaxing the implicit `'static` requirement + | +LL | impl MyTrait for dyn ObjectTrait + '_ {} + | ++++ error[E0521]: borrowed data escapes outside of function --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-nll.rs:114:9 @@ -49,6 +86,19 @@ LL | MyTrait::use_self(val) | | | `val` escapes the function body here | argument requires that `'a` must outlive `'static` + | +note: the used `impl` has a `'static` requirement + --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-nll.rs:110:26 + | +LL | fn use_self(&self) -> &() { panic!() } + | -------- calling this method introduces the `impl`'s 'static` requirement +... +LL | impl MyTrait for dyn ObjectTrait {} + | ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement +help: consider relaxing the implicit `'static` requirement + | +LL | impl MyTrait for dyn ObjectTrait + '_ {} + | ++++ error: aborting due to 4 previous errors |
