@@ -3,8 +3,8 @@ use rustc_hir::def_id::DefId;
3
3
use rustc_hir:: lang_items:: LangItem ;
4
4
use rustc_middle:: mir:: * ;
5
5
use rustc_middle:: query:: Providers ;
6
+ use rustc_middle:: ty:: GenericArgs ;
6
7
use rustc_middle:: ty:: { self , CoroutineArgs , EarlyBinder , Ty , TyCtxt } ;
7
- use rustc_middle:: ty:: { GenericArgs , CAPTURE_STRUCT_LOCAL } ;
8
8
use rustc_target:: abi:: { FieldIdx , VariantIdx , FIRST_VARIANT } ;
9
9
10
10
use rustc_index:: { Idx , IndexVec } ;
@@ -70,39 +70,13 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
70
70
build_call_shim ( tcx, instance, Some ( Adjustment :: RefMut ) , CallKind :: Direct ( call_mut) )
71
71
}
72
72
73
- ty:: InstanceDef :: ConstructCoroutineInClosureShim {
74
- coroutine_closure_def_id,
75
- target_kind,
76
- } => match target_kind {
77
- ty:: ClosureKind :: Fn => unreachable ! ( "shouldn't be building shim for Fn" ) ,
78
- ty:: ClosureKind :: FnMut => {
79
- // No need to optimize the body, it has already been optimized
80
- // since we steal it from the `AsyncFn::call` body and just fix
81
- // the return type.
82
- return build_construct_coroutine_by_mut_shim ( tcx, coroutine_closure_def_id) ;
83
- }
84
- ty:: ClosureKind :: FnOnce => {
85
- build_construct_coroutine_by_move_shim ( tcx, coroutine_closure_def_id)
86
- }
87
- } ,
73
+ ty:: InstanceDef :: ConstructCoroutineInClosureShim { coroutine_closure_def_id } => {
74
+ build_construct_coroutine_by_move_shim ( tcx, coroutine_closure_def_id)
75
+ }
88
76
89
- ty:: InstanceDef :: CoroutineKindShim { coroutine_def_id, target_kind } => match target_kind {
90
- ty:: ClosureKind :: Fn => unreachable ! ( ) ,
91
- ty:: ClosureKind :: FnMut => {
92
- return tcx
93
- . optimized_mir ( coroutine_def_id)
94
- . coroutine_by_mut_body ( )
95
- . unwrap ( )
96
- . clone ( ) ;
97
- }
98
- ty:: ClosureKind :: FnOnce => {
99
- return tcx
100
- . optimized_mir ( coroutine_def_id)
101
- . coroutine_by_move_body ( )
102
- . unwrap ( )
103
- . clone ( ) ;
104
- }
105
- } ,
77
+ ty:: InstanceDef :: CoroutineKindShim { coroutine_def_id } => {
78
+ return tcx. optimized_mir ( coroutine_def_id) . coroutine_by_move_body ( ) . unwrap ( ) . clone ( ) ;
79
+ }
106
80
107
81
ty:: InstanceDef :: DropGlue ( def_id, ty) => {
108
82
// FIXME(#91576): Drop shims for coroutines aren't subject to the MIR passes at the end
@@ -123,21 +97,11 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
123
97
let body = if id_args. as_coroutine ( ) . kind_ty ( ) == args. as_coroutine ( ) . kind_ty ( ) {
124
98
coroutine_body. coroutine_drop ( ) . unwrap ( )
125
99
} else {
126
- match args. as_coroutine ( ) . kind_ty ( ) . to_opt_closure_kind ( ) . unwrap ( ) {
127
- ty:: ClosureKind :: Fn => {
128
- unreachable ! ( )
129
- }
130
- ty:: ClosureKind :: FnMut => coroutine_body
131
- . coroutine_by_mut_body ( )
132
- . unwrap ( )
133
- . coroutine_drop ( )
134
- . unwrap ( ) ,
135
- ty:: ClosureKind :: FnOnce => coroutine_body
136
- . coroutine_by_move_body ( )
137
- . unwrap ( )
138
- . coroutine_drop ( )
139
- . unwrap ( ) ,
140
- }
100
+ assert_eq ! (
101
+ args. as_coroutine( ) . kind_ty( ) . to_opt_closure_kind( ) . unwrap( ) ,
102
+ ty:: ClosureKind :: FnOnce
103
+ ) ;
104
+ coroutine_body. coroutine_by_move_body ( ) . unwrap ( ) . coroutine_drop ( ) . unwrap ( )
141
105
} ;
142
106
143
107
let mut body = EarlyBinder :: bind ( body. clone ( ) ) . instantiate ( tcx, args) ;
@@ -1112,7 +1076,6 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
1112
1076
1113
1077
let source = MirSource :: from_instance ( ty:: InstanceDef :: ConstructCoroutineInClosureShim {
1114
1078
coroutine_closure_def_id,
1115
- target_kind : ty:: ClosureKind :: FnOnce ,
1116
1079
} ) ;
1117
1080
1118
1081
let body =
@@ -1121,40 +1084,3 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
1121
1084
1122
1085
body
1123
1086
}
1124
-
1125
- fn build_construct_coroutine_by_mut_shim < ' tcx > (
1126
- tcx : TyCtxt < ' tcx > ,
1127
- coroutine_closure_def_id : DefId ,
1128
- ) -> Body < ' tcx > {
1129
- let mut body = tcx. optimized_mir ( coroutine_closure_def_id) . clone ( ) ;
1130
- let coroutine_closure_ty = tcx. type_of ( coroutine_closure_def_id) . instantiate_identity ( ) ;
1131
- let ty:: CoroutineClosure ( _, args) = * coroutine_closure_ty. kind ( ) else {
1132
- bug ! ( ) ;
1133
- } ;
1134
- let args = args. as_coroutine_closure ( ) ;
1135
-
1136
- body. local_decls [ RETURN_PLACE ] . ty =
1137
- tcx. instantiate_bound_regions_with_erased ( args. coroutine_closure_sig ( ) . map_bound ( |sig| {
1138
- sig. to_coroutine_given_kind_and_upvars (
1139
- tcx,
1140
- args. parent_args ( ) ,
1141
- tcx. coroutine_for_closure ( coroutine_closure_def_id) ,
1142
- ty:: ClosureKind :: FnMut ,
1143
- tcx. lifetimes . re_erased ,
1144
- args. tupled_upvars_ty ( ) ,
1145
- args. coroutine_captures_by_ref_ty ( ) ,
1146
- )
1147
- } ) ) ;
1148
- body. local_decls [ CAPTURE_STRUCT_LOCAL ] . ty =
1149
- Ty :: new_mut_ref ( tcx, tcx. lifetimes . re_erased , coroutine_closure_ty) ;
1150
-
1151
- body. source = MirSource :: from_instance ( ty:: InstanceDef :: ConstructCoroutineInClosureShim {
1152
- coroutine_closure_def_id,
1153
- target_kind : ty:: ClosureKind :: FnMut ,
1154
- } ) ;
1155
-
1156
- body. pass_count = 0 ;
1157
- dump_mir ( tcx, false , "coroutine_closure_by_mut" , & 0 , & body, |_, _| Ok ( ( ) ) ) ;
1158
-
1159
- body
1160
- }
0 commit comments