aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics/unresolved_extern_crate.rs
blob: 2ea79c2eee1c894bf7c051db21267ca2e33daf7b (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
use crate::diagnostics::{Diagnostic, DiagnosticsContext};

// Diagnostic: unresolved-extern-crate
//
// This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate.
pub(super) fn unresolved_extern_crate(
    ctx: &DiagnosticsContext<'_>,
    d: &hir::UnresolvedExternCrate,
) -> Diagnostic {
    Diagnostic::new(
        "unresolved-extern-crate",
        "unresolved extern crate",
        ctx.sema.diagnostics_display_range(d.decl.clone().map(|it| it.into())).range,
    )
}

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

    #[test]
    fn unresolved_extern_crate() {
        check_diagnostics(
            r#"
//- /main.rs crate:main deps:core
extern crate core;
  extern crate doesnotexist;
//^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate
//- /lib.rs crate:core
"#,
        );
    }

    #[test]
    fn extern_crate_self_as() {
        cov_mark::check!(extern_crate_self_as);
        check_diagnostics(
            r#"
//- /lib.rs
  extern crate doesnotexist;
//^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate
// Should not error.
extern crate self as foo;
struct Foo;
use foo::Foo as Bar;
"#,
        );
    }
}