Skip to content

Commit 36b1756

Browse files
spastorinooli-obk
authored andcommitted
Do not store lint_root
1 parent 1565612 commit 36b1756

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ struct ConstPropagator<'mir, 'tcx> {
264264
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
265265
// the last known `SourceInfo` here and just keep revisiting it.
266266
source_info: Option<SourceInfo>,
267-
lint_root: Option<HirId>,
268267
}
269268

270269
impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> {
@@ -344,7 +343,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
344343
local_decls: body.local_decls.clone(),
345344
ret: ret.map(Into::into),
346345
source_info: None,
347-
lint_root: None,
348346
}
349347
}
350348

@@ -378,6 +376,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
378376
F: FnOnce(&mut Self) -> InterpResult<'tcx, T>,
379377
{
380378
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)?;
381383
let r = match f(self) {
382384
Ok(val) => Some(val),
383385
Err(error) => {
@@ -411,7 +413,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
411413
diagnostic.report_as_lint(
412414
self.ecx.tcx,
413415
"this expression will panic at runtime",
414-
self.lint_root?,
416+
lint_root,
415417
None,
416418
);
417419
}
@@ -423,7 +425,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
423425
r
424426
}
425427

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>> {
427433
self.ecx.tcx.span = c.span;
428434

429435
// FIXME we need to revisit this for #67176
@@ -435,7 +441,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
435441
Ok(op) => Some(op),
436442
Err(error) => {
437443
let err = error_to_const_error(&self.ecx, error);
438-
match self.lint_root {
444+
match self.lint_root(source_info) {
439445
Some(lint_root) if c.literal.needs_subst() => {
440446
// Out of backwards compatibility we cannot report hard errors in unused
441447
// generic functions using associated constants of the generic parameters.
@@ -462,7 +468,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
462468

463469
fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option<Const<'tcx>> {
464470
match *op {
465-
Operand::Constant(ref c) => self.eval_constant(c),
471+
Operand::Constant(ref c) => self.eval_constant(c, source_info),
466472
Operand::Move(ref place) | Operand::Copy(ref place) => {
467473
self.eval_place(place, source_info)
468474
}
@@ -801,14 +807,13 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
801807
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
802808
trace!("visit_constant: {:?}", constant);
803809
self.super_constant(constant, location);
804-
self.eval_constant(constant);
810+
self.eval_constant(constant, self.source_info.unwrap());
805811
}
806812

807813
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
808814
trace!("visit_statement: {:?}", statement);
809815
let source_info = statement.source_info;
810816
self.source_info = Some(source_info);
811-
self.lint_root = self.lint_root(source_info);
812817
if let StatementKind::Assign(box (ref place, ref mut rval)) = statement.kind {
813818
let place_ty: Ty<'tcx> = place.ty(&self.local_decls, self.tcx).ty;
814819
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> {
860865
let source_info = terminator.source_info;
861866
self.source_info = Some(source_info);
862867
self.super_terminator(terminator, location);
863-
self.lint_root = self.lint_root(source_info);
864868
match &mut terminator.kind {
865869
TerminatorKind::Assert { expected, ref msg, ref mut cond, .. } => {
866870
if let Some(value) = self.eval_operand(&cond, source_info) {

0 commit comments

Comments
 (0)