aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-13 14:06:27 +0100
committerGitHub <[email protected]>2021-06-13 14:06:27 +0100
commite6fa9b016fab4bf38f4e2a798fcabcc13b58e9ab (patch)
tree3e01ba8fb758b685abc4ea0fa162aa48aa81efd5 /crates/ide/src
parentcc6d761a99ab3b7e28ed13ca3839358f3341da4d (diff)
parent39f190b72ccab9a166529f6ae1c8d5d562b15571 (diff)
Merge #9247
9247: internal: refactor unresolved extern crate diagnostic r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/diagnostics.rs3
-rw-r--r--crates/ide/src/diagnostics/unresolved_extern_crate.rs49
2 files changed, 52 insertions, 0 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 3307e240b..1fbb7131d 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -5,6 +5,7 @@
5//! original files. So we need to map the ranges. 5//! original files. So we need to map the ranges.
6 6
7mod unresolved_module; 7mod unresolved_module;
8mod unresolved_extern_crate;
8mod missing_fields; 9mod missing_fields;
9 10
10mod fixes; 11mod fixes;
@@ -229,8 +230,10 @@ pub(crate) fn diagnostics(
229 230
230 let ctx = DiagnosticsContext { config, sema, resolve }; 231 let ctx = DiagnosticsContext { config, sema, resolve };
231 for diag in diags { 232 for diag in diags {
233 #[rustfmt::skip]
232 let d = match diag { 234 let d = match diag {
233 AnyDiagnostic::UnresolvedModule(d) => unresolved_module::unresolved_module(&ctx, &d), 235 AnyDiagnostic::UnresolvedModule(d) => unresolved_module::unresolved_module(&ctx, &d),
236 AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d),
234 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), 237 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
235 }; 238 };
236 if let Some(code) = d.code { 239 if let Some(code) = d.code {
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 @@
1use 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.
6pub(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)]
18mod 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
26extern 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.
43extern crate self as foo;
44struct Foo;
45use foo::Foo as Bar;
46"#,
47 );
48 }
49}