Skip to content

Commit 700a3d5

Browse files
author
Jonas Schievink
committed
Invert condition to unindent code
1 parent 086f1c4 commit 700a3d5

File tree

1 file changed

+157
-158
lines changed

1 file changed

+157
-158
lines changed

crates/hir_def/src/nameres/collector.rs

Lines changed: 157 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -874,184 +874,183 @@ impl ModCollector<'_, '_> {
874874

875875
for &item in items {
876876
let attrs = self.item_tree.attrs(item.into());
877-
if self.is_cfg_enabled(attrs) {
878-
let module =
879-
ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
880-
let container = ContainerId::ModuleId(module);
881-
882-
let mut def = None;
883-
match item {
884-
ModItem::Mod(m) => self.collect_module(&self.item_tree[m], attrs),
885-
ModItem::Import(import_id) => {
886-
self.def_collector.unresolved_imports.push(ImportDirective {
887-
module_id: self.module_id,
888-
import: Import::from_use(
889-
&self.item_tree,
890-
InFile::new(self.file_id, import_id),
891-
),
892-
status: PartialResolvedImport::Unresolved,
893-
})
894-
}
895-
ModItem::ExternCrate(import_id) => {
896-
self.def_collector.unresolved_imports.push(ImportDirective {
897-
module_id: self.module_id,
898-
import: Import::from_extern_crate(
899-
&self.item_tree,
900-
InFile::new(self.file_id, import_id),
901-
),
902-
status: PartialResolvedImport::Unresolved,
903-
})
904-
}
905-
ModItem::MacroCall(mac) => self.collect_macro(&self.item_tree[mac]),
906-
ModItem::Impl(imp) => {
907-
let module = ModuleId {
908-
krate: self.def_collector.def_map.krate,
909-
local_id: self.module_id,
910-
};
911-
let container = ContainerId::ModuleId(module);
912-
let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) }
913-
.intern(self.def_collector.db);
914-
self.def_collector.def_map.modules[self.module_id]
915-
.scope
916-
.define_impl(impl_id)
917-
}
918-
ModItem::Function(id) => {
919-
let func = &self.item_tree[id];
920-
def = Some(DefData {
921-
id: FunctionLoc {
922-
container: container.into(),
923-
id: ItemTreeId::new(self.file_id, id),
924-
}
925-
.intern(self.def_collector.db)
926-
.into(),
927-
name: &func.name,
928-
visibility: &self.item_tree[func.visibility],
929-
has_constructor: false,
930-
});
931-
}
932-
ModItem::Struct(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];
877+
if !self.is_cfg_enabled(attrs) {
878+
continue;
879+
}
880+
let module =
881+
ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
882+
let container = ContainerId::ModuleId(module);
883+
884+
let mut def = None;
885+
match item {
886+
ModItem::Mod(m) => self.collect_module(&self.item_tree[m], attrs),
887+
ModItem::Import(import_id) => {
888+
self.def_collector.unresolved_imports.push(ImportDirective {
889+
module_id: self.module_id,
890+
import: Import::from_use(
891+
&self.item_tree,
892+
InFile::new(self.file_id, import_id),
893+
),
894+
status: PartialResolvedImport::Unresolved,
895+
})
896+
}
897+
ModItem::ExternCrate(import_id) => {
898+
self.def_collector.unresolved_imports.push(ImportDirective {
899+
module_id: self.module_id,
900+
import: Import::from_extern_crate(
901+
&self.item_tree,
902+
InFile::new(self.file_id, import_id),
903+
),
904+
status: PartialResolvedImport::Unresolved,
905+
})
906+
}
907+
ModItem::MacroCall(mac) => self.collect_macro(&self.item_tree[mac]),
908+
ModItem::Impl(imp) => {
909+
let module = ModuleId {
910+
krate: self.def_collector.def_map.krate,
911+
local_id: self.module_id,
912+
};
913+
let container = ContainerId::ModuleId(module);
914+
let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) }
915+
.intern(self.def_collector.db);
916+
self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id)
917+
}
918+
ModItem::Function(id) => {
919+
let func = &self.item_tree[id];
920+
def = Some(DefData {
921+
id: FunctionLoc {
922+
container: container.into(),
923+
id: ItemTreeId::new(self.file_id, id),
924+
}
925+
.intern(self.def_collector.db)
926+
.into(),
927+
name: &func.name,
928+
visibility: &self.item_tree[func.visibility],
929+
has_constructor: false,
930+
});
931+
}
932+
ModItem::Struct(id) => {
933+
let it = &self.item_tree[id];
951934

952-
// 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
954-
// macro invocation
955-
self.collect_derives(attrs, it.ast_id.upcast());
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());
956939

957-
def = Some(DefData {
958-
id: UnionLoc { container, id: ItemTreeId::new(self.file_id, id) }
959-
.intern(self.def_collector.db)
960-
.into(),
961-
name: &it.name,
962-
visibility: &self.item_tree[it.visibility],
963-
has_constructor: false,
964-
});
965-
}
966-
ModItem::Enum(id) => {
967-
let it = &self.item_tree[id];
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];
968951

969-
// 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
971-
// macro invocation
972-
self.collect_derives(attrs, it.ast_id.upcast());
952+
// 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
954+
// macro invocation
955+
self.collect_derives(attrs, it.ast_id.upcast());
973956

974-
def = Some(DefData {
975-
id: EnumLoc { container, id: ItemTreeId::new(self.file_id, id) }
976-
.intern(self.def_collector.db)
977-
.into(),
978-
name: &it.name,
979-
visibility: &self.item_tree[it.visibility],
980-
has_constructor: false,
981-
});
982-
}
983-
ModItem::Const(id) => {
984-
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];
957+
def = Some(DefData {
958+
id: UnionLoc { container, id: ItemTreeId::new(self.file_id, id) }
959+
.intern(self.def_collector.db)
960+
.into(),
961+
name: &it.name,
962+
visibility: &self.item_tree[it.visibility],
963+
has_constructor: false,
964+
});
965+
}
966+
ModItem::Enum(id) => {
967+
let it = &self.item_tree[id];
1002968

1003-
def = Some(DefData {
1004-
id: StaticLoc { container, id: ItemTreeId::new(self.file_id, id) }
1005-
.intern(self.def_collector.db)
1006-
.into(),
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];
969+
// 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
971+
// macro invocation
972+
self.collect_derives(attrs, it.ast_id.upcast());
1014973

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-
});
1023-
}
1024-
ModItem::TypeAlias(id) => {
1025-
let it = &self.item_tree[id];
974+
def = Some(DefData {
975+
id: EnumLoc { container, id: ItemTreeId::new(self.file_id, id) }
976+
.intern(self.def_collector.db)
977+
.into(),
978+
name: &it.name,
979+
visibility: &self.item_tree[it.visibility],
980+
has_constructor: false,
981+
});
982+
}
983+
ModItem::Const(id) => {
984+
let it = &self.item_tree[id];
1026985

986+
if let Some(name) = &it.name {
1027987
def = Some(DefData {
1028-
id: TypeAliasLoc {
988+
id: ConstLoc {
1029989
container: container.into(),
1030990
id: ItemTreeId::new(self.file_id, id),
1031991
}
1032992
.intern(self.def_collector.db)
1033993
.into(),
1034-
name: &it.name,
994+
name,
1035995
visibility: &self.item_tree[it.visibility],
1036996
has_constructor: false,
1037997
});
1038998
}
1039999
}
1000+
ModItem::Static(id) => {
1001+
let it = &self.item_tree[id];
10401002

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-
)
1003+
def = Some(DefData {
1004+
id: StaticLoc { container, id: ItemTreeId::new(self.file_id, id) }
1005+
.intern(self.def_collector.db)
1006+
.into(),
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+
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+
});
10541023
}
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+
)
10551054
}
10561055
}
10571056
}

0 commit comments

Comments
 (0)