@@ -44,18 +44,6 @@ impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
44
44
}
45
45
} ;
46
46
47
- // Sometimes, the return place is assigned a local of a different but coercable type, for
48
- // example `&T` instead of `&mut T`. Overwriting the `LocalInfo` for the return place would
49
- // result in it having an incorrect type. Although this doesn't seem to cause a problem in
50
- // codegen, bail out anyways since it happens so rarely.
51
- let ret_ty = body. local_decls [ mir:: RETURN_PLACE ] . ty ;
52
- let assigned_ty = body. local_decls [ returned_local] . ty ;
53
- if ret_ty != assigned_ty {
54
- debug ! ( "`{:?}` was eligible for NRVO but for type mismatch" , src. def_id( ) ) ;
55
- debug ! ( "typeof(_0) != typeof({:?}); {:?} != {:?}" , returned_local, ret_ty, assigned_ty) ;
56
- return ;
57
- }
58
-
59
47
debug ! (
60
48
"`{:?}` was eligible for NRVO, making {:?} the return place" ,
61
49
src. def_id( ) ,
@@ -72,6 +60,12 @@ impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
72
60
// Overwrite the debuginfo of `_0` with that of the renamed local.
73
61
let ( renamed_decl, ret_decl) =
74
62
body. local_decls . pick2_mut ( returned_local, mir:: RETURN_PLACE ) ;
63
+
64
+ // Sometimes, the return place is assigned a local of a different but coercable type, for
65
+ // example `&mut T` instead of `&T`. Overwriting the `LocalInfo` for the return place means
66
+ // its type may no longer match the return type of its function. This doesn't cause a
67
+ // problem in codegen because these two types are layout-compatible, but may be unexpected.
68
+ debug ! ( "_0: {:?} = {:?}: {:?}" , ret_decl. ty, returned_local, renamed_decl. ty) ;
75
69
ret_decl. clone_from ( renamed_decl) ;
76
70
77
71
// The return place is always mutable.
0 commit comments