diff options
Diffstat (limited to 'crates/ide/src/diagnostics')
-rw-r--r-- | crates/ide/src/diagnostics/unresolved_extern_crate.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/ide/src/diagnostics/unresolved_extern_crate.rs b/crates/ide/src/diagnostics/unresolved_extern_crate.rs new file mode 100644 index 000000000..2ea79c2ee --- /dev/null +++ b/crates/ide/src/diagnostics/unresolved_extern_crate.rs | |||
@@ -0,0 +1,49 @@ | |||
1 | use crate::diagnostics::{Diagnostic, DiagnosticsContext}; | ||
2 | |||
3 | // Diagnostic: unresolved-extern-crate | ||
4 | // | ||
5 | // This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate. | ||
6 | pub(super) fn unresolved_extern_crate( | ||
7 | ctx: &DiagnosticsContext<'_>, | ||
8 | d: &hir::UnresolvedExternCrate, | ||
9 | ) -> Diagnostic { | ||
10 | Diagnostic::new( | ||
11 | "unresolved-extern-crate", | ||
12 | "unresolved extern crate", | ||
13 | ctx.sema.diagnostics_display_range(d.decl.clone().map(|it| it.into())).range, | ||
14 | ) | ||
15 | } | ||
16 | |||
17 | #[cfg(test)] | ||
18 | mod tests { | ||
19 | use crate::diagnostics::tests::check_diagnostics; | ||
20 | |||
21 | #[test] | ||
22 | fn unresolved_extern_crate() { | ||
23 | check_diagnostics( | ||
24 | r#" | ||
25 | //- /main.rs crate:main deps:core | ||
26 | extern crate core; | ||
27 | extern crate doesnotexist; | ||
28 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate | ||
29 | //- /lib.rs crate:core | ||
30 | "#, | ||
31 | ); | ||
32 | } | ||
33 | |||
34 | #[test] | ||
35 | fn extern_crate_self_as() { | ||
36 | cov_mark::check!(extern_crate_self_as); | ||
37 | check_diagnostics( | ||
38 | r#" | ||
39 | //- /lib.rs | ||
40 | extern crate doesnotexist; | ||
41 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate | ||
42 | // Should not error. | ||
43 | extern crate self as foo; | ||
44 | struct Foo; | ||
45 | use foo::Foo as Bar; | ||
46 | "#, | ||
47 | ); | ||
48 | } | ||
49 | } | ||