aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres/collector.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/nameres/collector.rs')
-rw-r--r--crates/hir_def/src/nameres/collector.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index e51d89b43..9ed48c506 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -18,7 +18,6 @@ use hir_expand::{
18use hir_expand::{InFile, MacroCallLoc}; 18use hir_expand::{InFile, MacroCallLoc};
19use rustc_hash::{FxHashMap, FxHashSet}; 19use rustc_hash::{FxHashMap, FxHashSet};
20use syntax::ast; 20use syntax::ast;
21use test_utils::mark;
22use tt::{Leaf, TokenTree}; 21use tt::{Leaf, TokenTree};
23 22
24use crate::{ 23use crate::{
@@ -38,9 +37,9 @@ use crate::{
38 path::{ImportAlias, ModPath, PathKind}, 37 path::{ImportAlias, ModPath, PathKind},
39 per_ns::PerNs, 38 per_ns::PerNs,
40 visibility::{RawVisibility, Visibility}, 39 visibility::{RawVisibility, Visibility},
41 AdtId, AstId, AstIdWithPath, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, 40 AdtId, AstId, AstIdWithPath, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
42 ImplLoc, Intern, LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, 41 LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
43 UnionLoc, UnresolvedMacro, 42 UnresolvedMacro,
44}; 43};
45 44
46const GLOB_RECURSION_LIMIT: usize = 100; 45const GLOB_RECURSION_LIMIT: usize = 100;
@@ -462,7 +461,7 @@ impl DefCollector<'_> {
462 let res = self.def_map.resolve_name_in_extern_prelude(&extern_crate.name); 461 let res = self.def_map.resolve_name_in_extern_prelude(&extern_crate.name);
463 462
464 if let Some(ModuleDefId::ModuleId(m)) = res.take_types() { 463 if let Some(ModuleDefId::ModuleId(m)) = res.take_types() {
465 mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use); 464 cov_mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use);
466 self.import_all_macros_exported(current_module_id, m.krate); 465 self.import_all_macros_exported(current_module_id, m.krate);
467 } 466 }
468 } 467 }
@@ -571,10 +570,10 @@ impl DefCollector<'_> {
571 match def.take_types() { 570 match def.take_types() {
572 Some(ModuleDefId::ModuleId(m)) => { 571 Some(ModuleDefId::ModuleId(m)) => {
573 if import.is_prelude { 572 if import.is_prelude {
574 mark::hit!(std_prelude); 573 cov_mark::hit!(std_prelude);
575 self.def_map.prelude = Some(m); 574 self.def_map.prelude = Some(m);
576 } else if m.krate != self.def_map.krate { 575 } else if m.krate != self.def_map.krate {
577 mark::hit!(glob_across_crates); 576 cov_mark::hit!(glob_across_crates);
578 // glob import from other crate => we can just import everything once 577 // glob import from other crate => we can just import everything once
579 let item_map = m.def_map(self.db); 578 let item_map = m.def_map(self.db);
580 let scope = &item_map[m.local_id].scope; 579 let scope = &item_map[m.local_id].scope;
@@ -626,7 +625,7 @@ impl DefCollector<'_> {
626 } 625 }
627 } 626 }
628 Some(ModuleDefId::AdtId(AdtId::EnumId(e))) => { 627 Some(ModuleDefId::AdtId(AdtId::EnumId(e))) => {
629 mark::hit!(glob_enum); 628 cov_mark::hit!(glob_enum);
630 // glob import from enum => just import all the variants 629 // glob import from enum => just import all the variants
631 630
632 // XXX: urgh, so this works by accident! Here, we look at 631 // XXX: urgh, so this works by accident! Here, we look at
@@ -675,7 +674,7 @@ impl DefCollector<'_> {
675 674
676 self.update(module_id, &[(name, def)], vis, ImportType::Named); 675 self.update(module_id, &[(name, def)], vis, ImportType::Named);
677 } 676 }
678 None => mark::hit!(bogus_paths), 677 None => cov_mark::hit!(bogus_paths),
679 } 678 }
680 } 679 }
681 } 680 }
@@ -738,7 +737,7 @@ impl DefCollector<'_> {
738 if max_vis == old_vis { 737 if max_vis == old_vis {
739 false 738 false
740 } else { 739 } else {
741 mark::hit!(upgrade_underscore_visibility); 740 cov_mark::hit!(upgrade_underscore_visibility);
742 true 741 true
743 } 742 }
744 } 743 }
@@ -866,7 +865,7 @@ impl DefCollector<'_> {
866 depth: usize, 865 depth: usize,
867 ) { 866 ) {
868 if depth > EXPANSION_DEPTH_LIMIT { 867 if depth > EXPANSION_DEPTH_LIMIT {
869 mark::hit!(macro_expansion_overflow); 868 cov_mark::hit!(macro_expansion_overflow);
870 log::warn!("macro expansion is too deep"); 869 log::warn!("macro expansion is too deep");
871 return; 870 return;
872 } 871 }
@@ -1009,7 +1008,7 @@ impl ModCollector<'_, '_> {
1009 // Prelude module is always considered to be `#[macro_use]`. 1008 // Prelude module is always considered to be `#[macro_use]`.
1010 if let Some(prelude_module) = self.def_collector.def_map.prelude { 1009 if let Some(prelude_module) = self.def_collector.def_map.prelude {
1011 if prelude_module.krate != self.def_collector.def_map.krate { 1010 if prelude_module.krate != self.def_collector.def_map.krate {
1012 mark::hit!(prelude_is_macro_use); 1011 cov_mark::hit!(prelude_is_macro_use);
1013 self.def_collector.import_all_macros_exported(self.module_id, prelude_module.krate); 1012 self.def_collector.import_all_macros_exported(self.module_id, prelude_module.krate);
1014 } 1013 }
1015 } 1014 }
@@ -1043,7 +1042,6 @@ impl ModCollector<'_, '_> {
1043 } 1042 }
1044 } 1043 }
1045 let module = self.def_collector.def_map.module_id(self.module_id); 1044 let module = self.def_collector.def_map.module_id(self.module_id);
1046 let container = ContainerId::ModuleId(module);
1047 1045
1048 let mut def = None; 1046 let mut def = None;
1049 match item { 1047 match item {
@@ -1110,9 +1108,9 @@ impl ModCollector<'_, '_> {
1110 } 1108 }
1111 ModItem::Impl(imp) => { 1109 ModItem::Impl(imp) => {
1112 let module = self.def_collector.def_map.module_id(self.module_id); 1110 let module = self.def_collector.def_map.module_id(self.module_id);
1113 let container = ContainerId::ModuleId(module); 1111 let impl_id =
1114 let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) } 1112 ImplLoc { container: module, id: ItemTreeId::new(self.file_id, imp) }
1115 .intern(self.def_collector.db); 1113 .intern(self.def_collector.db);
1116 self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id) 1114 self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id)
1117 } 1115 }
1118 ModItem::Function(id) => { 1116 ModItem::Function(id) => {
@@ -1122,7 +1120,7 @@ impl ModCollector<'_, '_> {
1122 1120
1123 def = Some(DefData { 1121 def = Some(DefData {
1124 id: FunctionLoc { 1122 id: FunctionLoc {
1125 container: container.into(), 1123 container: module.into(),
1126 id: ItemTreeId::new(self.file_id, id), 1124 id: ItemTreeId::new(self.file_id, id),
1127 } 1125 }
1128 .intern(self.def_collector.db) 1126 .intern(self.def_collector.db)
@@ -1141,7 +1139,7 @@ impl ModCollector<'_, '_> {
1141 self.collect_derives(&attrs, it.ast_id.upcast()); 1139 self.collect_derives(&attrs, it.ast_id.upcast());
1142 1140
1143 def = Some(DefData { 1141 def = Some(DefData {
1144 id: StructLoc { container, id: ItemTreeId::new(self.file_id, id) } 1142 id: StructLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1145 .intern(self.def_collector.db) 1143 .intern(self.def_collector.db)
1146 .into(), 1144 .into(),
1147 name: &it.name, 1145 name: &it.name,
@@ -1158,7 +1156,7 @@ impl ModCollector<'_, '_> {
1158 self.collect_derives(&attrs, it.ast_id.upcast()); 1156 self.collect_derives(&attrs, it.ast_id.upcast());
1159 1157
1160 def = Some(DefData { 1158 def = Some(DefData {
1161 id: UnionLoc { container, id: ItemTreeId::new(self.file_id, id) } 1159 id: UnionLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1162 .intern(self.def_collector.db) 1160 .intern(self.def_collector.db)
1163 .into(), 1161 .into(),
1164 name: &it.name, 1162 name: &it.name,
@@ -1175,7 +1173,7 @@ impl ModCollector<'_, '_> {
1175 self.collect_derives(&attrs, it.ast_id.upcast()); 1173 self.collect_derives(&attrs, it.ast_id.upcast());
1176 1174
1177 def = Some(DefData { 1175 def = Some(DefData {
1178 id: EnumLoc { container, id: ItemTreeId::new(self.file_id, id) } 1176 id: EnumLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1179 .intern(self.def_collector.db) 1177 .intern(self.def_collector.db)
1180 .into(), 1178 .into(),
1181 name: &it.name, 1179 name: &it.name,
@@ -1189,7 +1187,7 @@ impl ModCollector<'_, '_> {
1189 if let Some(name) = &it.name { 1187 if let Some(name) = &it.name {
1190 def = Some(DefData { 1188 def = Some(DefData {
1191 id: ConstLoc { 1189 id: ConstLoc {
1192 container: container.into(), 1190 container: module.into(),
1193 id: ItemTreeId::new(self.file_id, id), 1191 id: ItemTreeId::new(self.file_id, id),
1194 } 1192 }
1195 .intern(self.def_collector.db) 1193 .intern(self.def_collector.db)
@@ -1204,7 +1202,7 @@ impl ModCollector<'_, '_> {
1204 let it = &self.item_tree[id]; 1202 let it = &self.item_tree[id];
1205 1203
1206 def = Some(DefData { 1204 def = Some(DefData {
1207 id: StaticLoc { container, id: ItemTreeId::new(self.file_id, id) } 1205 id: StaticLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1208 .intern(self.def_collector.db) 1206 .intern(self.def_collector.db)
1209 .into(), 1207 .into(),
1210 name: &it.name, 1208 name: &it.name,
@@ -1216,7 +1214,7 @@ impl ModCollector<'_, '_> {
1216 let it = &self.item_tree[id]; 1214 let it = &self.item_tree[id];
1217 1215
1218 def = Some(DefData { 1216 def = Some(DefData {
1219 id: TraitLoc { container, id: ItemTreeId::new(self.file_id, id) } 1217 id: TraitLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1220 .intern(self.def_collector.db) 1218 .intern(self.def_collector.db)
1221 .into(), 1219 .into(),
1222 name: &it.name, 1220 name: &it.name,
@@ -1229,7 +1227,7 @@ impl ModCollector<'_, '_> {
1229 1227
1230 def = Some(DefData { 1228 def = Some(DefData {
1231 id: TypeAliasLoc { 1229 id: TypeAliasLoc {
1232 container: container.into(), 1230 container: module.into(),
1233 id: ItemTreeId::new(self.file_id, id), 1231 id: ItemTreeId::new(self.file_id, id),
1234 } 1232 }
1235 .intern(self.def_collector.db) 1233 .intern(self.def_collector.db)