7575: Fix resolution of `self` module within blocks r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-02-05 18:26:51 +00:00 committed by GitHub
commit 4e86aee60b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 7 deletions

View File

@ -26,22 +26,26 @@ fn inner() {}
fn use_from_crate() {
check_at(
r#"
struct Struct;
struct Struct {}
fn outer() {
use Struct;
fn Struct() {}
use Struct as PlainStruct;
use crate::Struct as CrateStruct;
use self::Struct as SelfStruct;
use super::Struct as SuperStruct;
$0
}
"#,
expect![[r#"
block scope
CrateStruct: t v
SelfStruct: t v
Struct: t v
CrateStruct: t
PlainStruct: t v
SelfStruct: t
Struct: v
SuperStruct: _
crate
Struct: t v
Struct: t
outer: v
"#]],
);

View File

@ -227,7 +227,15 @@ pub(super) fn resolve_path_fp_with_macro_single(
}
}
PerNs::types(self.module_id(module).into(), Visibility::Public)
// Resolve `self` to the containing crate-rooted module if we're a block
self.with_ancestor_maps(db, module, &mut |def_map, module| {
if def_map.block.is_some() {
None // keep ascending
} else {
Some(PerNs::types(def_map.module_id(module).into(), Visibility::Public))
}
})
.expect("block DefMap not rooted in crate DefMap")
}
PathKind::Abs => {
// 2018-style absolute path -- only extern prelude