about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-03-28 16:44:39 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2025-05-02 07:13:24 +1000
commitb2bf951dd60a57b423ab0a3f6b544ff580a08cd1 (patch)
tree88a6ea453b367409ea991ff94396ba9b00965017
parent251cda5e1f0057eb04fd9fc1653f2f1e010e8f97 (diff)
downloadrust-b2bf951dd60a57b423ab0a3f6b544ff580a08cd1.tar.gz
rust-b2bf951dd60a57b423ab0a3f6b544ff580a08cd1.zip
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, >`
-rw-r--r--tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs11
-rw-r--r--tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr59
2 files changed, 65 insertions, 5 deletions
diff --git a/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
index 443a7e3835e..f5c3da847c7 100644
--- a/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
+++ b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
@@ -49,6 +49,17 @@ mod alone_in_path {
     //~| ERROR missing lifetime specifier
 }
 
+mod alone_in_path2 {
+    trait Foo<'a> { fn next(&mut self) -> Option<&'a ()>; }
+
+    fn f(_: impl Foo<>) {}
+    //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
+
+    fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
+    //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
+    //~| ERROR missing lifetime specifier
+}
+
 mod in_path {
     trait Foo<'a, T> { fn next(&mut self) -> Option<&'a T>; }
 
diff --git a/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
index 24013c85c87..e7dbb06987a 100644
--- a/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
+++ b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
@@ -108,7 +108,28 @@ LL +     fn g(mut x: impl Foo) -> Option<()> { x.next() }
    |
 
 error[E0106]: missing lifetime specifier
-  --> $DIR/impl-trait-missing-lifetime-gated.rs:58:41
+  --> $DIR/impl-trait-missing-lifetime-gated.rs:58:39
+   |
+LL |     fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
+   |                                       ^ expected named lifetime parameter
+   |
+   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
+help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
+   |
+LL |     fn g(mut x: impl Foo<>) -> Option<&'static ()> { x.next() }
+   |                                        +++++++
+help: consider introducing a named lifetime parameter
+   |
+LL |     fn g<'a>(mut x: impl Foo<>) -> Option<&'a ()> { x.next() }
+   |         ++++                               ++
+help: alternatively, you might want to return an owned value
+   |
+LL -     fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
+LL +     fn g(mut x: impl Foo<>) -> Option<()> { x.next() }
+   |
+
+error[E0106]: missing lifetime specifier
+  --> $DIR/impl-trait-missing-lifetime-gated.rs:69:41
    |
 LL |     fn g(mut x: impl Foo<()>) -> Option<&()> { x.next() }
    |                                         ^ expected named lifetime parameter
@@ -129,7 +150,7 @@ LL +     fn g(mut x: impl Foo<()>) -> Option<()> { x.next() }
    |
 
 warning: elided lifetime has a name
-  --> $DIR/impl-trait-missing-lifetime-gated.rs:64:57
+  --> $DIR/impl-trait-missing-lifetime-gated.rs:75:57
    |
 LL | fn resolved_anonymous<'a, T: 'a>(f: impl Fn(&'a str) -> &T) {
    |                       -- 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() }
    |         ++++                ++++
 
 error[E0658]: anonymous lifetimes in `impl Trait` are unstable
-  --> $DIR/impl-trait-missing-lifetime-gated.rs:55:22
+  --> $DIR/impl-trait-missing-lifetime-gated.rs:55:21
+   |
+LL |     fn f(_: impl Foo<>) {}
+   |                     ^ expected named lifetime parameter
+   |
+   = help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+help: consider introducing a named lifetime parameter
+   |
+LL -     fn f(_: impl Foo<>) {}
+LL +     fn f<'a>(_: impl Foo'a, >) {}
+   |
+
+error[E0658]: anonymous lifetimes in `impl Trait` are unstable
+  --> $DIR/impl-trait-missing-lifetime-gated.rs:58:25
+   |
+LL |     fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
+   |                         ^ expected named lifetime parameter
+   |
+   = help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+help: consider introducing a named lifetime parameter
+   |
+LL -     fn g(mut x: impl Foo<>) -> Option<&()> { x.next() }
+LL +     fn g<'a>(mut x: impl Foo'a, >) -> Option<&()> { x.next() }
+   |
+
+error[E0658]: anonymous lifetimes in `impl Trait` are unstable
+  --> $DIR/impl-trait-missing-lifetime-gated.rs:66:22
    |
 LL |     fn f(_: impl Foo<()>) {}
    |                      ^ expected named lifetime parameter
@@ -230,7 +279,7 @@ LL |     fn f<'a>(_: impl Foo<'a, ()>) {}
    |         ++++             +++
 
 error[E0658]: anonymous lifetimes in `impl Trait` are unstable
-  --> $DIR/impl-trait-missing-lifetime-gated.rs:58:26
+  --> $DIR/impl-trait-missing-lifetime-gated.rs:69:26
    |
 LL |     fn g(mut x: impl Foo<()>) -> Option<&()> { x.next() }
    |                          ^ expected named lifetime parameter
@@ -242,7 +291,7 @@ help: consider introducing a named lifetime parameter
 LL |     fn g<'a>(mut x: impl Foo<'a, ()>) -> Option<&()> { x.next() }
    |         ++++                 +++
 
-error: aborting due to 14 previous errors; 1 warning emitted
+error: aborting due to 17 previous errors; 1 warning emitted
 
 Some errors have detailed explanations: E0106, E0658.
 For more information about an error, try `rustc --explain E0106`.