summaryrefslogtreecommitdiffstats
path: root/tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
blob: a1a51c4814e8fc980918e2c5735859d52f39d0a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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() {}