aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir/src/code_model.rs4
-rw-r--r--crates/hir_def/src/nameres/collector.rs317
-rw-r--r--crates/hir_expand/src/db.rs4
-rw-r--r--crates/hir_expand/src/eager.rs2
-rw-r--r--crates/hir_expand/src/hygiene.rs2
-rw-r--r--crates/hir_expand/src/lib.rs2
6 files changed, 165 insertions, 166 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 7a9747fc7..849c8f6d0 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -908,12 +908,12 @@ impl MacroDef {
908 908
909 /// Indicate it is a proc-macro 909 /// Indicate it is a proc-macro
910 pub fn is_proc_macro(&self) -> bool { 910 pub fn is_proc_macro(&self) -> bool {
911 matches!(self.id.kind, MacroDefKind::CustomDerive(_)) 911 matches!(self.id.kind, MacroDefKind::ProcMacro(_))
912 } 912 }
913 913
914 /// Indicate it is a derive macro 914 /// Indicate it is a derive macro
915 pub fn is_derive_macro(&self) -> bool { 915 pub fn is_derive_macro(&self) -> bool {
916 matches!(self.id.kind, MacroDefKind::CustomDerive(_) | MacroDefKind::BuiltInDerive(_)) 916 matches!(self.id.kind, MacroDefKind::ProcMacro(_) | MacroDefKind::BuiltInDerive(_))
917 } 917 }
918} 918}
919 919
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index c1e1d53f6..4c3993ff0 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -273,7 +273,7 @@ impl DefCollector<'_> {
273 let macro_id = MacroDefId { 273 let macro_id = MacroDefId {
274 ast_id: None, 274 ast_id: None,
275 krate: Some(krate), 275 krate: Some(krate),
276 kind: MacroDefKind::CustomDerive(expander), 276 kind: MacroDefKind::ProcMacro(expander),
277 local_inner: false, 277 local_inner: false,
278 }; 278 };
279 279
@@ -874,184 +874,183 @@ impl ModCollector<'_, '_> {
874 874
875 for &item in items { 875 for &item in items {
876 let attrs = self.item_tree.attrs(item.into()); 876 let attrs = self.item_tree.attrs(item.into());
877 if self.is_cfg_enabled(attrs) { 877 if !self.is_cfg_enabled(attrs) {
878 let module = 878 continue;
879 ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; 879 }
880 let container = ContainerId::ModuleId(module); 880 let module =
881 881 ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
882 let mut def = None; 882 let container = ContainerId::ModuleId(module);
883 match item { 883
884 ModItem::Mod(m) => self.collect_module(&self.item_tree[m], attrs), 884 let mut def = None;
885 ModItem::Import(import_id) => { 885 match item {
886 self.def_collector.unresolved_imports.push(ImportDirective { 886 ModItem::Mod(m) => self.collect_module(&self.item_tree[m], attrs),
887 module_id: self.module_id, 887 ModItem::Import(import_id) => {
888 import: Import::from_use( 888 self.def_collector.unresolved_imports.push(ImportDirective {
889 &self.item_tree, 889 module_id: self.module_id,
890 InFile::new(self.file_id, import_id), 890 import: Import::from_use(
891 ), 891 &self.item_tree,
892 status: PartialResolvedImport::Unresolved, 892 InFile::new(self.file_id, import_id),
893 }) 893 ),
894 } 894 status: PartialResolvedImport::Unresolved,
895 ModItem::ExternCrate(import_id) => { 895 })
896 self.def_collector.unresolved_imports.push(ImportDirective { 896 }
897 module_id: self.module_id, 897 ModItem::ExternCrate(import_id) => {
898 import: Import::from_extern_crate( 898 self.def_collector.unresolved_imports.push(ImportDirective {
899 &self.item_tree, 899 module_id: self.module_id,
900 InFile::new(self.file_id, import_id), 900 import: Import::from_extern_crate(
901 ), 901 &self.item_tree,
902 status: PartialResolvedImport::Unresolved, 902 InFile::new(self.file_id, import_id),
903 }) 903 ),
904 } 904 status: PartialResolvedImport::Unresolved,
905 ModItem::MacroCall(mac) => self.collect_macro(&self.item_tree[mac]), 905 })
906 ModItem::Impl(imp) => { 906 }
907 let module = ModuleId { 907 ModItem::MacroCall(mac) => self.collect_macro(&self.item_tree[mac]),
908 krate: self.def_collector.def_map.krate, 908 ModItem::Impl(imp) => {
909 local_id: self.module_id, 909 let module = ModuleId {
910 }; 910 krate: self.def_collector.def_map.krate,
911 let container = ContainerId::ModuleId(module); 911 local_id: self.module_id,
912 let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) } 912 };
913 .intern(self.def_collector.db); 913 let container = ContainerId::ModuleId(module);
914 self.def_collector.def_map.modules[self.module_id] 914 let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) }
915 .scope 915 .intern(self.def_collector.db);
916 .define_impl(impl_id) 916 self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id)
917 } 917 }
918 ModItem::Function(id) => { 918 ModItem::Function(id) => {
919 let func = &self.item_tree[id]; 919 let func = &self.item_tree[id];
920 def = Some(DefData { 920 def = Some(DefData {
921 id: FunctionLoc { 921 id: FunctionLoc {
922 container: container.into(), 922 container: container.into(),
923 id: ItemTreeId::new(self.file_id, id), 923 id: ItemTreeId::new(self.file_id, id),
924 } 924 }
925 .intern(self.def_collector.db) 925 .intern(self.def_collector.db)
926 .into(), 926 .into(),
927 name: &func.name, 927 name: &func.name,
928 visibility: &self.item_tree[func.visibility], 928 visibility: &self.item_tree[func.visibility],
929 has_constructor: false, 929 has_constructor: false,
930 }); 930 });
931 } 931 }
932 ModItem::Struct(id) => { 932 ModItem::Struct(id) => {
933 let it = &self.item_tree[id]; 933 let it = &self.item_tree[id];
934
935 // FIXME: check attrs to see if this is an attribute macro invocation;
936 // in which case we don't add the invocation, just a single attribute
937 // macro invocation
938 self.collect_derives(attrs, it.ast_id.upcast());
939
940 def = Some(DefData {
941 id: StructLoc { container, id: ItemTreeId::new(self.file_id, id) }
942 .intern(self.def_collector.db)
943 .into(),
944 name: &it.name,
945 visibility: &self.item_tree[it.visibility],
946 has_constructor: it.kind != StructDefKind::Record,
947 });
948 }
949 ModItem::Union(id) => {
950 let it = &self.item_tree[id];
951 934
952 // FIXME: check attrs to see if this is an attribute macro invocation; 935 // FIXME: check attrs to see if this is an attribute macro invocation;
953 // in which case we don't add the invocation, just a single attribute 936 // in which case we don't add the invocation, just a single attribute
954 // macro invocation 937 // macro invocation
955 self.collect_derives(attrs, it.ast_id.upcast()); 938 self.collect_derives(attrs, it.ast_id.upcast());
956 939
957 def = Some(DefData { 940 def = Some(DefData {
958 id: UnionLoc { container, id: ItemTreeId::new(self.file_id, id) } 941 id: StructLoc { container, id: ItemTreeId::new(self.file_id, id) }
959 .intern(self.def_collector.db) 942 .intern(self.def_collector.db)
960 .into(), 943 .into(),
961 name: &it.name, 944 name: &it.name,
962 visibility: &self.item_tree[it.visibility], 945 visibility: &self.item_tree[it.visibility],
963 has_constructor: false, 946 has_constructor: it.kind != StructDefKind::Record,
964 }); 947 });
965 } 948 }
966 ModItem::Enum(id) => { 949 ModItem::Union(id) => {
967 let it = &self.item_tree[id]; 950 let it = &self.item_tree[id];
968 951
969 // FIXME: check attrs to see if this is an attribute macro invocation; 952 // FIXME: check attrs to see if this is an attribute macro invocation;
970 // in which case we don't add the invocation, just a single attribute 953 // in which case we don't add the invocation, just a single attribute
971 // macro invocation 954 // macro invocation
972 self.collect_derives(attrs, it.ast_id.upcast()); 955 self.collect_derives(attrs, it.ast_id.upcast());
973 956
974 def = Some(DefData { 957 def = Some(DefData {
975 id: EnumLoc { container, id: ItemTreeId::new(self.file_id, id) } 958 id: UnionLoc { container, id: ItemTreeId::new(self.file_id, id) }
976 .intern(self.def_collector.db) 959 .intern(self.def_collector.db)
977 .into(), 960 .into(),
978 name: &it.name, 961 name: &it.name,
979 visibility: &self.item_tree[it.visibility], 962 visibility: &self.item_tree[it.visibility],
980 has_constructor: false, 963 has_constructor: false,
981 }); 964 });
982 } 965 }
983 ModItem::Const(id) => { 966 ModItem::Enum(id) => {
984 let it = &self.item_tree[id]; 967 let it = &self.item_tree[id];
985
986 if let Some(name) = &it.name {
987 def = Some(DefData {
988 id: ConstLoc {
989 container: container.into(),
990 id: ItemTreeId::new(self.file_id, id),
991 }
992 .intern(self.def_collector.db)
993 .into(),
994 name,
995 visibility: &self.item_tree[it.visibility],
996 has_constructor: false,
997 });
998 }
999 }
1000 ModItem::Static(id) => {
1001 let it = &self.item_tree[id];
1002 968
1003 def = Some(DefData { 969 // FIXME: check attrs to see if this is an attribute macro invocation;
1004 id: StaticLoc { container, id: ItemTreeId::new(self.file_id, id) } 970 // in which case we don't add the invocation, just a single attribute
1005 .intern(self.def_collector.db) 971 // macro invocation
1006 .into(), 972 self.collect_derives(attrs, it.ast_id.upcast());
1007 name: &it.name,
1008 visibility: &self.item_tree[it.visibility],
1009 has_constructor: false,
1010 });
1011 }
1012 ModItem::Trait(id) => {
1013 let it = &self.item_tree[id];
1014 973
1015 def = Some(DefData { 974 def = Some(DefData {
1016 id: TraitLoc { container, id: ItemTreeId::new(self.file_id, id) } 975 id: EnumLoc { container, id: ItemTreeId::new(self.file_id, id) }
1017 .intern(self.def_collector.db) 976 .intern(self.def_collector.db)
1018 .into(), 977 .into(),
1019 name: &it.name, 978 name: &it.name,
1020 visibility: &self.item_tree[it.visibility], 979 visibility: &self.item_tree[it.visibility],
1021 has_constructor: false, 980 has_constructor: false,
1022 }); 981 });
1023 } 982 }
1024 ModItem::TypeAlias(id) => { 983 ModItem::Const(id) => {
1025 let it = &self.item_tree[id]; 984 let it = &self.item_tree[id];
1026 985
986 if let Some(name) = &it.name {
1027 def = Some(DefData { 987 def = Some(DefData {
1028 id: TypeAliasLoc { 988 id: ConstLoc {
1029 container: container.into(), 989 container: container.into(),
1030 id: ItemTreeId::new(self.file_id, id), 990 id: ItemTreeId::new(self.file_id, id),
1031 } 991 }
1032 .intern(self.def_collector.db) 992 .intern(self.def_collector.db)
1033 .into(), 993 .into(),
1034 name: &it.name, 994 name,
1035 visibility: &self.item_tree[it.visibility], 995 visibility: &self.item_tree[it.visibility],
1036 has_constructor: false, 996 has_constructor: false,
1037 }); 997 });
1038 } 998 }
1039 } 999 }
1000 ModItem::Static(id) => {
1001 let it = &self.item_tree[id];
1040 1002
1041 if let Some(DefData { id, name, visibility, has_constructor }) = def { 1003 def = Some(DefData {
1042 self.def_collector.def_map.modules[self.module_id].scope.define_def(id); 1004 id: StaticLoc { container, id: ItemTreeId::new(self.file_id, id) }
1043 let vis = self 1005 .intern(self.def_collector.db)
1044 .def_collector 1006 .into(),
1045 .def_map 1007 name: &it.name,
1046 .resolve_visibility(self.def_collector.db, self.module_id, visibility) 1008 visibility: &self.item_tree[it.visibility],
1047 .unwrap_or(Visibility::Public); 1009 has_constructor: false,
1048 self.def_collector.update( 1010 });
1049 self.module_id, 1011 }
1050 &[(Some(name.clone()), PerNs::from_def(id, vis, has_constructor))], 1012 ModItem::Trait(id) => {
1051 vis, 1013 let it = &self.item_tree[id];
1052 ImportType::Named, 1014
1053 ) 1015 def = Some(DefData {
1016 id: TraitLoc { container, id: ItemTreeId::new(self.file_id, id) }
1017 .intern(self.def_collector.db)
1018 .into(),
1019 name: &it.name,
1020 visibility: &self.item_tree[it.visibility],
1021 has_constructor: false,
1022 });
1054 } 1023 }
1024 ModItem::TypeAlias(id) => {
1025 let it = &self.item_tree[id];
1026
1027 def = Some(DefData {
1028 id: TypeAliasLoc {
1029 container: container.into(),
1030 id: ItemTreeId::new(self.file_id, id),
1031 }
1032 .intern(self.def_collector.db)
1033 .into(),
1034 name: &it.name,
1035 visibility: &self.item_tree[it.visibility],
1036 has_constructor: false,
1037 });
1038 }
1039 }
1040
1041 if let Some(DefData { id, name, visibility, has_constructor }) = def {
1042 self.def_collector.def_map.modules[self.module_id].scope.define_def(id);
1043 let vis = self
1044 .def_collector
1045 .def_map
1046 .resolve_visibility(self.def_collector.db, self.module_id, visibility)
1047 .unwrap_or(Visibility::Public);
1048 self.def_collector.update(
1049 self.module_id,
1050 &[(Some(name.clone()), PerNs::from_def(id, vis, has_constructor))],
1051 vis,
1052 ImportType::Named,
1053 )
1055 } 1054 }
1056 } 1055 }
1057 } 1056 }
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs
index 710694a34..b591130ca 100644
--- a/crates/hir_expand/src/db.rs
+++ b/crates/hir_expand/src/db.rs
@@ -143,7 +143,7 @@ pub(crate) fn macro_def(
143 Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default()))) 143 Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default())))
144 } 144 }
145 MacroDefKind::BuiltInEager(_) => None, 145 MacroDefKind::BuiltInEager(_) => None,
146 MacroDefKind::CustomDerive(expander) => { 146 MacroDefKind::ProcMacro(expander) => {
147 Some(Arc::new((TokenExpander::ProcMacro(expander), mbe::TokenMap::default()))) 147 Some(Arc::new((TokenExpander::ProcMacro(expander), mbe::TokenMap::default())))
148 } 148 }
149 } 149 }
@@ -249,7 +249,7 @@ pub(crate) fn expand_proc_macro(
249 }; 249 };
250 250
251 let expander = match loc.def.kind { 251 let expander = match loc.def.kind {
252 MacroDefKind::CustomDerive(expander) => expander, 252 MacroDefKind::ProcMacro(expander) => expander,
253 _ => unreachable!(), 253 _ => unreachable!(),
254 }; 254 };
255 255
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs
index 10c45646f..2f37d7189 100644
--- a/crates/hir_expand/src/eager.rs
+++ b/crates/hir_expand/src/eager.rs
@@ -129,7 +129,7 @@ fn eager_macro_recur(
129 MacroDefKind::Declarative 129 MacroDefKind::Declarative
130 | MacroDefKind::BuiltIn(_) 130 | MacroDefKind::BuiltIn(_)
131 | MacroDefKind::BuiltInDerive(_) 131 | MacroDefKind::BuiltInDerive(_)
132 | MacroDefKind::CustomDerive(_) => { 132 | MacroDefKind::ProcMacro(_) => {
133 let expanded = lazy_expand(db, &def, curr.with_value(child.clone()), krate)?; 133 let expanded = lazy_expand(db, &def, curr.with_value(child.clone()), krate)?;
134 // replace macro inside 134 // replace macro inside
135 eager_macro_recur(db, expanded, krate, macro_resolver)? 135 eager_macro_recur(db, expanded, krate, macro_resolver)?
diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs
index 845e9cbc1..d383b968d 100644
--- a/crates/hir_expand/src/hygiene.rs
+++ b/crates/hir_expand/src/hygiene.rs
@@ -33,7 +33,7 @@ impl Hygiene {
33 MacroDefKind::BuiltIn(_) => (None, false), 33 MacroDefKind::BuiltIn(_) => (None, false),
34 MacroDefKind::BuiltInDerive(_) => (None, false), 34 MacroDefKind::BuiltInDerive(_) => (None, false),
35 MacroDefKind::BuiltInEager(_) => (None, false), 35 MacroDefKind::BuiltInEager(_) => (None, false),
36 MacroDefKind::CustomDerive(_) => (None, false), 36 MacroDefKind::ProcMacro(_) => (None, false),
37 } 37 }
38 } 38 }
39 MacroCallId::EagerMacro(_id) => (None, false), 39 MacroCallId::EagerMacro(_id) => (None, false),
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 2be15e841..17f1178ed 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -246,7 +246,7 @@ pub enum MacroDefKind {
246 // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander 246 // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
247 BuiltInDerive(BuiltinDeriveExpander), 247 BuiltInDerive(BuiltinDeriveExpander),
248 BuiltInEager(EagerExpander), 248 BuiltInEager(EagerExpander),
249 CustomDerive(ProcMacroExpander), 249 ProcMacro(ProcMacroExpander),
250} 250}
251 251
252#[derive(Debug, Clone, PartialEq, Eq, Hash)] 252#[derive(Debug, Clone, PartialEq, Eq, Hash)]