Merge #7502
7502: Honor #![macro_use] in mod source files r=jonas-schievink a=Veykril Fixes #7501 Since `ItemTree` builds the `RawAttrs` directly we need the special check here as I don't think we can fix this in `RawAttrs` constructor as its solely AST based and we need to touch two different ASTs here. This just made me realize that `attrs_query` suffers from a similar problem, for example hovering an outline `mod` decl won't show inner docs, only outer ones, #7503. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
e6e93b3d1d
@ -1273,12 +1273,8 @@ impl ModCollector<'_, '_> {
|
||||
// out of line module, resolve, parse and recurse
|
||||
ModKind::Outline {} => {
|
||||
let ast_id = AstId::new(self.file_id, module.ast_id);
|
||||
match self.mod_dir.resolve_declaration(
|
||||
self.def_collector.db,
|
||||
self.file_id,
|
||||
&module.name,
|
||||
path_attr,
|
||||
) {
|
||||
let db = self.def_collector.db;
|
||||
match self.mod_dir.resolve_declaration(db, self.file_id, &module.name, path_attr) {
|
||||
Ok((file_id, is_mod_rs, mod_dir)) => {
|
||||
let module_id = self.push_child_module(
|
||||
module.name.clone(),
|
||||
@ -1286,7 +1282,7 @@ impl ModCollector<'_, '_> {
|
||||
Some((file_id, is_mod_rs)),
|
||||
&self.item_tree[module.visibility],
|
||||
);
|
||||
let item_tree = self.def_collector.db.item_tree(file_id.into());
|
||||
let item_tree = db.item_tree(file_id.into());
|
||||
ModCollector {
|
||||
def_collector: &mut *self.def_collector,
|
||||
macro_depth: self.macro_depth,
|
||||
@ -1296,7 +1292,12 @@ impl ModCollector<'_, '_> {
|
||||
mod_dir,
|
||||
}
|
||||
.collect(item_tree.top_level_items());
|
||||
if is_macro_use {
|
||||
if is_macro_use
|
||||
|| item_tree
|
||||
.top_level_attrs(db, self.def_collector.def_map.krate)
|
||||
.by_key("macro_use")
|
||||
.exists()
|
||||
{
|
||||
self.import_all_legacy_macros(module_id);
|
||||
}
|
||||
}
|
||||
|
@ -391,11 +391,21 @@ foo!(ok_shadow);
|
||||
mod m4;
|
||||
bar!(OkMacroUse);
|
||||
|
||||
mod m5;
|
||||
baz!(OkMacroUseInner);
|
||||
|
||||
//- /m3/m4.rs
|
||||
foo!(ok_shadow_deep);
|
||||
macro_rules! bar {
|
||||
($x:ident) => { struct $x; }
|
||||
}
|
||||
//- /m3/m5.rs
|
||||
#![macro_use]
|
||||
macro_rules! baz {
|
||||
($x:ident) => { struct $x; }
|
||||
}
|
||||
|
||||
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
@ -423,11 +433,15 @@ macro_rules! bar {
|
||||
crate::m3
|
||||
OkAfterInside: t v
|
||||
OkMacroUse: t v
|
||||
OkMacroUseInner: t v
|
||||
m4: t
|
||||
m5: t
|
||||
ok_shadow: v
|
||||
|
||||
crate::m3::m4
|
||||
ok_shadow_deep: v
|
||||
|
||||
crate::m3::m5
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user