@@ -359,81 +359,62 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
359
359
& mut self ,
360
360
block : BasicBlock ,
361
361
kind : & TerminatorKind < ' tcx > ,
362
- _location : Location ,
362
+ location : Location ,
363
363
) {
364
- match kind {
365
- TerminatorKind :: SwitchInt { discr : value, .. } |
366
- TerminatorKind :: Yield { value, .. } |
367
- TerminatorKind :: Assert { cond : value, .. } => {
368
- match value {
369
- Operand :: Constant ( box Constant {
370
- literal : Literal :: Value {
371
- value : & ty:: Const {
372
- val : ConstVal :: Value ( _) ,
373
- ..
374
- } ,
375
- } ,
376
- ..
377
- } ) => return ,
378
- _ => { } ,
379
- }
380
- if let Some ( value) = self . eval_operand ( value) {
381
- if let TerminatorKind :: Assert { expected, msg, .. } = kind {
382
- if Value :: ByVal ( PrimVal :: from_bool ( * expected) ) != value. 0 {
383
- let span = self . mir [ block]
384
- . terminator
385
- . as_ref ( )
386
- . unwrap ( )
387
- . source_info
388
- . span ;
389
- let node_id = self
390
- . tcx
391
- . hir
392
- . as_local_node_id ( self . source . def_id )
393
- . expect ( "some part of a failing const eval must be local" ) ;
394
- let mut lint = self . tcx . struct_span_lint_node (
395
- :: rustc:: lint:: builtin:: CONST_ERR ,
396
- node_id,
364
+ self . super_terminator_kind ( block, kind, location) ;
365
+ if let TerminatorKind :: Assert { expected, msg, cond, .. } = kind {
366
+ if let Some ( value) = self . eval_operand ( cond) {
367
+ if Value :: ByVal ( PrimVal :: from_bool ( * expected) ) != value. 0 {
368
+ let span = self . mir [ block]
369
+ . terminator
370
+ . as_ref ( )
371
+ . unwrap ( )
372
+ . source_info
373
+ . span ;
374
+ let node_id = self
375
+ . tcx
376
+ . hir
377
+ . as_local_node_id ( self . source . def_id )
378
+ . expect ( "some part of a failing const eval must be local" ) ;
379
+ let mut lint = self . tcx . struct_span_lint_node (
380
+ :: rustc:: lint:: builtin:: CONST_ERR ,
381
+ node_id,
382
+ span,
383
+ "constant evaluation error" ,
384
+ ) ;
385
+ use rustc:: mir:: AssertMessage :: * ;
386
+ match msg {
387
+ GeneratorResumedAfterReturn =>
388
+ lint. span_label ( span, "generator resumed after completion" ) ,
389
+ GeneratorResumedAfterPanic =>
390
+ lint. span_label ( span, "generator resumed after panicking" ) ,
391
+ Math ( ref err) => lint. span_label ( span, err. description ( ) ) ,
392
+ BoundsCheck { ref len, ref index } => {
393
+ let len = self . eval_operand ( len) . expect ( "len must be const" ) ;
394
+ let len = match len. 0 {
395
+ Value :: ByVal ( PrimVal :: Bytes ( n) ) => n,
396
+ _ => bug ! ( "const len not primitive: {:?}" , len) ,
397
+ } ;
398
+ let index = self
399
+ . eval_operand ( index)
400
+ . expect ( "index must be const" ) ;
401
+ let index = match index. 0 {
402
+ Value :: ByVal ( PrimVal :: Bytes ( n) ) => n,
403
+ _ => bug ! ( "const index not primitive: {:?}" , index) ,
404
+ } ;
405
+ lint. span_label (
397
406
span,
398
- "constant evaluation error" ,
399
- ) ;
400
- use rustc:: mir:: AssertMessage :: * ;
401
- match msg {
402
- GeneratorResumedAfterReturn =>
403
- lint. span_label ( span, "generator resumed after completion" ) ,
404
- GeneratorResumedAfterPanic =>
405
- lint. span_label ( span, "generator resumed after panicking" ) ,
406
- Math ( ref err) => lint. span_label ( span, err. description ( ) ) ,
407
- BoundsCheck { ref len, ref index } => {
408
- let len = self . eval_operand ( len) . expect ( "len must be const" ) ;
409
- let len = match len. 0 {
410
- Value :: ByVal ( PrimVal :: Bytes ( n) ) => n,
411
- _ => bug ! ( "const len not primitive: {:?}" , len) ,
412
- } ;
413
- let index = self
414
- . eval_operand ( index)
415
- . expect ( "index must be const" ) ;
416
- let index = match index. 0 {
417
- Value :: ByVal ( PrimVal :: Bytes ( n) ) => n,
418
- _ => bug ! ( "const index not primitive: {:?}" , index) ,
419
- } ;
420
- lint. span_label (
421
- span,
422
- format ! (
423
- "index out of bounds: \
424
- the len is {} but the index is {}",
425
- len,
426
- index,
427
- ) ,
428
- )
429
- } ,
430
- } . emit ( ) ;
431
- }
432
- }
407
+ format ! (
408
+ "index out of bounds: \
409
+ the len is {} but the index is {}",
410
+ len,
411
+ index,
412
+ ) ,
413
+ )
414
+ } ,
415
+ } . emit ( ) ;
433
416
}
434
417
}
435
- // FIXME: do this optimization for function calls
436
- _ => { } ,
437
418
}
438
419
}
439
420
}
0 commit comments