Added help message for impl trait static constraint.

This commit is contained in:
David Wood 2018-09-02 11:10:51 +02:00
parent 78b21643a8
commit 6bf131f3f4
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
5 changed files with 73 additions and 15 deletions

View file

@ -11,12 +11,20 @@ error: unsatisfied lifetime constraints
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
help: you can add a constraint to the return type to make it last less than `'static` and match 'a
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ^^^^^^^^^^^^^^
error: unsatisfied lifetime constraints
--> $DIR/must_outlive_least_region_or_bound.rs:22:69
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
help: you can add a constraint to the return type to make it last less than `'static` and match 'a
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static + 'a { x }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsatisfied lifetime constraints
--> $DIR/must_outlive_least_region_or_bound.rs:29:5

View file

@ -5,6 +5,10 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
| - let's call the lifetime of this reference `'1`
LL | self.x.iter().map(|a| a.0)
| ^^^^^^ cast requires that `'1` must outlive `'static`
help: you can add a constraint to the return type to make it last less than `'static` and match '1
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsatisfied lifetime constraints
--> $DIR/static-return-lifetime-infered.rs:21:9
@ -13,6 +17,10 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| -- lifetime `'a` defined here
LL | self.x.iter().map(|a| a.0)
| ^^^^^^ cast requires that `'a` must outlive `'static`
help: you can add a constraint to the return type to make it last less than `'static` and match 'a
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors