File tree 1 file changed +11
-3
lines changed
compiler/rustc_passes/src
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -772,13 +772,21 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
772
772
let ty = self . tcx . type_of ( item. def_id ) ;
773
773
let ty:: Adt ( adt_def, substs) = ty. kind ( ) else { bug ! ( ) } ;
774
774
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
+
775
785
// Non-`Copy` fields are unstable, except for `ManuallyDrop`.
776
786
let param_env = self . tcx . param_env ( item. def_id ) ;
777
787
for field in & adt_def. non_enum_variant ( ) . fields {
778
788
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) {
782
790
if field_ty. needs_drop ( self . tcx , param_env) {
783
791
// Avoid duplicate error: This will error later anyway because fields
784
792
// that need drop are not allowed.
You can’t perform that action at this time.
0 commit comments