diff options
author | Jonas Schievink <[email protected]> | 2020-09-18 11:32:07 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-09-18 11:32:07 +0100 |
commit | 700a3d5d75cdc1b8b7049d35af335c638e079c5c (patch) | |
tree | 3ed524763bcabeaa26f39ba16289f148e59fe891 /crates/hir_def/src | |
parent | 086f1c4b3025b405fde077df3319551140136131 (diff) |
Invert condition to unindent code
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 315 |
1 files changed, 157 insertions, 158 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index c1e1d53f6..925043aa9 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -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 | } |