mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
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
2 changed files with 23 additions and 8 deletions
|
@ -1273,12 +1273,8 @@ impl ModCollector<'_, '_> {
|
||||||
// out of line module, resolve, parse and recurse
|
// out of line module, resolve, parse and recurse
|
||||||
ModKind::Outline {} => {
|
ModKind::Outline {} => {
|
||||||
let ast_id = AstId::new(self.file_id, module.ast_id);
|
let ast_id = AstId::new(self.file_id, module.ast_id);
|
||||||
match self.mod_dir.resolve_declaration(
|
let db = self.def_collector.db;
|
||||||
self.def_collector.db,
|
match self.mod_dir.resolve_declaration(db, self.file_id, &module.name, path_attr) {
|
||||||
self.file_id,
|
|
||||||
&module.name,
|
|
||||||
path_attr,
|
|
||||||
) {
|
|
||||||
Ok((file_id, is_mod_rs, mod_dir)) => {
|
Ok((file_id, is_mod_rs, mod_dir)) => {
|
||||||
let module_id = self.push_child_module(
|
let module_id = self.push_child_module(
|
||||||
module.name.clone(),
|
module.name.clone(),
|
||||||
|
@ -1286,7 +1282,7 @@ impl ModCollector<'_, '_> {
|
||||||
Some((file_id, is_mod_rs)),
|
Some((file_id, is_mod_rs)),
|
||||||
&self.item_tree[module.visibility],
|
&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 {
|
ModCollector {
|
||||||
def_collector: &mut *self.def_collector,
|
def_collector: &mut *self.def_collector,
|
||||||
macro_depth: self.macro_depth,
|
macro_depth: self.macro_depth,
|
||||||
|
@ -1296,7 +1292,12 @@ impl ModCollector<'_, '_> {
|
||||||
mod_dir,
|
mod_dir,
|
||||||
}
|
}
|
||||||
.collect(item_tree.top_level_items());
|
.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);
|
self.import_all_legacy_macros(module_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,11 +391,21 @@ foo!(ok_shadow);
|
||||||
mod m4;
|
mod m4;
|
||||||
bar!(OkMacroUse);
|
bar!(OkMacroUse);
|
||||||
|
|
||||||
|
mod m5;
|
||||||
|
baz!(OkMacroUseInner);
|
||||||
|
|
||||||
//- /m3/m4.rs
|
//- /m3/m4.rs
|
||||||
foo!(ok_shadow_deep);
|
foo!(ok_shadow_deep);
|
||||||
macro_rules! bar {
|
macro_rules! bar {
|
||||||
($x:ident) => { struct $x; }
|
($x:ident) => { struct $x; }
|
||||||
}
|
}
|
||||||
|
//- /m3/m5.rs
|
||||||
|
#![macro_use]
|
||||||
|
macro_rules! baz {
|
||||||
|
($x:ident) => { struct $x; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
crate
|
crate
|
||||||
|
@ -423,11 +433,15 @@ macro_rules! bar {
|
||||||
crate::m3
|
crate::m3
|
||||||
OkAfterInside: t v
|
OkAfterInside: t v
|
||||||
OkMacroUse: t v
|
OkMacroUse: t v
|
||||||
|
OkMacroUseInner: t v
|
||||||
m4: t
|
m4: t
|
||||||
|
m5: t
|
||||||
ok_shadow: v
|
ok_shadow: v
|
||||||
|
|
||||||
crate::m3::m4
|
crate::m3::m4
|
||||||
ok_shadow_deep: v
|
ok_shadow_deep: v
|
||||||
|
|
||||||
|
crate::m3::m5
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue