diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index f60ecb3f453a..9998f089588a 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -484,13 +484,19 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { 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; } diff --git a/tests/ui/lifetimes/issue-17728.stderr b/tests/ui/lifetimes/issue-17728.stderr index da4ce2dd2911..eb4381ea99ee 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 3408463ce499..40eee22fc321 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 ca6ee1c25cdd..345f099542d9 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 3408463ce499..40eee22fc321 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 a81b5cfad5a5..dd45c8b1cb77 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 0a312cf93c8d..997537f1ecd9 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 549b03b061bc..98f493f3f91d 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 ff0c057fe427..1d90eacea50d 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>, f: &'b u32) -> &'b u32 { + fn box_box_ref_Self<'b>(self: Box>, f: &'b u32) -> &'b u32 { f //~^ ERROR lifetime may not live long enough } - fn box_pin_Self<'b>(self: Box>, f: &'b u32) -> &'b u32 { + fn box_pin_Self<'b>(self: Box>, 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 237175ac7635..5c8e0a7a742a 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>, f: &'b u32) -> &'b u32 { - | ++++ ++ ++ ++ +LL | fn box_box_ref_Self<'b>(self: Box>, 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>, f: &'b u32) -> &'b u32 { - | ++++ ++ ++ ++ +LL | fn box_pin_Self<'b>(self: Box>, 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 7886d0979761..42e8050f65e3 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>, f: &'a u32) -> &'a u32 { + fn box_box_ref_Self<'a>(self: Box>, f: &'a u32) -> &'a u32 { f //~^ ERROR lifetime may not live long enough } - fn box_pin_ref_Self<'a>(self: Box>, f: &'a u32) -> &'a u32 { + fn box_pin_ref_Self<'a>(self: Box>, 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 a09034e5f71d..620706fdbdbc 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_box_ref_Self<'a>(self: Box>, 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_pin_ref_Self<'a>(self: Box>, 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 188d3bb517e0..f7a84d4a45c7 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>, f: &'a u32) -> &'a u32 { + fn box_box_ref_Struct<'a>(self: Box>, f: &'a u32) -> &'a u32 { f //~^ ERROR lifetime may not live long enough } - fn box_pin_ref_Struct<'a>(self: Box>, f: &'a u32) -> &'a u32 { + fn box_pin_ref_Struct<'a>(self: Box>, 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 19b09272504e..cce07f827184 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_box_ref_Struct<'a>(self: Box>, 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_pin_ref_Struct<'a>(self: Box>, 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 1369bb83e970..8bf5a0bb2232 100644 --- a/tests/ui/self/elision/ref-self.fixed +++ b/tests/ui/self/elision/ref-self.fixed @@ -20,39 +20,39 @@ impl Deref for Wrap { 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>, f: &'a u32) -> &'a u32 { + fn box_box_ref_Self<'a>(self: Box>, f: &'a u32) -> &'a u32 { f //~^ ERROR lifetime may not live long enough } - fn box_pin_ref_Self<'a>(self: Box>, f: &'a u32) -> &'a u32 { + fn box_pin_ref_Self<'a>(self: Box>, 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 a39a6a15385e..c4ec8c55a003 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_box_ref_Self<'a>(self: Box>, 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_pin_ref_Self<'a>(self: Box>, 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 a9ecbc9c3aec..411f60131956 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>, f: &'a u32) -> &'a u32 { + fn box_box_ref_Struct<'a>(self: Box>, f: &'a u32) -> &'a u32 { f //~^ ERROR lifetime may not live long enough } - fn box_pin_Struct<'a>(self: Box>, f: &'a u32) -> &'a u32 { + fn box_pin_Struct<'a>(self: Box>, 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 157e0d407932..860186c83532 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_box_ref_Struct<'a>(self: Box>, 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>, f: &'a u32) -> &'a u32 { - | ++++ ++ ++ ++ +LL | fn box_pin_Struct<'a>(self: Box>, f: &'a u32) -> &'a u32 { + | ++++ ++ ++ error: aborting due to 5 previous errors