Process macro_use prelude in semantic scope resolver

This commit is contained in:
Ryo Yoshida 2023-05-17 17:45:44 +09:00
parent 2f8cd66fb4
commit 68a74decb6
No known key found for this signature in database
GPG Key ID: E25698A930586171
4 changed files with 32 additions and 4 deletions

View File

@ -183,7 +183,7 @@ fn find_path_for_module(
// - if the item is the crate root of a dependency crate, return the name from the extern prelude
let root_def_map = crate_root.def_map(db);
for (name, &def_id) in root_def_map.extern_prelude() {
for (name, def_id) in root_def_map.extern_prelude() {
if module_id == def_id {
let name = scope_name.unwrap_or_else(|| name.clone());

View File

@ -355,8 +355,12 @@ pub(crate) fn prelude(&self) -> Option<ModuleId> {
self.prelude
}
pub(crate) fn extern_prelude(&self) -> impl Iterator<Item = (&Name, &ModuleId)> + '_ {
self.extern_prelude.iter()
pub(crate) fn extern_prelude(&self) -> impl Iterator<Item = (&Name, ModuleId)> + '_ {
self.extern_prelude.iter().map(|(name, def)| (name, *def))
}
pub(crate) fn macro_use_prelude(&self) -> impl Iterator<Item = (&Name, MacroId)> + '_ {
self.macro_use_prelude.iter().map(|(name, def)| (name, *def))
}
pub fn module_id(&self, local_id: LocalModuleId) -> ModuleId {

View File

@ -461,7 +461,10 @@ pub fn names_in_scope(
res.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)));
})
});
def_map.extern_prelude().for_each(|(name, &def)| {
def_map.macro_use_prelude().for_each(|(name, def)| {
res.add(name, ScopeDef::ModuleDef(def.into()));
});
def_map.extern_prelude().for_each(|(name, def)| {
res.add(name, ScopeDef::ModuleDef(ModuleDefId::ModuleId(def)));
});
BUILTIN_SCOPE.iter().for_each(|(name, &def)| {

View File

@ -1265,3 +1265,24 @@ macro_rules! define_struct {
"#]],
);
}
#[test]
fn macro_use_prelude_is_in_scope() {
check(
r#"
//- /main.rs crate:main deps:dep
#[macro_use]
extern crate dep;
fn main() {
print$0
}
//- /lib.rs crate:dep
#[macro_export]
macro_rules! println {
() => {}
}
"#,
expect![""],
)
}