ide_diagnostics/handlers/
unresolved_assoc_item.rs

1use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
2
3// Diagnostic: unresolved-assoc-item
4//
5// This diagnostic is triggered if the referenced associated item does not exist.
6pub(crate) fn unresolved_assoc_item(
7    ctx: &DiagnosticsContext<'_>,
8    d: &hir::UnresolvedAssocItem,
9) -> Diagnostic {
10    Diagnostic::new_with_syntax_node_ptr(
11        ctx,
12        DiagnosticCode::RustcHardError("E0599"),
13        "no such associated item",
14        d.expr_or_pat.map(Into::into),
15    )
16}
17
18#[cfg(test)]
19mod tests {
20    use crate::tests::check_diagnostics;
21
22    #[test]
23    fn bare() {
24        check_diagnostics(
25            r#"
26struct S;
27
28fn main() {
29    let _ = S::Assoc;
30          //^^^^^^^^ error: no such associated item
31}
32"#,
33        );
34    }
35
36    #[test]
37    fn unimplemented_trait() {
38        check_diagnostics(
39            r#"
40struct S;
41trait Foo {
42    const X: u32;
43}
44
45fn main() {
46    let _ = S::X;
47          //^^^^ error: no such associated item
48}
49"#,
50        );
51    }
52
53    #[test]
54    fn dyn_super_trait_assoc_type() {
55        check_diagnostics(
56            r#"
57//- minicore: future, send
58
59use core::{future::Future, marker::Send, pin::Pin};
60
61trait FusedFuture: Future {
62    fn is_terminated(&self) -> bool;
63}
64
65struct Box<T: ?Sized>(*const T);
66
67fn main() {
68    let _fut: Pin<Box<dyn FusedFuture<Output = ()> + Send>> = loop {};
69}
70"#,
71        );
72    }
73}