Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ pub struct LongRunning {

#[derive(Diagnostic)]
#[diag("constant evaluation is taking a long time")]
#[note("number of steps elapsed: {$force_duplicate}")]
Copy link
Member

@RalfJung RalfJung Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This number was not meant to be user-visible. Now that it is, we have to worry about what it represents. It counts how many ConstEvalCounter there have been... I don't actually know when and how those get emitted, and whether it is appropriate to call each of them one "step".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine showing it to users, but we need to filter it in UI tests, otherwise a lot of random changes will keep changing these tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An option would be to add an explicit disambiguation field to Diag independent of the message variables.

pub struct LongRunningWarn {
#[primary_span]
#[label("the const evaluator is currently interpreting this expression")]
Expand Down
39 changes: 37 additions & 2 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::thread::panicking;

use rustc_data_structures::sync::DynSend;
use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg};
use rustc_errors::formatting::{format_diag_message, format_diag_messages};
use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_macros::{Decodable, Encodable};
use rustc_span::source_map::Spanned;
Expand Down Expand Up @@ -350,7 +351,7 @@ impl DiagInner {
}
}

/// Fields used for Hash, and PartialEq trait.
/// Fields used for PartialEq trait.
fn keys(
&self,
) -> (
Expand Down Expand Up @@ -383,7 +384,41 @@ impl Hash for DiagInner {
where
H: Hasher,
{
self.keys().hash(state);
// Instead of using `Self::keys`, we compute the hash for every field because we want to
// ensure that two independent diagnostics that are built from different structured errors
// or through the `Diag` API are equivalent if their *rendered output* is the same, which
// means we have to format the diagnostic messages (and labels) before computing the hash.
self.level.hash(state);
format_diag_messages(&self.messages, &self.args).hash(state);
self.code.hash(state);
for span in self.span.primary_spans() {
span.hash(state);
}
for span_label in self.span.span_labels() {
span_label.span.hash(state);
span_label.is_primary.hash(state);
if let Some(label) = span_label.label {
format_diag_message(&label, &self.args).hash(state);
}
}
for c in &self.children {
c.level.hash(state);
format_diag_messages(&c.messages, &self.args).hash(state);
for span_label in c.span.span_labels() {
span_label.span.hash(state);
span_label.is_primary.hash(state);
if let Some(label) = span_label.label {
format_diag_message(&label, &self.args).hash(state);
}
}
}
for s in self.suggestions.borrow_tag() {
s.style.hash(state);
s.substitutions.hash(state);
format_diag_message(&s.msg, &self.args).hash(state);
s.applicability.hash(state);
}
self.is_lint.hash(state);
}
}

Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ impl Suggestions {
Suggestions::Disabled => Vec::new(),
}
}

pub fn borrow_tag(&self) -> &[CodeSuggestion] {
match self {
Suggestions::Enabled(suggestions) => &suggestions,
Suggestions::Sealed(suggestions) => &suggestions,
Suggestions::Disabled => &[],
}
}
}

impl Default for Suggestions {
Expand Down Expand Up @@ -1285,8 +1293,12 @@ impl DiagCtxtInner {
let mut hasher = StableHasher::new();
diagnostic.hash(&mut hasher);
let diagnostic_hash = hasher.finish();
tracing::info!(?diagnostic.messages);
tracing::info!(?diagnostic.span);
tracing::info!(?diagnostic_hash);
!self.emitted_diagnostics.insert(diagnostic_hash)
};
tracing::info!(?already_emitted);

let is_error = diagnostic.is_error();
let is_lint = diagnostic.is_lint.is_some();
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/cfg/cfg-stmt-recovery.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ error: removing an expression is not supported in this position
|
LL | let _ = #[cfg(false)] 0;
| ^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 3 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | / while index < n {
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
= note: number of steps elapsed: 32
help: the constant being evaluated
--> $DIR/ctfe-simple-loop.rs:20:1
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ LL | / while index < n {
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
= note: number of steps elapsed: 32
help: the constant being evaluated
--> $DIR/ctfe-simple-loop.rs:20:1
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | / loop {
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
= note: number of steps elapsed: 32
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
Expand All @@ -20,6 +21,7 @@ LL | / loop {
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
= note: number of steps elapsed: 64
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
Expand All @@ -34,6 +36,7 @@ LL | / loop {
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
= note: number of steps elapsed: 128
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
Expand All @@ -48,6 +51,7 @@ LL | / loop {
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
= note: number of steps elapsed: 256
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
Expand All @@ -62,6 +66,7 @@ LL | / loop {
LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
= note: number of steps elapsed: 512
help: the constant being evaluated
--> $DIR/evade-deduplication-issue-118612.rs:6:1
|
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/coroutine/gen_block.none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ LL | let _ = || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/gen_block.rs:16:16
Expand All @@ -94,6 +95,7 @@ LL | let _ = #[coroutine] || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 11 previous errors

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/feature-gates/feature-gate-coroutines.e2024.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ LL | yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-coroutines.rs:5:5
Expand All @@ -68,6 +69,7 @@ LL | let _ = || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-coroutines.rs:10:16
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/feature-gates/feature-gate-coroutines.none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ LL | yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-coroutines.rs:5:5
Expand All @@ -68,6 +69,7 @@ LL | let _ = || yield true;
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-coroutines.rs:10:16
Expand Down
1 change: 1 addition & 0 deletions tests/ui/feature-gates/feature-gate-yield-expr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LL | yield ();
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
= help: add `#![feature(yield_expr)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
--> $DIR/feature-gate-yield-expr.rs:5:5
Expand Down
Loading