]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
Rollup merge of #107264 - ferrocene:pa-private-items, r=Mark-Simulacrum
[rust.git] / tests / ui / suggestions / impl-trait-missing-lifetime-gated.rs
1 // edition:2021
2 // gate-test-anonymous_lifetime_in_impl_trait
3 // Verify the behaviour of `feature(anonymous_lifetime_in_impl_trait)`.
4
5 mod elided {
6     fn f(_: impl Iterator<Item = &()>) {}
7     //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
8
9     fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { x.next() }
10     //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
11     //~| ERROR missing lifetime specifier
12
13     // Anonymous lifetimes in async fn are already allowed.
14     // This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
15     async fn h(_: impl Iterator<Item = &()>) {}
16
17     // Anonymous lifetimes in async fn are already allowed.
18     // But that lifetime does not participate in resolution.
19     async fn i(mut x: impl Iterator<Item = &()>) -> Option<&()> { x.next() }
20     //~^ ERROR missing lifetime specifier
21 }
22
23 mod underscore {
24     fn f(_: impl Iterator<Item = &'_ ()>) {}
25     //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
26
27     fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
28     //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
29     //~| ERROR missing lifetime specifier
30
31     // Anonymous lifetimes in async fn are already allowed.
32     // This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
33     async fn h(_: impl Iterator<Item = &'_ ()>) {}
34
35     // Anonymous lifetimes in async fn are already allowed.
36     // But that lifetime does not participate in resolution.
37     async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
38     //~^ ERROR missing lifetime specifier
39 }
40
41 mod alone_in_path {
42     trait Foo<'a> { fn next(&mut self) -> Option<&'a ()>; }
43
44     fn f(_: impl Foo) {}
45     //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
46
47     fn g(mut x: impl Foo) -> Option<&()> { x.next() }
48     //~^ ERROR anonymous lifetimes in `impl Trait` are unstable
49     //~| ERROR missing lifetime specifier
50 }
51
52 mod in_path {
53     trait Foo<'a, T> { fn next(&mut self) -> Option<&'a T>; }
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
63 // This must not err, as the `&` actually resolves to `'a`.
64 fn resolved_anonymous<'a, T>(f: impl Fn(&'a str) -> &T) {
65     f("f")
66 }
67
68 fn main() {}