about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/Linker.cpp
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-17 19:26:22 +0100
committerGitHub <noreply@github.com>2024-03-17 19:26:22 +0100
commit8e748c0a413486c41b8c13548c9a3622646dc454 (patch)
treec2337a27cdc4b899730c7da1a7c56b0e71d3f52b /compiler/rustc_llvm/llvm-wrapper/Linker.cpp
parent3fbe203cc121f1af6690b4cef2ec67be6ac81e6d (diff)
parentbdab02ca994eebd8b4a964793d2684fc87c11119 (diff)
downloadrust-8e748c0a413486c41b8c13548c9a3622646dc454.tar.gz
rust-8e748c0a413486c41b8c13548c9a3622646dc454.zip
Rollup merge of #122578 - jieyouxu:guard-decorate, r=fee1-dead
Only invoke `decorate` if the diag can eventually be emitted

Lints can call [`trimmed_def_paths`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/print/fn.trimmed_def_paths.html#), such as through manual implementations of `LintDiagnostic` and calling `def_path_str`.

https://github.com/rust-lang/rust/blob/05a2be3def211255dc7640b006ac10f0f02baf5c/compiler/rustc_lint/src/lints.rs#L1834-L1839

The emission of a lint eventually relies on [`TyCtxt::node_lint`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.node_lint), which has a `decorate` closure which is responsible for decorating the diagnostic with "lint stuff". `node_lint` in turn relies on [`lint_level`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/fn.lint_level.html). Within `lint_level`, `decorate` is eventually called just before `Diag::emit` is called to decorate the diagnostic. However, if `-A warnings` or `--cap-lint=allow` are set, or if the unused_must_use lint is explicitly allowed, then `decorate` would be called, which would call `def_path_str`, but the diagnostic would never be emitted and hence would trigger the `must_produce_diag` ICE.

To avoid calling `decorate` when we don't eventually emit the diagnostic, we check that:

- if `--force-warn` is specified, then call `decorate`; otherwise
- if we can emit warnings (or higher), then call `decorate`.

Fixes #121774.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/Linker.cpp')
0 files changed, 0 insertions, 0 deletions