@@ -42,9 +42,8 @@ fn is_stable(
4242 }
4343}
4444
45- /// Determine whether this type may have a reference in it, recursing below compound types but
46- /// not below references.
47- fn may_have_reference < ' tcx > ( ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> bool {
45+ /// Determine whether this type may be a reference (or box), and thus needs retagging.
46+ fn may_be_reference < ' tcx > ( ty : Ty < ' tcx > ) -> bool {
4847 match ty. sty {
4948 // Primitive types that are not references
5049 ty:: Bool | ty:: Char |
@@ -55,15 +54,12 @@ fn may_have_reference<'tcx>(ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
5554 // References
5655 ty:: Ref ( ..) => true ,
5756 ty:: Adt ( ..) if ty. is_box ( ) => true ,
58- // Compound types
59- ty:: Array ( ty, ..) | ty:: Slice ( ty) =>
60- may_have_reference ( ty, tcx) ,
61- ty:: Tuple ( tys) =>
62- tys. iter ( ) . any ( |ty| may_have_reference ( ty. expect_ty ( ) , tcx) ) ,
63- ty:: Adt ( adt, substs) =>
64- adt. variants . iter ( ) . any ( |v| v. fields . iter ( ) . any ( |f|
65- may_have_reference ( f. ty ( tcx, substs) , tcx)
66- ) ) ,
57+ // Compound types are not references
58+ ty:: Array ( ..) |
59+ ty:: Slice ( ..) |
60+ ty:: Tuple ( ..) |
61+ ty:: Adt ( ..) =>
62+ false ,
6763 // Conservative fallback
6864 _ => true ,
6965 }
@@ -80,7 +76,7 @@ impl MirPass for AddRetag {
8076 // FIXME: Instead of giving up for unstable places, we should introduce
8177 // a temporary and retag on that.
8278 is_stable ( place. as_ref ( ) )
83- && may_have_reference ( place. ty ( & * local_decls, tcx) . ty , tcx )
79+ && may_be_reference ( place. ty ( & * local_decls, tcx) . ty )
8480 } ;
8581
8682 // PART 1
0 commit comments