diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/nameres/path_resolution.rs | 8 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/diagnostics.rs | 16 |
2 files changed, 24 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 82528b792..7b5fe24a7 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs | |||
@@ -13,6 +13,7 @@ | |||
13 | use std::iter::successors; | 13 | use std::iter::successors; |
14 | 14 | ||
15 | use base_db::Edition; | 15 | use base_db::Edition; |
16 | use hir_expand::name; | ||
16 | use hir_expand::name::Name; | 17 | use hir_expand::name::Name; |
17 | use test_utils::mark; | 18 | use test_utils::mark; |
18 | 19 | ||
@@ -63,6 +64,13 @@ impl ResolvePathResult { | |||
63 | 64 | ||
64 | impl DefMap { | 65 | impl DefMap { |
65 | pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { | 66 | pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { |
67 | if name == &name!(self) { | ||
68 | mark::hit!(extern_crate_self_as); | ||
69 | return PerNs::types( | ||
70 | ModuleId { krate: self.krate, local_id: self.root }.into(), | ||
71 | Visibility::Public, | ||
72 | ); | ||
73 | } | ||
66 | self.extern_prelude | 74 | self.extern_prelude |
67 | .get(name) | 75 | .get(name) |
68 | .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)) | 76 | .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)) |
diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs index 58d69d3c6..e8e72e5ef 100644 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ b/crates/hir_def/src/nameres/tests/diagnostics.rs | |||
@@ -62,6 +62,22 @@ fn unresolved_extern_crate() { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | #[test] | 64 | #[test] |
65 | fn extern_crate_self_as() { | ||
66 | mark::check!(extern_crate_self_as); | ||
67 | check_diagnostics( | ||
68 | r" | ||
69 | //- /lib.rs | ||
70 | extern crate doesnotexist; | ||
71 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate | ||
72 | // Should not error. | ||
73 | extern crate self as foo; | ||
74 | struct Foo; | ||
75 | use foo::Foo as Bar; | ||
76 | ", | ||
77 | ); | ||
78 | } | ||
79 | |||
80 | #[test] | ||
65 | fn dedup_unresolved_import_from_unresolved_crate() { | 81 | fn dedup_unresolved_import_from_unresolved_crate() { |
66 | check_diagnostics( | 82 | check_diagnostics( |
67 | r" | 83 | r" |