summaryrefslogtreecommitdiffstats
path: root/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs')
-rw-r--r--tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
new file mode 100644
index 000000000..a1a51c481
--- /dev/null
+++ b/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
@@ -0,0 +1,68 @@
+// edition:2021
+// gate-test-anonymous_lifetime_in_impl_trait
+// Verify the behaviour of `feature(anonymous_lifetime_in_impl_trait)`.
+
+mod elided {
+ fn f(_: impl Iterator<Item = &()>) {}
+ //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
+
+ fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { x.next() }
+ //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
+ //~| ERROR missing lifetime specifier
+
+ // Anonymous lifetimes in async fn are already allowed.
+ // This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
+ async fn h(_: impl Iterator<Item = &()>) {}
+
+ // Anonymous lifetimes in async fn are already allowed.
+ // But that lifetime does not participate in resolution.
+ async fn i(mut x: impl Iterator<Item = &()>) -> Option<&()> { x.next() }
+ //~^ ERROR missing lifetime specifier
+}
+
+mod underscore {
+ fn f(_: impl Iterator<Item = &'_ ()>) {}
+ //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
+
+ fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
+ //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
+ //~| ERROR missing lifetime specifier
+
+ // Anonymous lifetimes in async fn are already allowed.
+ // This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
+ async fn h(_: impl Iterator<Item = &'_ ()>) {}
+
+ // Anonymous lifetimes in async fn are already allowed.
+ // But that lifetime does not participate in resolution.
+ async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
+ //~^ ERROR missing lifetime specifier
+}
+
+mod alone_in_path {
+ 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>; }
+
+ 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
+}
+
+// This must not err, as the `&` actually resolves to `'a`.
+fn resolved_anonymous<'a, T>(f: impl Fn(&'a str) -> &T) {
+ f("f")
+}
+
+fn main() {}