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