Only invoke decorate if the diag can eventually be emitted

This commit is contained in:
许杰友 Jieyou Xu (Joe)
2024-03-16 02:38:42 +00:00
parent a0c20d52e0
commit 772d8598d2
2 changed files with 24 additions and 2 deletions

View File

@@ -398,8 +398,16 @@ pub fn lint_level(
}
}
// Finally, run `decorate`.
decorate(&mut err);
// Finally, run `decorate`. This is guarded by a `can_emit_warnings()` check so that any
// `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);
err.emit()
}