factor 'is this type allowed as union field on stable' into separate function
This commit is contained in:
parent
c80dde43f9
commit
848d23b57b
1 changed files with 11 additions and 3 deletions
|
@ -772,13 +772,21 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
|
||||||
let ty = self.tcx.type_of(item.def_id);
|
let ty = self.tcx.type_of(item.def_id);
|
||||||
let ty::Adt(adt_def, substs) = ty.kind() else { bug!() };
|
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`.
|
// Non-`Copy` fields are unstable, except for `ManuallyDrop`.
|
||||||
let param_env = self.tcx.param_env(item.def_id);
|
let param_env = self.tcx.param_env(item.def_id);
|
||||||
for field in &adt_def.non_enum_variant().fields {
|
for field in &adt_def.non_enum_variant().fields {
|
||||||
let field_ty = field.ty(self.tcx, substs);
|
let field_ty = field.ty(self.tcx, substs);
|
||||||
if !field_ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())
|
if !allowed_union_field(self.tcx, param_env, field_ty) {
|
||||||
&& !field_ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), param_env)
|
|
||||||
{
|
|
||||||
if field_ty.needs_drop(self.tcx, param_env) {
|
if field_ty.needs_drop(self.tcx, param_env) {
|
||||||
// Avoid duplicate error: This will error later anyway because fields
|
// Avoid duplicate error: This will error later anyway because fields
|
||||||
// that need drop are not allowed.
|
// that need drop are not allowed.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue