Reduce verbosity of suggestion message and mention lifetime in label

This commit is contained in:
Esteban Küber 2020-05-29 18:59:42 -07:00
parent 4e90f177cc
commit 921f35fe73
14 changed files with 96 additions and 87 deletions

View file

@ -4,7 +4,7 @@ error: cannot infer an appropriate lifetime
LL | pub async fn run_dummy_fn(&self) {
| ^^^^^
| |
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
| ...is captured here...
LL | foo(|| self.bar()).await;
| --- ...and required to be `'static` by this

View file

@ -5,9 +5,9 @@ LL | fn elided(x: &i32) -> impl Copy { x }
| ---- --------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 3:1
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ^^^^
@ -19,9 +19,9 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| ------- --------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the lifetime `'a` as defined on the function body at 6:13
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for lifetime `'a`
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ^^^^
@ -33,9 +33,9 @@ LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| ---- ------------------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: consider changing the `impl Trait`'s explicit `'static` bound
help: consider changing the `impl Trait`'s explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
| ^^
@ -51,9 +51,9 @@ LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
| ------- ------------------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: consider changing the `impl Trait`'s explicit `'static` bound
help: consider changing the `impl Trait`'s explicit `'static` bound to lifetime `'a`
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ^^
@ -77,9 +77,9 @@ LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| ------- -------------------------------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: consider changing the `impl Trait`'s explicit `'static` bound
help: consider changing the `impl Trait`'s explicit `'static` bound to lifetime `'a`
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
| ^^
@ -113,9 +113,9 @@ LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
| | | |
| | | ...and is captured here
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 18:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
| ^^^^
@ -128,9 +128,9 @@ LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
| | | |
| | | ...and is captured here
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the lifetime `'a` as defined on the function body at 21:14
help: to permit non-static references in a trait object value, you can add an explicit bound for lifetime `'a`
|
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
| ^^^^
@ -142,9 +142,10 @@ LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ---- ---------^-
| | | |
| | | ...and is captured here
| data with this lifetime... ...is required to be `'static` by this...
| | ...is required to be `'static` by this...
| this data with the anonymous lifetime `'_`...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
| ^^
@ -160,9 +161,10 @@ LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ------- ---------^-
| | | |
| | | ...and is captured here
| data with this lifetime... ...is required to be `'static` by this...
| | ...is required to be `'static` by this...
| this data with lifetime `'a`...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
| ^^

View file

@ -4,13 +4,13 @@ error: cannot infer an appropriate lifetime
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
| ----- ----------------------- ...is required to be `'static` by this...
| |
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
| ...and is captured here
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the method body at 6:5
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ^^^^
@ -21,13 +21,13 @@ error: cannot infer an appropriate lifetime
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| -------- ----------------------- ...is required to be `'static` by this...
| |
| data with this lifetime...
| this data with lifetime `'a`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
| ...and is captured here
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the lifetime `'a` as defined on the method body at 10:20
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for lifetime `'a`
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
| ^^^^

View file

@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/issue-16922.rs:4:14
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
| -- data with this lifetime...
| -- this data with the anonymous lifetime `'_`...
LL | Box::new(value) as Box<dyn Any>
| ---------^^^^^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 3:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
| ^^^^

View file

@ -2,12 +2,12 @@ error: cannot infer an appropriate lifetime
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
|
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
| --------------- data with this lifetime...
| --------------- this data with the anonymous lifetime `'_`...
...
LL | ss.r
| ^^^^ ...is captured and required to be `'static` here
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #2 defined on the function body at 14:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {
| ^^^^

View file

@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:8:46
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
| ----- data with this lifetime...
| ----- this data with the anonymous lifetime `'_`...
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
| ---------^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^
@ -22,14 +22,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:13:14
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
| ----- data with this lifetime...
| ----- this data with the anonymous lifetime `'_`...
LL | Box::new(v)
| ---------^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^
@ -42,7 +42,7 @@ error: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:19:14
|
LL | fn c(v: &[u8]) -> Box<dyn Foo> {
| ----- data with this lifetime...
| ----- this data with the anonymous lifetime `'_`...
...
LL | Box::new(v)
| ---------^-
@ -50,7 +50,7 @@ LL | Box::new(v)
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 16:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^^^

View file

@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/regions-close-object-into-object-2.rs:10:11
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
| ------------------ data with this lifetime...
| ------------------ this data with lifetime `'a`...
LL | box B(&*v) as Box<dyn X>
| ------^^^---------------
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'a> {
| ^^

View file

@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/regions-close-object-into-object-4.rs:10:11
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
| ---------------- data with this lifetime...
| ---------------- this data with lifetime `'a`...
LL | box B(&*v) as Box<dyn X>
| ------^^^---------------
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'a> {
| ^^

View file

@ -2,7 +2,7 @@ error: cannot infer an appropriate lifetime
--> $DIR/regions-proc-bound-capture.rs:9:14
|
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
| ------ data with this lifetime...
| ------ this data with the anonymous lifetime `'_`...
LL | // This is illegal, because the region bound on `proc` is 'static.
LL | Box::new(move || { *x })
| ---------^^^^^^^^^^^^^^-
@ -10,7 +10,7 @@ LL | Box::new(move || { *x })
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + '_> {
| ^^

View file

@ -4,7 +4,7 @@ error: cannot infer an appropriate lifetime
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
| ^^^^ ---------- ---------- ...and required to be `'static` by this
| | |
| | data with this lifetime...
| | this data with the anonymous lifetime `'_`...
| ...is captured here...
error: aborting due to previous error

View file

@ -5,9 +5,9 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self }
| ---------- ---------- ^^^^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the method body at 6:5
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
| ^^^^

View file

@ -12,14 +12,14 @@ error: cannot infer an appropriate lifetime
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
| ------ ------------- ...is required to be `'static` by this...
| |
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
...
LL | / move || {
LL | | *dest = g.get();
LL | | }
| |_____^ ...and is captured here
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 15:1
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
| ^^^^

View file

@ -2,12 +2,12 @@ error: cannot infer an appropriate lifetime
--> $DIR/dyn-trait-underscore.rs:8:20
|
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| ---- data with this lifetime...
| ---- this data with the anonymous lifetime `'_`...
LL | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
LL | Box::new(items.iter())
| ---------------^^^^--- ...is captured and required to be `'static` here
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 6:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T> + '_> {
| ^^^^