diff options
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r-- | crates/hir_def/src/nameres/path_resolution.rs | 6 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/diagnostics.rs | 15 |
2 files changed, 21 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index ec90f4e65..a6e0f64fc 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs | |||
@@ -14,6 +14,7 @@ use std::iter::successors; | |||
14 | 14 | ||
15 | use base_db::Edition; | 15 | use base_db::Edition; |
16 | use hir_expand::name::Name; | 16 | use hir_expand::name::Name; |
17 | use hir_expand::name; | ||
17 | use test_utils::mark; | 18 | use test_utils::mark; |
18 | 19 | ||
19 | use crate::{ | 20 | use crate::{ |
@@ -63,6 +64,11 @@ 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 | return PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into(), | ||
69 | Visibility::Public, | ||
70 | ); | ||
71 | } | ||
66 | self.extern_prelude | 72 | self.extern_prelude |
67 | .get(name) | 73 | .get(name) |
68 | .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)) | 74 | .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..679a505dc 100644 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ b/crates/hir_def/src/nameres/tests/diagnostics.rs | |||
@@ -62,6 +62,21 @@ fn unresolved_extern_crate() { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | #[test] | 64 | #[test] |
65 | fn extern_crate_self_as() { | ||
66 | check_diagnostics( | ||
67 | r" | ||
68 | //- /lib.rs | ||
69 | extern crate doesnotexist; | ||
70 | //^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved extern crate | ||
71 | // Should not error. | ||
72 | extern crate self as foo; | ||
73 | struct Foo; | ||
74 | use foo::Foo as Bar; | ||
75 | ", | ||
76 | ); | ||
77 | } | ||
78 | |||
79 | #[test] | ||
65 | fn dedup_unresolved_import_from_unresolved_crate() { | 80 | fn dedup_unresolved_import_from_unresolved_crate() { |
66 | check_diagnostics( | 81 | check_diagnostics( |
67 | r" | 82 | r" |