diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 6a691abae02..9daee12ca2e 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -641,7 +641,14 @@ fn increment_const_eval_counter(ecx: &mut InterpCx<'tcx, Self>) -> InterpResult< // current number of evaluated terminators is a power of 2. The latter gives us a cheap // way to implement exponential backoff. let span = ecx.cur_span(); - ecx.tcx.dcx().emit_warn(LongRunningWarn { span, item_span: ecx.tcx.span }); + // We store a unique number in `force_duplicate` to evade `-Z deduplicate-diagnostics`. + // `new_steps` is guaranteed to be unique because `ecx.machine.num_evaluated_steps` is + // always increasing. + ecx.tcx.dcx().emit_warn(LongRunningWarn { + span, + item_span: ecx.tcx.span, + force_duplicate: new_steps, + }); } } diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index b66b5c0a00a..06ae5b30be0 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -209,6 +209,8 @@ pub struct LongRunningWarn { pub span: Span, #[help] pub item_span: Span, + // Used for evading `-Z deduplicate-diagnostics`. + pub force_duplicate: usize, } #[derive(Subdiagnostic)] diff --git a/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.rs b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.rs new file mode 100644 index 00000000000..a2d34eaa384 --- /dev/null +++ b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.rs @@ -0,0 +1,24 @@ +//@ check-pass + +#![allow(long_running_const_eval)] + +//@ compile-flags: -Z tiny-const-eval-limit -Z deduplicate-diagnostics=yes +const FOO: () = { + let mut i = 0; + loop { + //~^ WARN is taking a long time + //~| WARN is taking a long time + //~| WARN is taking a long time + //~| WARN is taking a long time + //~| WARN is taking a long time + if i == 1000 { + break; + } else { + i += 1; + } + } +}; + +fn main() { + FOO +} diff --git a/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr new file mode 100644 index 00000000000..cb19c59b15b --- /dev/null +++ b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr @@ -0,0 +1,92 @@ +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: 5 warnings emitted +