diff options
| author | Ralf Jung <post@ralfj.de> | 2022-06-10 21:44:57 -0700 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-07-13 18:27:28 -0400 |
| commit | 848d23b57bb788cfdf0df6ec5d83b56b7c19f8ff (patch) | |
| tree | 4ba4c81ef93e65a98881eed57701fb9a17b93fcd | |
| parent | c80dde43f992f3eb419899a34551b84c6301f8e8 (diff) | |
| download | rust-848d23b57bb788cfdf0df6ec5d83b56b7c19f8ff.tar.gz rust-848d23b57bb788cfdf0df6ec5d83b56b7c19f8ff.zip | |
factor 'is this type allowed as union field on stable' into separate function
| -rw-r--r-- | compiler/rustc_passes/src/stability.rs | 14 |
1 files 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. |
