Skip to content

Commit 772d859

Browse files
committed
Only invoke decorate if the diag can eventually be emitted
1 parent a0c20d5 commit 772d859

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

compiler/rustc_middle/src/lint.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,16 @@ pub fn lint_level(
398398
}
399399
}
400400

401-
// Finally, run `decorate`.
402-
decorate(&mut err);
401+
// Finally, run `decorate`. This is guarded by a `can_emit_warnings()` check so that any
402+
// `def_path_str` called within `decorate` won't trigger a `must_produce_diag` ICE if the
403+
// `err` isn't eventually emitted (e.g. due to `-A warnings`). If an `err` is force-warn,
404+
// it's going to be emitted anyway.
405+
if matches!(err_level, rustc_errors::Level::ForceWarning(_))
406+
|| sess.dcx().can_emit_warnings()
407+
{
408+
decorate(&mut err);
409+
}
410+
403411
explain_lint_level_source(lint, level, src, &mut err);
404412
err.emit()
405413
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Checks that compiling this file with
2+
// `-Dunused_must_use -Awarnings --cap-lints=warn --crate-type=lib` does not ICE when emitting
3+
// diagnostics.
4+
// Issue: <https://github.com/rust-lang/rust/issues/121774>.
5+
6+
//@ compile-flags: -Dunused_must_use -Awarnings --cap-lints=warn --crate-type=lib
7+
//@ check-pass
8+
9+
#[must_use]
10+
fn f() {}
11+
12+
pub fn g() {
13+
f();
14+
}

0 commit comments

Comments
 (0)