Only invoke decorate
if the diag can eventually be emitted
This commit is contained in:
parent
a0c20d52e0
commit
772d8598d2
2 changed files with 24 additions and 2 deletions
|
@ -398,8 +398,16 @@ pub fn lint_level(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, run `decorate`.
|
// Finally, run `decorate`. This is guarded by a `can_emit_warnings()` check so that any
|
||||||
decorate(&mut err);
|
// `def_path_str` called within `decorate` won't trigger a `must_produce_diag` ICE if the
|
||||||
|
// `err` isn't eventually emitted (e.g. due to `-A warnings`). If an `err` is force-warn,
|
||||||
|
// it's going to be emitted anyway.
|
||||||
|
if matches!(err_level, rustc_errors::Level::ForceWarning(_))
|
||||||
|
|| sess.dcx().can_emit_warnings()
|
||||||
|
{
|
||||||
|
decorate(&mut err);
|
||||||
|
}
|
||||||
|
|
||||||
explain_lint_level_source(lint, level, src, &mut err);
|
explain_lint_level_source(lint, level, src, &mut err);
|
||||||
err.emit()
|
err.emit()
|
||||||
}
|
}
|
||||||
|
|
14
tests/ui/lint/decorate-def-path-str-ice.rs
Normal file
14
tests/ui/lint/decorate-def-path-str-ice.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// Checks that compiling this file with
|
||||||
|
// `-Dunused_must_use -Awarnings --cap-lints=warn --crate-type=lib` does not ICE when emitting
|
||||||
|
// diagnostics.
|
||||||
|
// Issue: <https://github.com/rust-lang/rust/issues/121774>.
|
||||||
|
|
||||||
|
//@ compile-flags: -Dunused_must_use -Awarnings --cap-lints=warn --crate-type=lib
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
fn f() {}
|
||||||
|
|
||||||
|
pub fn g() {
|
||||||
|
f();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue