aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/body/tests/block.rs16
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs10
2 files changed, 19 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..b599c6269 100644
--- a/crates/hir_def/src/body/tests/block.rs
+++ b/crates/hir_def/src/body/tests/block.rs
@@ -26,22 +26,26 @@ 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;
35 use super::Struct as SuperStruct;
34 $0 36 $0
35} 37}
36"#, 38"#,
37 expect![[r#" 39 expect![[r#"
38 block scope 40 block scope
39 CrateStruct: t v 41 CrateStruct: t
40 SelfStruct: t v 42 PlainStruct: t v
41 Struct: t v 43 SelfStruct: t
44 Struct: v
45 SuperStruct: _
42 46
43 crate 47 crate
44 Struct: t v 48 Struct: t
45 outer: v 49 outer: v
46 "#]], 50 "#]],
47 ); 51 );
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