Skip to content

Commit e8be2bf

Browse files
committed
Auto merge of rust-lang#128396 - mu001999-contrib:fix/128053, r=<try>
Avoid repeating traversals and getting the types of fields Win back the perf. loss in rust-lang#128104 r? `@Kobzol`
2 parents 1ddedba + 7fc00e6 commit e8be2bf

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

compiler/rustc_passes/src/dead.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,22 @@ fn adt_of<'tcx>(ty: &hir::Ty<'tcx>) -> Option<(LocalDefId, DefKind)> {
7373
}
7474

7575
fn struct_all_fields_are_public(tcx: TyCtxt<'_>, id: LocalDefId) -> bool {
76-
let adt_def = tcx.adt_def(id);
77-
78-
// skip types contain fields of unit and never type,
79-
// it's usually intentional to make the type not constructible
80-
let not_require_constructor = adt_def.all_fields().any(|field| {
76+
for field in tcx.adt_def(id).all_fields() {
8177
let field_type = tcx.type_of(field.did).instantiate_identity();
82-
field_type.is_unit() || field_type.is_never()
83-
});
84-
85-
not_require_constructor
86-
|| adt_def.all_fields().all(|field| {
87-
let field_type = tcx.type_of(field.did).instantiate_identity();
88-
// skip fields of PhantomData,
89-
// cause it's a common way to check things like well-formedness
90-
if field_type.is_phantom_data() {
91-
return true;
92-
}
9378

94-
field.vis.is_public()
95-
})
79+
// skip types contain fields of unit and never type,
80+
// it's usually intentional to make the type not constructible
81+
if field_type.is_unit() || field_type.is_never() {
82+
return true;
83+
}
84+
85+
// skip fields of PhantomData,
86+
// cause it's a common way to check things like well-formedness
87+
if !field_type.is_phantom_data() && !field.vis.is_public() {
88+
return false;
89+
}
90+
}
91+
true
9692
}
9793

9894
/// check struct and its fields are public or not,

0 commit comments

Comments
 (0)