ide_diagnostics/handlers/
unresolved_extern_crate.rs1use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
2
3pub(crate) fn unresolved_extern_crate(
7 ctx: &DiagnosticsContext<'_>,
8 d: &hir::UnresolvedExternCrate,
9) -> Diagnostic {
10 Diagnostic::new_with_syntax_node_ptr(
11 ctx,
12 DiagnosticCode::RustcHardError("unresolved-extern-crate"),
13 "unresolved extern crate",
14 d.decl.map(|it| it.into()),
15 )
16 .stable()
17}
18
19#[cfg(test)]
20mod tests {
21 use crate::tests::check_diagnostics;
22
23 #[test]
24 fn unresolved_extern_crate() {
25 check_diagnostics(
26 r#"
27//- /main.rs crate:main deps:core
28extern crate core;
29 extern crate doesnotexist;
30//^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved extern crate
31//- /lib.rs crate:core
32"#,
33 );
34 }
35
36 #[test]
37 fn extern_crate_self_as() {
38 cov_mark::check!(extern_crate_self_as);
39 check_diagnostics(
40 r#"
41//- /lib.rs
42 extern crate doesnotexist;
43//^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved extern crate
44// Should not error.
45extern crate self as foo;
46struct Foo;
47use foo::Foo as Bar;
48"#,
49 );
50 }
51}