@@ -264,7 +264,6 @@ struct ConstPropagator<'mir, 'tcx> {
264
264
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
265
265
// the last known `SourceInfo` here and just keep revisiting it.
266
266
source_info : Option < SourceInfo > ,
267
- lint_root : Option < HirId > ,
268
267
}
269
268
270
269
impl < ' mir , ' tcx > LayoutOf for ConstPropagator < ' mir , ' tcx > {
@@ -344,7 +343,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
344
343
local_decls : body. local_decls . clone ( ) ,
345
344
ret : ret. map ( Into :: into) ,
346
345
source_info : None ,
347
- lint_root : None ,
348
346
}
349
347
}
350
348
@@ -378,6 +376,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
378
376
F : FnOnce ( & mut Self ) -> InterpResult < ' tcx , T > ,
379
377
{
380
378
self . ecx . tcx . span = source_info. span ;
379
+ // FIXME(eddyb) move this to the `Panic(_)` error case, so that
380
+ // `f(self)` is always called, and that the only difference when the
381
+ // scope's `local_data` is missing, is that the lint isn't emitted.
382
+ let lint_root = self . lint_root ( source_info) ?;
381
383
let r = match f ( self ) {
382
384
Ok ( val) => Some ( val) ,
383
385
Err ( error) => {
@@ -411,7 +413,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
411
413
diagnostic. report_as_lint (
412
414
self . ecx . tcx ,
413
415
"this expression will panic at runtime" ,
414
- self . lint_root ? ,
416
+ lint_root,
415
417
None ,
416
418
) ;
417
419
}
@@ -423,7 +425,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
423
425
r
424
426
}
425
427
426
- fn eval_constant ( & mut self , c : & Constant < ' tcx > ) -> Option < Const < ' tcx > > {
428
+ fn eval_constant (
429
+ & mut self ,
430
+ c : & Constant < ' tcx > ,
431
+ source_info : SourceInfo ,
432
+ ) -> Option < Const < ' tcx > > {
427
433
self . ecx . tcx . span = c. span ;
428
434
429
435
// FIXME we need to revisit this for #67176
@@ -435,7 +441,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
435
441
Ok ( op) => Some ( op) ,
436
442
Err ( error) => {
437
443
let err = error_to_const_error ( & self . ecx , error) ;
438
- match self . lint_root {
444
+ match self . lint_root ( source_info ) {
439
445
Some ( lint_root) if c. literal . needs_subst ( ) => {
440
446
// Out of backwards compatibility we cannot report hard errors in unused
441
447
// generic functions using associated constants of the generic parameters.
@@ -462,7 +468,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
462
468
463
469
fn eval_operand ( & mut self , op : & Operand < ' tcx > , source_info : SourceInfo ) -> Option < Const < ' tcx > > {
464
470
match * op {
465
- Operand :: Constant ( ref c) => self . eval_constant ( c) ,
471
+ Operand :: Constant ( ref c) => self . eval_constant ( c, source_info ) ,
466
472
Operand :: Move ( ref place) | Operand :: Copy ( ref place) => {
467
473
self . eval_place ( place, source_info)
468
474
}
@@ -801,14 +807,13 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
801
807
fn visit_constant ( & mut self , constant : & mut Constant < ' tcx > , location : Location ) {
802
808
trace ! ( "visit_constant: {:?}" , constant) ;
803
809
self . super_constant ( constant, location) ;
804
- self . eval_constant ( constant) ;
810
+ self . eval_constant ( constant, self . source_info . unwrap ( ) ) ;
805
811
}
806
812
807
813
fn visit_statement ( & mut self , statement : & mut Statement < ' tcx > , location : Location ) {
808
814
trace ! ( "visit_statement: {:?}" , statement) ;
809
815
let source_info = statement. source_info ;
810
816
self . source_info = Some ( source_info) ;
811
- self . lint_root = self . lint_root ( source_info) ;
812
817
if let StatementKind :: Assign ( box ( ref place, ref mut rval) ) = statement. kind {
813
818
let place_ty: Ty < ' tcx > = place. ty ( & self . local_decls , self . tcx ) . ty ;
814
819
if let Ok ( place_layout) = self . tcx . layout_of ( self . param_env . and ( place_ty) ) {
@@ -860,7 +865,6 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
860
865
let source_info = terminator. source_info ;
861
866
self . source_info = Some ( source_info) ;
862
867
self . super_terminator ( terminator, location) ;
863
- self . lint_root = self . lint_root ( source_info) ;
864
868
match & mut terminator. kind {
865
869
TerminatorKind :: Assert { expected, ref msg, ref mut cond, .. } => {
866
870
if let Some ( value) = self . eval_operand ( & cond, source_info) {
0 commit comments