mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
factor 'is this type allowed as union field on stable' into separate function
This commit is contained in:
parent
c80dde43f9
commit
848d23b57b
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user