Skip to content

Commit b2bf951

Browse files
committed
Augment impl-trait-missing-lifetime-gated.rs.
We have coverage for `Foo` and `Foo<T>` but not for `Foo<>`. This commit adds it. Note that the output has bogus syntax: `impl Foo'a, >`
1 parent 251cda5 commit b2bf951

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ mod alone_in_path {
4949
//~| ERROR missing lifetime specifier
5050
}
5151

52+
mod alone_in_path2 {
53+
trait Foo<'a> { fn next(&mut self) -> Option<&'a ()>; }
54+
55+
fn f(_: impl Foo<>) {}
56+
//~^ ERROR anonymous lifetimes in `impl Trait` are unstable
57+
58+
fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
59+
//~^ ERROR anonymous lifetimes in `impl Trait` are unstable
60+
//~| ERROR missing lifetime specifier
61+
}
62+
5263
mod in_path {
5364
trait Foo<'a, T> { fn next(&mut self) -> Option<&'a T>; }
5465

tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr

+54-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,28 @@ LL + fn g(mut x: impl Foo) -> Option<()> { x.next() }
108108
|
109109

110110
error[E0106]: missing lifetime specifier
111-
--> $DIR/impl-trait-missing-lifetime-gated.rs:58:41
111+
--> $DIR/impl-trait-missing-lifetime-gated.rs:58:39
112+
|
113+
LL | fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
114+
| ^ expected named lifetime parameter
115+
|
116+
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
117+
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
118+
|
119+
LL | fn g(mut x: impl Foo<>) -> Option<&'static ()> { x.next() }
120+
| +++++++
121+
help: consider introducing a named lifetime parameter
122+
|
123+
LL | fn g<'a>(mut x: impl Foo<>) -> Option<&'a ()> { x.next() }
124+
| ++++ ++
125+
help: alternatively, you might want to return an owned value
126+
|
127+
LL - fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
128+
LL + fn g(mut x: impl Foo<>) -> Option<()> { x.next() }
129+
|
130+
131+
error[E0106]: missing lifetime specifier
132+
--> $DIR/impl-trait-missing-lifetime-gated.rs:69:41
112133
|
113134
LL | fn g(mut x: impl Foo<()>) -> Option<&()> { x.next() }
114135
| ^ expected named lifetime parameter
@@ -129,7 +150,7 @@ LL + fn g(mut x: impl Foo<()>) -> Option<()> { x.next() }
129150
|
130151

131152
warning: elided lifetime has a name
132-
--> $DIR/impl-trait-missing-lifetime-gated.rs:64:57
153+
--> $DIR/impl-trait-missing-lifetime-gated.rs:75:57
133154
|
134155
LL | fn resolved_anonymous<'a, T: 'a>(f: impl Fn(&'a str) -> &T) {
135156
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
@@ -217,7 +238,35 @@ LL | fn g<'a>(mut x: impl Foo<'a>) -> Option<&()> { x.next() }
217238
| ++++ ++++
218239

219240
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
220-
--> $DIR/impl-trait-missing-lifetime-gated.rs:55:22
241+
--> $DIR/impl-trait-missing-lifetime-gated.rs:55:21
242+
|
243+
LL | fn f(_: impl Foo<>) {}
244+
| ^ expected named lifetime parameter
245+
|
246+
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
247+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
248+
help: consider introducing a named lifetime parameter
249+
|
250+
LL - fn f(_: impl Foo<>) {}
251+
LL + fn f<'a>(_: impl Foo'a, >) {}
252+
|
253+
254+
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
255+
--> $DIR/impl-trait-missing-lifetime-gated.rs:58:25
256+
|
257+
LL | fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
258+
| ^ expected named lifetime parameter
259+
|
260+
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
261+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
262+
help: consider introducing a named lifetime parameter
263+
|
264+
LL - fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
265+
LL + fn g<'a>(mut x: impl Foo'a, >) -> Option<&()> { x.next() }
266+
|
267+
268+
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
269+
--> $DIR/impl-trait-missing-lifetime-gated.rs:66:22
221270
|
222271
LL | fn f(_: impl Foo<()>) {}
223272
| ^ expected named lifetime parameter
@@ -230,7 +279,7 @@ LL | fn f<'a>(_: impl Foo<'a, ()>) {}
230279
| ++++ +++
231280

232281
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
233-
--> $DIR/impl-trait-missing-lifetime-gated.rs:58:26
282+
--> $DIR/impl-trait-missing-lifetime-gated.rs:69:26
234283
|
235284
LL | fn g(mut x: impl Foo<()>) -> Option<&()> { x.next() }
236285
| ^ expected named lifetime parameter
@@ -242,7 +291,7 @@ help: consider introducing a named lifetime parameter
242291
LL | fn g<'a>(mut x: impl Foo<'a, ()>) -> Option<&()> { x.next() }
243292
| ++++ +++
244293

245-
error: aborting due to 14 previous errors; 1 warning emitted
294+
error: aborting due to 17 previous errors; 1 warning emitted
246295

247296
Some errors have detailed explanations: E0106, E0658.
248297
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)