1
1
//! See docs in `build/expr/mod.rs`.
2
2
3
- use rustc_abi:: { BackendRepr , FieldIdx , Primitive } ;
3
+ use rustc_abi:: FieldIdx ;
4
4
use rustc_hir:: lang_items:: LangItem ;
5
5
use rustc_index:: { Idx , IndexVec } ;
6
6
use rustc_middle:: bug;
@@ -9,7 +9,6 @@ use rustc_middle::mir::interpret::Scalar;
9
9
use rustc_middle:: mir:: * ;
10
10
use rustc_middle:: thir:: * ;
11
11
use rustc_middle:: ty:: cast:: { CastTy , mir_cast_kind} ;
12
- use rustc_middle:: ty:: layout:: IntegerExt ;
13
12
use rustc_middle:: ty:: util:: IntTypeExt ;
14
13
use rustc_middle:: ty:: { self , Ty , UpvarArgs } ;
15
14
use rustc_span:: source_map:: Spanned ;
@@ -200,89 +199,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
200
199
{
201
200
let discr_ty = adt_def. repr ( ) . discr_type ( ) . to_ty ( this. tcx ) ;
202
201
let temp = unpack ! ( block = this. as_temp( block, scope, source, Mutability :: Not ) ) ;
203
- let layout =
204
- this. tcx . layout_of ( this. typing_env ( ) . as_query_input ( source_expr. ty ) ) ;
205
202
let discr = this. temp ( discr_ty, source_expr. span ) ;
206
203
this. cfg . push_assign (
207
204
block,
208
205
source_info,
209
206
discr,
210
207
Rvalue :: Discriminant ( temp. into ( ) ) ,
211
208
) ;
212
- let ( op, ty) = ( Operand :: Move ( discr) , discr_ty) ;
213
-
214
- if let BackendRepr :: Scalar ( scalar) = layout. unwrap ( ) . backend_repr
215
- && !scalar. is_always_valid ( & this. tcx )
216
- && let Primitive :: Int ( int_width, _signed) = scalar. primitive ( )
217
- {
218
- let unsigned_ty = int_width. to_ty ( this. tcx , false ) ;
219
- let unsigned_place = this. temp ( unsigned_ty, expr_span) ;
220
- this. cfg . push_assign (
221
- block,
222
- source_info,
223
- unsigned_place,
224
- Rvalue :: Cast ( CastKind :: IntToInt , Operand :: Copy ( discr) , unsigned_ty) ,
225
- ) ;
226
-
227
- let bool_ty = this. tcx . types . bool ;
228
- let range = scalar. valid_range ( & this. tcx ) ;
229
- let merge_op =
230
- if range. start <= range. end { BinOp :: BitAnd } else { BinOp :: BitOr } ;
231
-
232
- let mut comparer = |range : u128 , bin_op : BinOp | -> Place < ' tcx > {
233
- // We can use `ty::TypingEnv::fully_monomorphized()` here
234
- // as we only need it to compute the layout of a primitive.
235
- let range_val = Const :: from_bits (
236
- this. tcx ,
237
- range,
238
- ty:: TypingEnv :: fully_monomorphized ( ) ,
239
- unsigned_ty,
240
- ) ;
241
- let lit_op = this. literal_operand ( expr. span , range_val) ;
242
- let is_bin_op = this. temp ( bool_ty, expr_span) ;
243
- this. cfg . push_assign (
244
- block,
245
- source_info,
246
- is_bin_op,
247
- Rvalue :: BinaryOp (
248
- bin_op,
249
- Box :: new ( ( Operand :: Copy ( unsigned_place) , lit_op) ) ,
250
- ) ,
251
- ) ;
252
- is_bin_op
253
- } ;
254
- let assert_place = if range. start == 0 {
255
- comparer ( range. end , BinOp :: Le )
256
- } else {
257
- let start_place = comparer ( range. start , BinOp :: Ge ) ;
258
- let end_place = comparer ( range. end , BinOp :: Le ) ;
259
- let merge_place = this. temp ( bool_ty, expr_span) ;
260
- this. cfg . push_assign (
261
- block,
262
- source_info,
263
- merge_place,
264
- Rvalue :: BinaryOp (
265
- merge_op,
266
- Box :: new ( (
267
- Operand :: Move ( start_place) ,
268
- Operand :: Move ( end_place) ,
269
- ) ) ,
270
- ) ,
271
- ) ;
272
- merge_place
273
- } ;
274
- this. cfg . push (
275
- block,
276
- Statement :: new (
277
- source_info,
278
- StatementKind :: Intrinsic ( Box :: new ( NonDivergingIntrinsic :: Assume (
279
- Operand :: Move ( assert_place) ,
280
- ) ) ) ,
281
- ) ,
282
- ) ;
283
- }
284
-
285
- ( op, ty)
209
+ ( Operand :: Move ( discr) , discr_ty)
286
210
} else {
287
211
let ty = source_expr. ty ;
288
212
let source = unpack ! (
0 commit comments