From 848d23b57bb788cfdf0df6ec5d83b56b7c19f8ff Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 10 Jun 2022 21:44:57 -0700 Subject: [PATCH] factor 'is this type allowed as union field on stable' into separate function --- compiler/rustc_passes/src/stability.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 12050dceb60..a1697978d66 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -772,13 +772,21 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let ty = self.tcx.type_of(item.def_id); let ty::Adt(adt_def, substs) = ty.kind() else { bug!() }; + #[allow(rustc::usage_of_qualified_ty)] // `Ty` is the wrong type here, we really want `ty::Ty`. + fn allowed_union_field<'tcx>( + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ty: ty::Ty<'tcx>, + ) -> bool { + ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop()) + || ty.is_copy_modulo_regions(tcx.at(DUMMY_SP), param_env) + } + // Non-`Copy` fields are unstable, except for `ManuallyDrop`. let param_env = self.tcx.param_env(item.def_id); for field in &adt_def.non_enum_variant().fields { let field_ty = field.ty(self.tcx, substs); - if !field_ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop()) - && !field_ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), param_env) - { + if !allowed_union_field(self.tcx, param_env, field_ty) { if field_ty.needs_drop(self.tcx, param_env) { // Avoid duplicate error: This will error later anyway because fields // that need drop are not allowed.