Auto merge of #14828 - lowr:fix/macro_use_prelude_is_in_scope, r=Veykril

fix: process `macro_use` prelude in semantic scope resolver

Fixes #14826
This commit is contained in:
bors 2023-05-18 05:36:24 +00:00
commit 07baa176c2
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 @@ impl DefMap {
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 @@ impl Resolver {
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![""],
)
}