Unnamed repository; edit this file 'description' to name the repository.
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};

// Diagnostic: missing-lifetime
//
// This diagnostic is triggered when a lifetime argument is missing.
pub(crate) fn missing_lifetime(
    ctx: &DiagnosticsContext<'_>,
    d: &hir::MissingLifetime,
) -> Diagnostic {
    Diagnostic::new_with_syntax_node_ptr(
        ctx,
        DiagnosticCode::RustcHardError("E0106"),
        "missing lifetime specifier",
        d.generics_or_segment.map(Into::into),
    )
}

#[cfg(test)]
mod tests {
    use crate::tests::check_diagnostics;

    #[test]
    fn in_fields() {
        check_diagnostics(
            r#"
struct Foo<'a>(&'a ());
struct Bar(Foo);
        // ^^^ error: missing lifetime specifier
        "#,
        );
    }

    #[test]
    fn bounds() {
        check_diagnostics(
            r#"
struct Foo<'a, T>(&'a T);
trait Trait<'a> {
    type Assoc;
}

fn foo<'a, T: Trait>(
           // ^^^^^ error: missing lifetime specifier
    _: impl Trait<'a, Assoc: Trait>,
                          // ^^^^^ error: missing lifetime specifier
)
where
    Foo<T>: Trait<'a>,
    // ^^^ error: missing lifetime specifier
{
}
        "#,
        );
    }

    #[test]
    fn generic_defaults() {
        check_diagnostics(
            r#"
struct Foo<'a>(&'a ());

struct Bar<T = Foo>(T);
            // ^^^ error: missing lifetime specifier
        "#,
        );
    }

    #[test]
    fn type_alias_type() {
        check_diagnostics(
            r#"
struct Foo<'a>(&'a ());

type Bar = Foo;
        // ^^^ error: missing lifetime specifier
        "#,
        );
    }

    #[test]
    fn const_param_ty() {
        check_diagnostics(
            r#"
struct Foo<'a>(&'a ());

fn bar<const F: Foo>() {}
             // ^^^ error: missing lifetime specifier
        "#,
        );
    }

    #[test]
    fn fn_traits() {
        check_diagnostics(
            r#"
//- minicore: fn
struct WithLifetime<'a>(&'a ());

fn foo<T: Fn(WithLifetime) -> WithLifetime>() {}
        "#,
        );
    }

    #[test]
    fn regression_21430() {
        check_diagnostics(
            r#"
struct S {
    f: fn(A<()>),
}

struct A<'a, T> {
    a: &'a T,
}
        "#,
        );
    }
}