about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-05-07 19:54:16 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-05-17 20:31:13 +0000
commit1775e7b93d4142eb2e4c75c2d49a9c4d8541d7a6 (patch)
tree1af69d838ce403b5367e22bb36ed3907ae2b039e /tests
parentee5a157b4a9d51788d7306af63b3e3ef063ec49d (diff)
downloadrust-1775e7b93d4142eb2e4c75c2d49a9c4d8541d7a6.tar.gz
rust-1775e7b93d4142eb2e4c75c2d49a9c4d8541d7a6.zip
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 {
  |                 ++
```
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/lifetimes/issue-17728.stderr4
-rw-r--r--tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.fixed2
-rw-r--r--tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr4
-rw-r--r--tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.fixed2
-rw-r--r--tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr4
-rw-r--r--tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr4
-rw-r--r--tests/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr12
-rw-r--r--tests/ui/self/elision/lt-ref-self.fixed12
-rw-r--r--tests/ui/self/elision/lt-ref-self.stderr24
-rw-r--r--tests/ui/self/elision/ref-mut-self.fixed12
-rw-r--r--tests/ui/self/elision/ref-mut-self.stderr24
-rw-r--r--tests/ui/self/elision/ref-mut-struct.fixed10
-rw-r--r--tests/ui/self/elision/ref-mut-struct.stderr20
-rw-r--r--tests/ui/self/elision/ref-self.fixed14
-rw-r--r--tests/ui/self/elision/ref-self.stderr28
-rw-r--r--tests/ui/self/elision/ref-struct.fixed10
-rw-r--r--tests/ui/self/elision/ref-struct.stderr20
17 files changed, 103 insertions, 103 deletions
diff --git a/tests/ui/lifetimes/issue-17728.stderr b/tests/ui/lifetimes/issue-17728.stderr
index da4ce2dd291..eb4381ea99e 100644
--- a/tests/ui/lifetimes/issue-17728.stderr
+++ b/tests/ui/lifetimes/issue-17728.stderr
@@ -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
 
diff --git a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.fixed b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.fixed
index 3408463ce49..40eee22fc32 100644
--- a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.fixed
+++ b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.fixed
@@ -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
     }
diff --git a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr
index ca6ee1c25cd..345f099542d 100644
--- a/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr
+++ b/tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-return-type-is-anon.stderr
@@ -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
 
diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.fixed b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.fixed
index 3408463ce49..40eee22fc32 100644
--- a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.fixed
+++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.fixed
@@ -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
     }
diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr
index a81b5cfad5a..dd45c8b1cb7 100644
--- a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr
+++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-return-type-is-anon.stderr
@@ -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
 
diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr
index 0a312cf93c8..997537f1ecd 100644
--- a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr
+++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.stderr
@@ -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
 
diff --git a/tests/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr b/tests/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr
index 549b03b061b..98f493f3f91 100644
--- a/tests/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr
+++ b/tests/ui/self/arbitrary_self_types_pin_lifetime_mismatch.stderr
@@ -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
 
diff --git a/tests/ui/self/elision/lt-ref-self.fixed b/tests/ui/self/elision/lt-ref-self.fixed
index ff0c057fe42..1d90eacea50 100644
--- a/tests/ui/self/elision/lt-ref-self.fixed
+++ b/tests/ui/self/elision/lt-ref-self.fixed
@@ -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
     }
diff --git a/tests/ui/self/elision/lt-ref-self.stderr b/tests/ui/self/elision/lt-ref-self.stderr
index 237175ac763..5c8e0a7a742 100644
--- a/tests/ui/self/elision/lt-ref-self.stderr
+++ b/tests/ui/self/elision/lt-ref-self.stderr
@@ -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
 
diff --git a/tests/ui/self/elision/ref-mut-self.fixed b/tests/ui/self/elision/ref-mut-self.fixed
index 7886d097976..42e8050f65e 100644
--- a/tests/ui/self/elision/ref-mut-self.fixed
+++ b/tests/ui/self/elision/ref-mut-self.fixed
@@ -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
     }
diff --git a/tests/ui/self/elision/ref-mut-self.stderr b/tests/ui/self/elision/ref-mut-self.stderr
index a09034e5f71..620706fdbdb 100644
--- a/tests/ui/self/elision/ref-mut-self.stderr
+++ b/tests/ui/self/elision/ref-mut-self.stderr
@@ -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
 
diff --git a/tests/ui/self/elision/ref-mut-struct.fixed b/tests/ui/self/elision/ref-mut-struct.fixed
index 188d3bb517e..f7a84d4a45c 100644
--- a/tests/ui/self/elision/ref-mut-struct.fixed
+++ b/tests/ui/self/elision/ref-mut-struct.fixed
@@ -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
     }
diff --git a/tests/ui/self/elision/ref-mut-struct.stderr b/tests/ui/self/elision/ref-mut-struct.stderr
index 19b09272504..cce07f82718 100644
--- a/tests/ui/self/elision/ref-mut-struct.stderr
+++ b/tests/ui/self/elision/ref-mut-struct.stderr
@@ -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
 
diff --git a/tests/ui/self/elision/ref-self.fixed b/tests/ui/self/elision/ref-self.fixed
index 1369bb83e97..8bf5a0bb223 100644
--- a/tests/ui/self/elision/ref-self.fixed
+++ b/tests/ui/self/elision/ref-self.fixed
@@ -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
     }
diff --git a/tests/ui/self/elision/ref-self.stderr b/tests/ui/self/elision/ref-self.stderr
index a39a6a15385..c4ec8c55a00 100644
--- a/tests/ui/self/elision/ref-self.stderr
+++ b/tests/ui/self/elision/ref-self.stderr
@@ -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
 
diff --git a/tests/ui/self/elision/ref-struct.fixed b/tests/ui/self/elision/ref-struct.fixed
index a9ecbc9c3ae..411f6013195 100644
--- a/tests/ui/self/elision/ref-struct.fixed
+++ b/tests/ui/self/elision/ref-struct.fixed
@@ -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
     }
diff --git a/tests/ui/self/elision/ref-struct.stderr b/tests/ui/self/elision/ref-struct.stderr
index 157e0d40793..860186c8353 100644
--- a/tests/ui/self/elision/ref-struct.stderr
+++ b/tests/ui/self/elision/ref-struct.stderr
@@ -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