Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions crates/hir_def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,29 +1294,37 @@ impl ModCollector<'_, '_> {
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(),
ast_id,
Some((file_id, is_mod_rs)),
&self.item_tree[module.visibility],
);
let item_tree = db.file_item_tree(file_id.into());
ModCollector {
def_collector: &mut *self.def_collector,
macro_depth: self.macro_depth,
module_id,
file_id: file_id.into(),
item_tree: &item_tree,
mod_dir,
}
.collect(item_tree.top_level_items());
if is_macro_use
|| item_tree
.top_level_attrs(db, self.def_collector.def_map.krate)
.by_key("macro_use")
.exists()
if item_tree
.top_level_attrs(db, self.def_collector.def_map.krate)
.cfg()
.map_or(true, |cfg| {
self.def_collector.cfg_options.check(&cfg) != Some(false)
})
{
self.import_all_legacy_macros(module_id);
let module_id = self.push_child_module(
module.name.clone(),
ast_id,
Some((file_id, is_mod_rs)),
&self.item_tree[module.visibility],
);
ModCollector {
def_collector: &mut *self.def_collector,
macro_depth: self.macro_depth,
module_id,
file_id: file_id.into(),
item_tree: &item_tree,
mod_dir,
}
.collect(item_tree.top_level_items());
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);
}
}
}
Err(candidate) => {
Expand Down
19 changes: 19 additions & 0 deletions crates/hir_def/src/nameres/tests/mod_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,22 @@ pub mod hash { pub trait Hash {} }
"#]],
);
}

#[test]
fn cfg_in_module_file() {
// Inner `#![cfg]` in a module file makes the whole module disappear.
check(
r#"
//- /main.rs
mod module;

//- /module.rs
#![cfg(NEVER)]

struct AlsoShoulntAppear;
"#,
expect![[r#"
crate
"#]],
)
}