Skip to content

Commit b4ac138

Browse files
Rollup merge of rust-lang#130665 - veera-sivarajan:fix-118612, r=compiler-errors
Prevent Deduplication of `LongRunningWarn` Fixes rust-lang#118612 As mention in the issue, `LongRunningWarn` is meant to be repeated multiple times. Therefore, this PR stores a unique number in every instance of `LongRunningWarn` so that it's not hashed into the same value and omitted by the deduplication mechanism.
2 parents a457a95 + 669f610 commit b4ac138

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,14 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
641641
// current number of evaluated terminators is a power of 2. The latter gives us a cheap
642642
// way to implement exponential backoff.
643643
let span = ecx.cur_span();
644-
ecx.tcx.dcx().emit_warn(LongRunningWarn { span, item_span: ecx.tcx.span });
644+
// We store a unique number in `force_duplicate` to evade `-Z deduplicate-diagnostics`.
645+
// `new_steps` is guaranteed to be unique because `ecx.machine.num_evaluated_steps` is
646+
// always increasing.
647+
ecx.tcx.dcx().emit_warn(LongRunningWarn {
648+
span,
649+
item_span: ecx.tcx.span,
650+
force_duplicate: new_steps,
651+
});
645652
}
646653
}
647654

compiler/rustc_const_eval/src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ pub struct LongRunningWarn {
209209
pub span: Span,
210210
#[help]
211211
pub item_span: Span,
212+
// Used for evading `-Z deduplicate-diagnostics`.
213+
pub force_duplicate: usize,
212214
}
213215

214216
#[derive(Subdiagnostic)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ check-pass
2+
3+
#![allow(long_running_const_eval)]
4+
5+
//@ compile-flags: -Z tiny-const-eval-limit -Z deduplicate-diagnostics=yes
6+
const FOO: () = {
7+
let mut i = 0;
8+
loop {
9+
//~^ WARN is taking a long time
10+
//~| WARN is taking a long time
11+
//~| WARN is taking a long time
12+
//~| WARN is taking a long time
13+
//~| WARN is taking a long time
14+
if i == 1000 {
15+
break;
16+
} else {
17+
i += 1;
18+
}
19+
}
20+
};
21+
22+
fn main() {
23+
FOO
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
warning: constant evaluation is taking a long time
2+
--> $DIR/evade-deduplication-issue-118612.rs:8:5
3+
|
4+
LL | / loop {
5+
LL | |
6+
LL | |
7+
LL | |
8+
... |
9+
LL | | }
10+
LL | | }
11+
| |_____^ the const evaluator is currently interpreting this expression
12+
|
13+
help: the constant being evaluated
14+
--> $DIR/evade-deduplication-issue-118612.rs:6:1
15+
|
16+
LL | const FOO: () = {
17+
| ^^^^^^^^^^^^^
18+
19+
warning: constant evaluation is taking a long time
20+
--> $DIR/evade-deduplication-issue-118612.rs:8:5
21+
|
22+
LL | / loop {
23+
LL | |
24+
LL | |
25+
LL | |
26+
... |
27+
LL | | }
28+
LL | | }
29+
| |_____^ the const evaluator is currently interpreting this expression
30+
|
31+
help: the constant being evaluated
32+
--> $DIR/evade-deduplication-issue-118612.rs:6:1
33+
|
34+
LL | const FOO: () = {
35+
| ^^^^^^^^^^^^^
36+
37+
warning: constant evaluation is taking a long time
38+
--> $DIR/evade-deduplication-issue-118612.rs:8:5
39+
|
40+
LL | / loop {
41+
LL | |
42+
LL | |
43+
LL | |
44+
... |
45+
LL | | }
46+
LL | | }
47+
| |_____^ the const evaluator is currently interpreting this expression
48+
|
49+
help: the constant being evaluated
50+
--> $DIR/evade-deduplication-issue-118612.rs:6:1
51+
|
52+
LL | const FOO: () = {
53+
| ^^^^^^^^^^^^^
54+
55+
warning: constant evaluation is taking a long time
56+
--> $DIR/evade-deduplication-issue-118612.rs:8:5
57+
|
58+
LL | / loop {
59+
LL | |
60+
LL | |
61+
LL | |
62+
... |
63+
LL | | }
64+
LL | | }
65+
| |_____^ the const evaluator is currently interpreting this expression
66+
|
67+
help: the constant being evaluated
68+
--> $DIR/evade-deduplication-issue-118612.rs:6:1
69+
|
70+
LL | const FOO: () = {
71+
| ^^^^^^^^^^^^^
72+
73+
warning: constant evaluation is taking a long time
74+
--> $DIR/evade-deduplication-issue-118612.rs:8:5
75+
|
76+
LL | / loop {
77+
LL | |
78+
LL | |
79+
LL | |
80+
... |
81+
LL | | }
82+
LL | | }
83+
| |_____^ the const evaluator is currently interpreting this expression
84+
|
85+
help: the constant being evaluated
86+
--> $DIR/evade-deduplication-issue-118612.rs:6:1
87+
|
88+
LL | const FOO: () = {
89+
| ^^^^^^^^^^^^^
90+
91+
warning: 5 warnings emitted
92+

0 commit comments

Comments
 (0)