Skip to content

Commit 848d23b

Browse files
committed
factor 'is this type allowed as union field on stable' into separate function
1 parent c80dde4 commit 848d23b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

compiler/rustc_passes/src/stability.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -772,13 +772,21 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
772772
let ty = self.tcx.type_of(item.def_id);
773773
let ty::Adt(adt_def, substs) = ty.kind() else { bug!() };
774774

775+
#[allow(rustc::usage_of_qualified_ty)] // `Ty` is the wrong type here, we really want `ty::Ty`.
776+
fn allowed_union_field<'tcx>(
777+
tcx: TyCtxt<'tcx>,
778+
param_env: ty::ParamEnv<'tcx>,
779+
ty: ty::Ty<'tcx>,
780+
) -> bool {
781+
ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())
782+
|| ty.is_copy_modulo_regions(tcx.at(DUMMY_SP), param_env)
783+
}
784+
775785
// Non-`Copy` fields are unstable, except for `ManuallyDrop`.
776786
let param_env = self.tcx.param_env(item.def_id);
777787
for field in &adt_def.non_enum_variant().fields {
778788
let field_ty = field.ty(self.tcx, substs);
779-
if !field_ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())
780-
&& !field_ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), param_env)
781-
{
789+
if !allowed_union_field(self.tcx, param_env, field_ty) {
782790
if field_ty.needs_drop(self.tcx, param_env) {
783791
// Avoid duplicate error: This will error later anyway because fields
784792
// that need drop are not allowed.

0 commit comments

Comments
 (0)