aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/body/tests/block.rs14
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs10
2 files changed, 17 insertions, 7 deletions
diff --git a/crates/hir_def/src/body/tests/block.rs b/crates/hir_def/src/body/tests/block.rs
index 062560a70..e688c0989 100644
--- a/crates/hir_def/src/body/tests/block.rs
+++ b/crates/hir_def/src/body/tests/block.rs
@@ -26,9 +26,10 @@ fn outer() {
26fn use_from_crate() { 26fn use_from_crate() {
27 check_at( 27 check_at(
28 r#" 28 r#"
29struct Struct; 29struct Struct {}
30fn outer() { 30fn outer() {
31 use Struct; 31 fn Struct() {}
32 use Struct as PlainStruct;
32 use crate::Struct as CrateStruct; 33 use crate::Struct as CrateStruct;
33 use self::Struct as SelfStruct; 34 use self::Struct as SelfStruct;
34 $0 35 $0
@@ -36,12 +37,13 @@ fn outer() {
36"#, 37"#,
37 expect![[r#" 38 expect![[r#"
38 block scope 39 block scope
39 CrateStruct: t v 40 CrateStruct: t
40 SelfStruct: t v 41 PlainStruct: t v
41 Struct: t v 42 SelfStruct: t
43 Struct: v
42 44
43 crate 45 crate
44 Struct: t v 46 Struct: t
45 outer: v 47 outer: v
46 "#]], 48 "#]],
47 ); 49 );
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs
index 036e389b0..fdcdc23ae 100644
--- a/crates/hir_def/src/nameres/path_resolution.rs
+++ b/crates/hir_def/src/nameres/path_resolution.rs
@@ -227,7 +227,15 @@ impl DefMap {
227 } 227 }
228 } 228 }
229 229
230 PerNs::types(self.module_id(module).into(), Visibility::Public) 230 // Resolve `self` to the containing crate-rooted module if we're a block
231 self.with_ancestor_maps(db, module, &mut |def_map, module| {
232 if def_map.block.is_some() {
233 None // keep ascending
234 } else {
235 Some(PerNs::types(def_map.module_id(module).into(), Visibility::Public))
236 }
237 })
238 .expect("block DefMap not rooted in crate DefMap")
231 } 239 }
232 PathKind::Abs => { 240 PathKind::Abs => {
233 // 2018-style absolute path -- only extern prelude 241 // 2018-style absolute path -- only extern prelude