11// https://github.com/rust-lang/rust/issues/101393
22//@ run-rustfix
3- #![allow(unused, mismatched_lifetime_syntaxes )]
3+ #![allow(unused)]
44
55mod _struct {
6- pub struct Path<'a> {
7- string: &'a mut String ,
6+ pub struct Path<'a, T = String > {
7+ string: &'a mut T ,
88 }
99
1010 impl<'a> Path<'a> {
1111 //~^ NOTE lifetime `'a` defined here
1212 //~| NOTE lifetime `'a` defined here
1313 //~| NOTE lifetime `'a` defined here
14- pub fn sub(&mut self) -> Path/* <'_>*/ {
14+ pub fn sub(&mut self) -> Path<'_> {
1515 //~^ NOTE: let's call the lifetime of this reference `'1`
16- // FIXME(estebank): we should extend the diagnostic to mention that `Path` in the
17- // return type has a hidden `'_ ` lifetime in it.
16+ //~| NOTE: this returned type has an implicit lifetime `'1`
17+ //~| HELP: consider making explicit the implicit `'1 ` lifetime in the return type
1818 Path {
1919 //~^ NOTE: requires lifetime `'a` from the `impl`
2020 //~| HELP: consider using the type's name directly instead
@@ -23,8 +23,10 @@ mod _struct {
2323 //~| NOTE: this usage requires that `'1` must outlive `'a`
2424 }
2525 }
26- pub fn sup(&mut self) -> Path/* <'_>*/ {
26+ pub fn sup(&mut self) -> Path<'_> {
2727 //~^ NOTE: let's call the lifetime of this reference `'1`
28+ //~| NOTE: this returned type has an implicit lifetime `'1`
29+ //~| HELP: consider making explicit the implicit `'1` lifetime in the return type
2830 let x = Path {
2931 //~^ NOTE: requires lifetime `'a` from the `impl`
3032 //~| HELP: consider using the type's name directly instead
@@ -34,8 +36,10 @@ mod _struct {
3436 };
3537 x
3638 }
37- pub fn soup(&mut self) -> Path/* <'_>*/ {
39+ pub fn soup(&mut self) -> Path<'_> {
3840 //~^ NOTE: let's call the lifetime of this reference `'1`
41+ //~| NOTE: this returned type has an implicit lifetime `'1`
42+ //~| HELP: consider making explicit the implicit `'1` lifetime in the return type
3943 let x: Path<'_> = Path {
4044 //~^ ERROR: lifetime may not live long enough
4145 //~| NOTE: type annotation requires that `'1` must outlive `'a`
@@ -47,15 +51,76 @@ mod _struct {
4751 }
4852}
4953
54+ mod _struct2 {
55+ pub struct Path<'a, T = String> {
56+ string: &'a mut T,
57+ }
58+
59+ impl<'a> Path<'a, String> {
60+ //~^ NOTE lifetime `'a` defined here
61+ //~| NOTE lifetime `'a` defined here
62+ //~| NOTE lifetime `'a` defined here
63+ //~| NOTE lifetime `'a` defined here
64+ pub fn sub(&mut self) -> Path<'_, String> {
65+ //~^ NOTE: let's call the lifetime of this reference `'1`
66+ //~| NOTE: there is an implicit lifetime `'1` in this parameter list
67+ //~| HELP: consider making explicit the implicit `'1` lifetime in the return type
68+ Path {
69+ //~^ NOTE: requires lifetime `'a` from the `impl`
70+ //~| HELP: consider using the type's name directly instead
71+ string: self.string,
72+ //~^ ERROR: lifetime may not live long enough
73+ //~| NOTE: this usage requires that `'1` must outlive `'a`
74+ }
75+ }
76+ pub fn sup(&mut self) -> Path<'_> {
77+ //~^ NOTE: let's call the lifetime of this reference `'1`
78+ //~| NOTE: there is an implicit lifetime `'1` in this empty parameter list
79+ //~| HELP: consider making explicit the implicit `'1` lifetime in the return type
80+ let x = Path {
81+ //~^ NOTE: requires lifetime `'a` from the `impl`
82+ //~| HELP: consider using the type's name directly instead
83+ string: self.string,
84+ //~^ ERROR: lifetime may not live long enough
85+ //~| NOTE: this usage requires that `'1` must outlive `'a`
86+ };
87+ x
88+ }
89+ pub fn soup(&mut self) -> Path<'_> {
90+ //~^ NOTE: let's call the lifetime of this reference `'1`
91+ let x: Path<'_> = Path {
92+ //~^ ERROR: lifetime may not live long enough
93+ //~| NOTE: type annotation requires that `'1` must outlive `'a`
94+ //~| HELP: consider using the type directly instead
95+ string: self.string,
96+ };
97+ x
98+ }
99+ pub fn sap<'b>(&'b mut self) -> Path<'b> {
100+ //~^ NOTE: lifetime `'b` defined here
101+ Path {
102+ //~^ NOTE: requires lifetime `'a` from the `impl`
103+ //~| HELP: consider using the type's name directly instead
104+ string: self.string,
105+ //~^ ERROR: lifetime may not live long enough
106+ //~| NOTE: this usage requires that `'b` must outlive `'a`
107+ //~| HELP: consider adding the following bound: `'b: 'a`
108+ }
109+ }
110+ }
111+ }
112+
50113mod tuple_struct {
51114 pub struct Path<'a>(&'a mut String);
52115
53116 impl<'a> Path<'a> {
54117 //~^ NOTE lifetime `'a` defined here
55118 //~| NOTE lifetime `'a` defined here
56119 //~| NOTE lifetime `'a` defined here
57- pub fn sub(&mut self) -> Path/* <'_>*/ {
120+ pub fn sub(&mut self) -> Path<'_> {
58121 //~^ NOTE: let's call the lifetime of this reference `'1`
122+ //~| NOTE: this returned type has an implicit lifetime `'1`
123+ //~| HELP: consider making explicit the implicit `'1` lifetime in the return type
59124 Path(
60125 //~^ HELP: consider using the type's name directly instead
61126 //~| NOTE: requires lifetime `'a` from the `impl`
@@ -64,8 +129,10 @@ mod tuple_struct {
64129 //~| NOTE: this usage requires that `'1` must outlive `'a`
65130 )
66131 }
67- pub fn sup(&mut self) -> Path/* <'_>*/ {
132+ pub fn sup(&mut self) -> Path<'_> {
68133 //~^ NOTE: let's call the lifetime of this reference `'1`
134+ //~| NOTE: this returned type has an implicit lifetime `'1`
135+ //~| HELP: consider making explicit the implicit `'1` lifetime in the return type
69136 let x = Path(
70137 //~^ NOTE: requires lifetime `'a` from the `impl`
71138 //~| HELP: consider using the type's name directly instead
@@ -75,8 +142,10 @@ mod tuple_struct {
75142 );
76143 x
77144 }
78- pub fn soup(&mut self) -> Path/* <'_>*/ {
145+ pub fn soup(&mut self) -> Path<'_> {
79146 //~^ NOTE: let's call the lifetime of this reference `'1`
147+ //~| NOTE: this returned type has an implicit lifetime `'1`
148+ //~| HELP: consider making explicit the implicit `'1` lifetime in the return type
80149 let x: Path<'_> = Path(
81150 //~^ ERROR: lifetime may not live long enough
82151 //~| NOTE: type annotation requires that `'1` must outlive `'a`
0 commit comments