diff options
author | Jonas Schievink <[email protected]> | 2021-03-19 17:24:04 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-03-19 17:24:04 +0000 |
commit | cf494a515ff70675a4531585aa24a792f5b5e896 (patch) | |
tree | 2d69a62693790a12c98bfd414ecfcd6bbac1b1eb /crates/hir_def | |
parent | dc8e2fea98aecbba0c587e5999b9e09533e0091c (diff) |
Fix handling of `#![cfg]` in outline module file
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 50 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/mod_resolution.rs | 19 |
2 files changed, 48 insertions, 21 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 4bcdc0fc8..46a3c60cd 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1294,29 +1294,37 @@ impl ModCollector<'_, '_> { | |||
1294 | let db = self.def_collector.db; | 1294 | let db = self.def_collector.db; |
1295 | match self.mod_dir.resolve_declaration(db, self.file_id, &module.name, path_attr) { | 1295 | match self.mod_dir.resolve_declaration(db, self.file_id, &module.name, path_attr) { |
1296 | Ok((file_id, is_mod_rs, mod_dir)) => { | 1296 | Ok((file_id, is_mod_rs, mod_dir)) => { |
1297 | let module_id = self.push_child_module( | ||
1298 | module.name.clone(), | ||
1299 | ast_id, | ||
1300 | Some((file_id, is_mod_rs)), | ||
1301 | &self.item_tree[module.visibility], | ||
1302 | ); | ||
1303 | let item_tree = db.file_item_tree(file_id.into()); | 1297 | let item_tree = db.file_item_tree(file_id.into()); |
1304 | ModCollector { | 1298 | if item_tree |
1305 | def_collector: &mut *self.def_collector, | 1299 | .top_level_attrs(db, self.def_collector.def_map.krate) |
1306 | macro_depth: self.macro_depth, | 1300 | .cfg() |
1307 | module_id, | 1301 | .map_or(true, |cfg| { |
1308 | file_id: file_id.into(), | 1302 | self.def_collector.cfg_options.check(&cfg) != Some(false) |
1309 | item_tree: &item_tree, | 1303 | }) |
1310 | mod_dir, | ||
1311 | } | ||
1312 | .collect(item_tree.top_level_items()); | ||
1313 | if is_macro_use | ||
1314 | || item_tree | ||
1315 | .top_level_attrs(db, self.def_collector.def_map.krate) | ||
1316 | .by_key("macro_use") | ||
1317 | .exists() | ||
1318 | { | 1304 | { |
1319 | self.import_all_legacy_macros(module_id); | 1305 | let module_id = self.push_child_module( |
1306 | module.name.clone(), | ||
1307 | ast_id, | ||
1308 | Some((file_id, is_mod_rs)), | ||
1309 | &self.item_tree[module.visibility], | ||
1310 | ); | ||
1311 | ModCollector { | ||
1312 | def_collector: &mut *self.def_collector, | ||
1313 | macro_depth: self.macro_depth, | ||
1314 | module_id, | ||
1315 | file_id: file_id.into(), | ||
1316 | item_tree: &item_tree, | ||
1317 | mod_dir, | ||
1318 | } | ||
1319 | .collect(item_tree.top_level_items()); | ||
1320 | if is_macro_use | ||
1321 | || item_tree | ||
1322 | .top_level_attrs(db, self.def_collector.def_map.krate) | ||
1323 | .by_key("macro_use") | ||
1324 | .exists() | ||
1325 | { | ||
1326 | self.import_all_legacy_macros(module_id); | ||
1327 | } | ||
1320 | } | 1328 | } |
1321 | } | 1329 | } |
1322 | Err(candidate) => { | 1330 | Err(candidate) => { |
diff --git a/crates/hir_def/src/nameres/tests/mod_resolution.rs b/crates/hir_def/src/nameres/tests/mod_resolution.rs index dfbbad1f9..16a2cd27a 100644 --- a/crates/hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/hir_def/src/nameres/tests/mod_resolution.rs | |||
@@ -819,3 +819,22 @@ pub mod hash { pub trait Hash {} } | |||
819 | "#]], | 819 | "#]], |
820 | ); | 820 | ); |
821 | } | 821 | } |
822 | |||
823 | #[test] | ||
824 | fn cfg_in_module_file() { | ||
825 | // Inner `#![cfg]` in a module file makes the whole module disappear. | ||
826 | check( | ||
827 | r#" | ||
828 | //- /main.rs | ||
829 | mod module; | ||
830 | |||
831 | //- /module.rs | ||
832 | #![cfg(NEVER)] | ||
833 | |||
834 | struct AlsoShoulntAppear; | ||
835 | "#, | ||
836 | expect![[r#" | ||
837 | crate | ||
838 | "#]], | ||
839 | ) | ||
840 | } | ||