ide_diagnostics/handlers/
unresolved_assoc_item.rs

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
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};

// Diagnostic: unresolved-assoc-item
//
// This diagnostic is triggered if the referenced associated item does not exist.
pub(crate) fn unresolved_assoc_item(
    ctx: &DiagnosticsContext<'_>,
    d: &hir::UnresolvedAssocItem,
) -> Diagnostic {
    Diagnostic::new_with_syntax_node_ptr(
        ctx,
        DiagnosticCode::RustcHardError("E0599"),
        "no such associated item",
        d.expr_or_pat.map(Into::into),
    )
    .experimental()
}

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

    #[test]
    fn bare() {
        check_diagnostics(
            r#"
struct S;

fn main() {
    let _ = S::Assoc;
          //^^^^^^^^ error: no such associated item
}
"#,
        );
    }

    #[test]
    fn unimplemented_trait() {
        check_diagnostics(
            r#"
struct S;
trait Foo {
    const X: u32;
}

fn main() {
    let _ = S::X;
          //^^^^ error: no such associated item
}
"#,
        );
    }
}