Skip to content

Commit 1ed3a20

Browse files
committed
Dedup code
1 parent d79b82f commit 1ed3a20

File tree

1 file changed

+21
-20
lines changed
  • compiler/rustc_privacy/src

1 file changed

+21
-20
lines changed

compiler/rustc_privacy/src/lib.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,25 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
947947
});
948948
}
949949
}
950+
951+
fn check_expanded_fields(
952+
&mut self,
953+
adt: ty::AdtDef<'tcx>,
954+
variant: &'tcx ty::VariantDef,
955+
fields: &[hir::ExprField<'tcx>],
956+
hir_id: hir::HirId,
957+
span: Span,
958+
) {
959+
for (vf_index, variant_field) in variant.fields.iter_enumerated() {
960+
let field =
961+
fields.iter().find(|f| self.typeck_results().field_index(f.hir_id) == vf_index);
962+
let (hir_id, use_ctxt, span) = match field {
963+
Some(field) => (field.hir_id, field.ident.span, field.span),
964+
None => (hir_id, span, span),
965+
};
966+
self.check_field(hir_id, use_ctxt, span, adt, variant_field, true);
967+
}
968+
}
950969
}
951970

952971
impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
@@ -971,28 +990,10 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
971990
// If the expression uses FRU we need to make sure all the unmentioned fields
972991
// are checked for privacy (RFC 736). Rather than computing the set of
973992
// unmentioned fields, just check them all.
974-
for (vf_index, variant_field) in variant.fields.iter_enumerated() {
975-
let field = fields
976-
.iter()
977-
.find(|f| self.typeck_results().field_index(f.hir_id) == vf_index);
978-
let (hir_id, use_ctxt, span) = match field {
979-
Some(field) => (field.hir_id, field.ident.span, field.span),
980-
None => (base.hir_id, base.span, base.span),
981-
};
982-
self.check_field(hir_id, use_ctxt, span, adt, variant_field, true);
983-
}
993+
self.check_expanded_fields(adt, variant, fields, base.hir_id, base.span);
984994
}
985995
hir::StructTailExpr::DefaultFields(span) => {
986-
for (vf_index, variant_field) in variant.fields.iter_enumerated() {
987-
let field = fields
988-
.iter()
989-
.find(|f| self.typeck_results().field_index(f.hir_id) == vf_index);
990-
let (hir_id, use_ctxt, span) = match field {
991-
Some(field) => (field.hir_id, field.ident.span, field.span),
992-
None => (expr.hir_id, span, span),
993-
};
994-
self.check_field(hir_id, use_ctxt, span, adt, variant_field, true);
995-
}
996+
self.check_expanded_fields(adt, variant, fields, expr.hir_id, span);
996997
}
997998
hir::StructTailExpr::None => {
998999
for field in fields {

0 commit comments

Comments
 (0)