Tweak suggested lifetimes to modify return type instead of &self receiver

Do not suggest constraining the `&self` param, but rather the return type.
If that is wrong (because it is not sufficient), a follow up error will tell the
user to fix it. This way we lower the chances of *over* constraining, but still
get the cake of "correctly" contrained in two steps.

This is a correct suggestion:

```
error: lifetime may not live long enough
  --> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:9:9
   |
LL |     fn foo<'a>(&self, x: &i32) -> &i32 {
   |                -         - let's call the lifetime of this reference `'1`
   |                |
   |                let's call the lifetime of this reference `'2`
LL |         x
   |         ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
   |
help: consider introducing a named lifetime parameter and update trait if needed
   |
LL |     fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
   |                           ++          ++
```

While this is incomplete because it should suggestino `&'a self`

```
error: lifetime may not live long enough
  --> $DIR/ex3-both-anon-regions-self-is-anon.rs:7:19
   |
LL |     fn foo<'a>(&self, x: &Foo) -> &Foo {
   |                -         - let's call the lifetime of this reference `'1`
   |                |
   |                let's call the lifetime of this reference `'2`
LL |         if true { x } else { self }
   |                   ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
   |
help: consider introducing a named lifetime parameter and update trait if needed
   |
LL |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
   |                           ++          ++
```

but the follow up error is

```
error: lifetime may not live long enough
 --> tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.rs:7:30
  |
6 |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
  |            --  - let's call the lifetime of this reference `'1`
  |            |
  |            lifetime `'a` defined here
7 |         if true { x } else { self }
  |                              ^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`
  |
help: consider introducing a named lifetime parameter and update trait if needed
  |
6 |     fn foo<'a>(&'a self, x: &'a Foo) -> &'a Foo {
  |                 ++
```
This commit is contained in:
Esteban Küber 2024-05-07 19:54:16 +00:00
parent ee5a157b4a
commit 1775e7b93d
18 changed files with 111 additions and 105 deletions

View File

@ -484,13 +484,19 @@ fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
suggestions: vec![],
suggestion_param_name: suggestion_param_name.clone(),
};
visitor.visit_ty(self.ty_sub);
visitor.visit_ty(self.ty_sup);
if let Some(fn_decl) = node.fn_decl()
&& let hir::FnRetTy::Return(ty) = fn_decl.output
{
visitor.visit_ty(ty);
}
if visitor.suggestions.is_empty() {
// Do not suggest constraining the `&self` param, but rather the return type.
// If that is wrong (because it is not sufficient), a follow up error will tell the
// user to fix it. This way we lower the chances of *over* constraining, but still
// get the cake of "correctly" contrained in two steps.
visitor.visit_ty(self.ty_sup);
}
visitor.visit_ty(self.ty_sub);
if visitor.suggestions.is_empty() {
return false;
}

View File

@ -29,8 +29,8 @@ LL | Some(entry) => Ok(entry),
|
help: consider introducing a named lifetime parameter
|
LL | fn attemptTraverse<'a>(&'a self, room: &'a Room, directionStr: &str) -> Result<&'a Room, &'a str> {
| ++++ ++ ++ ++ ++
LL | fn attemptTraverse<'a>(&self, room: &'a Room, directionStr: &str) -> Result<&'a Room, &'a str> {
| ++++ ++ ++ ++
error: aborting due to 2 previous errors

View File

@ -5,7 +5,7 @@ struct Foo {
}
impl Foo {
fn foo<'a>(&'a self, x: &'a i32) -> &'a i32 {
fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
x
//~^ ERROR lifetime may not live long enough
}

View File

@ -10,8 +10,8 @@ LL | x
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn foo<'a>(&'a self, x: &'a i32) -> &'a i32 {
| ++ ++
LL | fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
| ++
error: aborting due to 1 previous error

View File

@ -5,7 +5,7 @@ struct Foo {
}
impl Foo {
fn foo<'a>(&'a self, x: &'a i32) -> &'a i32 {
fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
x
//~^ ERROR lifetime may not live long enough
}

View File

@ -10,8 +10,8 @@ LL | x
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn foo<'a>(&'a self, x: &'a i32) -> &'a i32 {
| ++ ++ ++
LL | fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
| ++ ++
error: aborting due to 1 previous error

View File

@ -10,8 +10,8 @@ LL | if true { x } else { self }
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn foo<'a>(&'a self, x: &'a Foo) -> &'a Foo {
| ++ ++ ++
LL | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
| ++ ++
error: aborting due to 1 previous error

View File

@ -10,8 +10,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn a<'a>(self: Pin<&'a Foo>, f: &'a Foo) -> &'a Foo {
| ++++ ++ ++ ++
LL | fn a<'a>(self: Pin<&Foo>, f: &'a Foo) -> &'a Foo {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:14:9
@ -25,8 +25,8 @@ LL | (self, f)
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn c<'a>(self: Pin<&'a Self>, f: &'a Foo, g: &Foo) -> (Pin<&'a Foo>, &'a Foo) {
| ++++ ++ ++ ++ ++
LL | fn c<'a>(self: Pin<&Self>, f: &'a Foo, g: &Foo) -> (Pin<&'a Foo>, &'a Foo) {
| ++++ ++ ++ ++
error: lifetime may not live long enough
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch.rs:21:9
@ -40,8 +40,8 @@ LL | arg
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn bar<'a>(self: Alias<&'a Self>, arg: &'a ()) -> &'a () {
| ++ ++
LL | fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &'a () {
| ++
error: aborting due to 3 previous errors

View File

@ -10,34 +10,34 @@ struct Struct<'a> {
impl<'a> Struct<'a> {
// Test using `&self` sugar:
fn ref_self<'b>(&'b self, f: &'b u32) -> &'b u32 {
fn ref_self<'b>(&self, f: &'b u32) -> &'b u32 {
f
//~^ ERROR lifetime may not live long enough
}
// Test using `&Self` explicitly:
fn ref_Self<'b>(self: &'b Self, f: &'b u32) -> &'b u32 {
fn ref_Self<'b>(self: &Self, f: &'b u32) -> &'b u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_ref_Self<'b>(self: Box<&'b Self>, f: &'b u32) -> &'b u32 {
fn box_ref_Self<'b>(self: Box<&Self>, f: &'b u32) -> &'b u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn pin_ref_Self<'b>(self: Pin<&'b Self>, f: &'b u32) -> &'b u32 {
fn pin_ref_Self<'b>(self: Pin<&Self>, f: &'b u32) -> &'b u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_box_ref_Self<'b>(self: Box<Box<&'b Self>>, f: &'b u32) -> &'b u32 {
fn box_box_ref_Self<'b>(self: Box<Box<&Self>>, f: &'b u32) -> &'b u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_pin_Self<'b>(self: Box<Pin<&'b Self>>, f: &'b u32) -> &'b u32 {
fn box_pin_Self<'b>(self: Box<Pin<&Self>>, f: &'b u32) -> &'b u32 {
f
//~^ ERROR lifetime may not live long enough
}

View File

@ -10,8 +10,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_self<'b>(&'b self, f: &'b u32) -> &'b u32 {
| ++++ ++ ++ ++
LL | fn ref_self<'b>(&self, f: &'b u32) -> &'b u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/lt-ref-self.rs:21:9
@ -25,8 +25,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_Self<'b>(self: &'b Self, f: &'b u32) -> &'b u32 {
| ++++ ++ ++ ++
LL | fn ref_Self<'b>(self: &Self, f: &'b u32) -> &'b u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/lt-ref-self.rs:26:9
@ -40,8 +40,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_ref_Self<'b>(self: Box<&'b Self>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++ ++
LL | fn box_ref_Self<'b>(self: Box<&Self>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/lt-ref-self.rs:31:9
@ -55,8 +55,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn pin_ref_Self<'b>(self: Pin<&'b Self>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++ ++
LL | fn pin_ref_Self<'b>(self: Pin<&Self>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/lt-ref-self.rs:36:9
@ -70,8 +70,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_box_ref_Self<'b>(self: Box<Box<&'b Self>>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++ ++
LL | fn box_box_ref_Self<'b>(self: Box<Box<&Self>>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/lt-ref-self.rs:41:9
@ -85,8 +85,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_pin_Self<'b>(self: Box<Pin<&'b Self>>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++ ++
LL | fn box_pin_Self<'b>(self: Box<Pin<&Self>>, f: &'b u32) -> &'b u32 {
| ++++ ++ ++
error: aborting due to 6 previous errors

View File

@ -8,34 +8,34 @@ struct Struct {}
impl Struct {
// Test using `&mut self` sugar:
fn ref_self<'a>(&'a mut self, f: &'a u32) -> &'a u32 {
fn ref_self<'a>(&mut self, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
// Test using `&mut Self` explicitly:
fn ref_Self<'a>(self: &'a mut Self, f: &'a u32) -> &'a u32 {
fn ref_Self<'a>(self: &mut Self, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_ref_Self<'a>(self: Box<&'a mut Self>, f: &'a u32) -> &'a u32 {
fn box_ref_Self<'a>(self: Box<&mut Self>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn pin_ref_Self<'a>(self: Pin<&'a mut Self>, f: &'a u32) -> &'a u32 {
fn pin_ref_Self<'a>(self: Pin<&mut Self>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_box_ref_Self<'a>(self: Box<Box<&'a mut Self>>, f: &'a u32) -> &'a u32 {
fn box_box_ref_Self<'a>(self: Box<Box<&mut Self>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_pin_ref_Self<'a>(self: Box<Pin<&'a mut Self>>, f: &'a u32) -> &'a u32 {
fn box_pin_ref_Self<'a>(self: Box<Pin<&mut Self>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}

View File

@ -10,8 +10,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_self<'a>(&'a mut self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn ref_self<'a>(&mut self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-self.rs:19:9
@ -25,8 +25,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_Self<'a>(self: &'a mut Self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn ref_Self<'a>(self: &mut Self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-self.rs:24:9
@ -40,8 +40,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_ref_Self<'a>(self: Box<&'a mut Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_ref_Self<'a>(self: Box<&mut Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-self.rs:29:9
@ -55,8 +55,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn pin_ref_Self<'a>(self: Pin<&'a mut Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn pin_ref_Self<'a>(self: Pin<&mut Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-self.rs:34:9
@ -70,8 +70,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_box_ref_Self<'a>(self: Box<Box<&'a mut Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_box_ref_Self<'a>(self: Box<Box<&mut Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-self.rs:39:9
@ -85,8 +85,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_pin_ref_Self<'a>(self: Box<Pin<&'a mut Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_pin_ref_Self<'a>(self: Box<Pin<&mut Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: aborting due to 6 previous errors

View File

@ -8,27 +8,27 @@ struct Struct {}
impl Struct {
// Test using `&mut Struct` explicitly:
fn ref_Struct<'a>(self: &'a mut Struct, f: &'a u32) -> &'a u32 {
fn ref_Struct<'a>(self: &mut Struct, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_ref_Struct<'a>(self: Box<&'a mut Struct>, f: &'a u32) -> &'a u32 {
fn box_ref_Struct<'a>(self: Box<&mut Struct>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn pin_ref_Struct<'a>(self: Pin<&'a mut Struct>, f: &'a u32) -> &'a u32 {
fn pin_ref_Struct<'a>(self: Pin<&mut Struct>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_box_ref_Struct<'a>(self: Box<Box<&'a mut Struct>>, f: &'a u32) -> &'a u32 {
fn box_box_ref_Struct<'a>(self: Box<Box<&mut Struct>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_pin_ref_Struct<'a>(self: Box<Pin<&'a mut Struct>>, f: &'a u32) -> &'a u32 {
fn box_pin_ref_Struct<'a>(self: Box<Pin<&mut Struct>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}

View File

@ -10,8 +10,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_Struct<'a>(self: &'a mut Struct, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn ref_Struct<'a>(self: &mut Struct, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-struct.rs:17:9
@ -25,8 +25,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_ref_Struct<'a>(self: Box<&'a mut Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_ref_Struct<'a>(self: Box<&mut Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-struct.rs:22:9
@ -40,8 +40,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn pin_ref_Struct<'a>(self: Pin<&'a mut Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn pin_ref_Struct<'a>(self: Pin<&mut Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-struct.rs:27:9
@ -55,8 +55,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_box_ref_Struct<'a>(self: Box<Box<&'a mut Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_box_ref_Struct<'a>(self: Box<Box<&mut Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-mut-struct.rs:32:9
@ -70,8 +70,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_pin_ref_Struct<'a>(self: Box<Pin<&'a mut Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_pin_ref_Struct<'a>(self: Box<Pin<&mut Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: aborting due to 5 previous errors

View File

@ -20,39 +20,39 @@ impl<T, P> Deref for Wrap<T, P> {
impl Struct {
// Test using `&self` sugar:
fn ref_self<'a>(&'a self, f: &'a u32) -> &'a u32 {
fn ref_self<'a>(&self, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
// Test using `&Self` explicitly:
fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &'a u32 {
fn ref_Self<'a>(self: &Self, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &'a u32 {
fn box_ref_Self<'a>(self: Box<&Self>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &'a u32 {
fn pin_ref_Self<'a>(self: Pin<&Self>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_box_ref_Self<'a>(self: Box<Box<&'a Self>>, f: &'a u32) -> &'a u32 {
fn box_box_ref_Self<'a>(self: Box<Box<&Self>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_pin_ref_Self<'a>(self: Box<Pin<&'a Self>>, f: &'a u32) -> &'a u32 {
fn box_pin_ref_Self<'a>(self: Box<Pin<&Self>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn wrap_ref_Self_Self<'a>(self: Wrap<&'a Self, Self>, f: &'a u8) -> &'a u8 {
fn wrap_ref_Self_Self<'a>(self: Wrap<&Self, Self>, f: &'a u8) -> &'a u8 {
f
//~^ ERROR lifetime may not live long enough
}

View File

@ -10,8 +10,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_self<'a>(&'a self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn ref_self<'a>(&self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-self.rs:31:9
@ -25,8 +25,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn ref_Self<'a>(self: &Self, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-self.rs:36:9
@ -40,8 +40,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_ref_Self<'a>(self: Box<&Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-self.rs:41:9
@ -55,8 +55,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn pin_ref_Self<'a>(self: Pin<&Self>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-self.rs:46:9
@ -70,8 +70,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_box_ref_Self<'a>(self: Box<Box<&'a Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_box_ref_Self<'a>(self: Box<Box<&Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-self.rs:51:9
@ -85,8 +85,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_pin_ref_Self<'a>(self: Box<Pin<&'a Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_pin_ref_Self<'a>(self: Box<Pin<&Self>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-self.rs:56:9
@ -100,8 +100,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn wrap_ref_Self_Self<'a>(self: Wrap<&'a Self, Self>, f: &'a u8) -> &'a u8 {
| ++++ ++ ++ ++
LL | fn wrap_ref_Self_Self<'a>(self: Wrap<&Self, Self>, f: &'a u8) -> &'a u8 {
| ++++ ++ ++
error: aborting due to 7 previous errors

View File

@ -8,27 +8,27 @@ struct Struct {}
impl Struct {
// Test using `&Struct` explicitly:
fn ref_Struct<'a>(self: &'a Struct, f: &'a u32) -> &'a u32 {
fn ref_Struct<'a>(self: &Struct, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_ref_Struct<'a>(self: Box<&'a Struct>, f: &'a u32) -> &'a u32 {
fn box_ref_Struct<'a>(self: Box<&Struct>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn pin_ref_Struct<'a>(self: Pin<&'a Struct>, f: &'a u32) -> &'a u32 {
fn pin_ref_Struct<'a>(self: Pin<&Struct>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_box_ref_Struct<'a>(self: Box<Box<&'a Struct>>, f: &'a u32) -> &'a u32 {
fn box_box_ref_Struct<'a>(self: Box<Box<&Struct>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}
fn box_pin_Struct<'a>(self: Box<Pin<&'a Struct>>, f: &'a u32) -> &'a u32 {
fn box_pin_Struct<'a>(self: Box<Pin<&Struct>>, f: &'a u32) -> &'a u32 {
f
//~^ ERROR lifetime may not live long enough
}

View File

@ -10,8 +10,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn ref_Struct<'a>(self: &'a Struct, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn ref_Struct<'a>(self: &Struct, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-struct.rs:17:9
@ -25,8 +25,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_ref_Struct<'a>(self: Box<&'a Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_ref_Struct<'a>(self: Box<&Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-struct.rs:22:9
@ -40,8 +40,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn pin_ref_Struct<'a>(self: Pin<&'a Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn pin_ref_Struct<'a>(self: Pin<&Struct>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-struct.rs:27:9
@ -55,8 +55,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_box_ref_Struct<'a>(self: Box<Box<&'a Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_box_ref_Struct<'a>(self: Box<Box<&Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/ref-struct.rs:32:9
@ -70,8 +70,8 @@ LL | f
|
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn box_pin_Struct<'a>(self: Box<Pin<&'a Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++ ++
LL | fn box_pin_Struct<'a>(self: Box<Pin<&Struct>>, f: &'a u32) -> &'a u32 {
| ++++ ++ ++
error: aborting due to 5 previous errors