Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: must_produce_diag: trimmed_def_paths called but no diagnostics emitted #121774

Closed
dtolnay opened this issue Feb 29, 2024 · 6 comments · Fixed by #122578
Closed

ICE: must_produce_diag: trimmed_def_paths called but no diagnostics emitted #121774

dtolnay opened this issue Feb 29, 2024 · 6 comments · Fixed by #122578
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 29, 2024

Input:

// lib.rs

#[must_use]
fn f() {}

pub fn g() {
    f();
}

rustc lib.rs -Dunused_must_use -Awarnings --cap-lints=warn --crate-type=lib

thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:572:17:
must_produce_diag: trimmed_def_paths called but no diagnostics emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging
stack backtrace:
   0:     0x7f268108cdb6 - std::backtrace_rs::backtrace::libunwind::trace::h341f79bffd736d88
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f268108cdb6 - std::backtrace_rs::backtrace::trace_unsynchronized::h699175639bf0c53f
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f268108cdb6 - std::sys_common::backtrace::_print_fmt::he64554b6b8851325
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f268108cdb6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6f1d81aff3ba783c
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f26810ddd3c - core::fmt::rt::Argument::fmt::ha094c70f8a774861
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/core/src/fmt/rt.rs:142:9
   5:     0x7f26810ddd3c - core::fmt::write::h7f13c4b287d5364f
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f268108163f - std::io::Write::write_fmt::h33c62cb7f1d9ccd2
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/io/mod.rs:1846:15
   7:     0x7f268108cb64 - std::sys_common::backtrace::_print::h5a328173cecd6a17
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f268108cb64 - std::sys_common::backtrace::print::h40f459d9b04f57e7
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f268108f8ab - std::panicking::default_hook::{{closure}}::hd2a3df71af903bed
  10:     0x7f268108f5f9 - std::panicking::default_hook::ha092baec2054d09a
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/panicking.rs:292:9
  11:     0x7f267dc9bcbc - std[aeaa4a650f96ca4f]::panicking::update_hook::<alloc[4c4126b71025da3b]::boxed::Box<rustc_driver_impl[2ad8c6e0ef02d37]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f2681090010 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he192bb5ab07c6e66
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/alloc/src/boxed.rs:2030:9
  13:     0x7f2681090010 - std::panicking::rust_panic_with_hook::h46c6fddd63cff830
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/panicking.rs:783:13
  14:     0x7f268108fd19 - std::panicking::begin_panic_handler::{{closure}}::h8abc72b89d98e75c
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/panicking.rs:649:13
  15:     0x7f268108d296 - std::sys_common::backtrace::__rust_end_short_backtrace::h1eafc870bd031abe
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f268108fa84 - rust_begin_unwind
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/panicking.rs:645:5
  17:     0x7f26810da255 - core::panicking::panic_fmt::hd079a8afc216673e
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/core/src/panicking.rs:72:14
  18:     0x7f26805d5ea2 - <rustc_errors[8f2d5467e268fcd1]::DiagCtxtInner as core[ceaa87f59aeb8bba]::ops::drop::Drop>::drop.cold.0
  19:     0x7f267fb5719c - core[ceaa87f59aeb8bba]::ptr::drop_in_place::<rustc_errors[8f2d5467e268fcd1]::DiagCtxt>
  20:     0x7f267fdee217 - core[ceaa87f59aeb8bba]::ptr::drop_in_place::<rustc_session[6420a5b3483699f8]::parse::ParseSess>
  21:     0x7f267fdee7f1 - core[ceaa87f59aeb8bba]::ptr::drop_in_place::<rustc_interface[91b806f92bb77cda]::interface::Compiler>
  22:     0x7f267fd3e672 - rustc_interface[91b806f92bb77cda]::interface::run_compiler::<core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>, rustc_driver_impl[2ad8c6e0ef02d37]::run_compiler::{closure#0}>::{closure#0}
  23:     0x7f267ffddd05 - std[aeaa4a650f96ca4f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[91b806f92bb77cda]::util::run_in_thread_with_globals<rustc_interface[91b806f92bb77cda]::util::run_in_thread_pool_with_globals<rustc_interface[91b806f92bb77cda]::interface::run_compiler<core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>, rustc_driver_impl[2ad8c6e0ef02d37]::run_compiler::{closure#0}>::{closure#0}, core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>>::{closure#0}, core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>>
  24:     0x7f267ffddb32 - <<std[aeaa4a650f96ca4f]::thread::Builder>::spawn_unchecked_<rustc_interface[91b806f92bb77cda]::util::run_in_thread_with_globals<rustc_interface[91b806f92bb77cda]::util::run_in_thread_pool_with_globals<rustc_interface[91b806f92bb77cda]::interface::run_compiler<core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>, rustc_driver_impl[2ad8c6e0ef02d37]::run_compiler::{closure#0}>::{closure#0}, core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>>::{closure#0}, core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ceaa87f59aeb8bba]::result::Result<(), rustc_span[ac3b12a2af12cb0d]::ErrorGuaranteed>>::{closure#1} as core[ceaa87f59aeb8bba]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f26810999e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4c4227d670230628
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/alloc/src/boxed.rs:2016:9
  26:     0x7f26810999e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4bc52f0323c8ae82
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/alloc/src/boxed.rs:2016:9
  27:     0x7f26810999e5 - std::sys::pal::unix::thread::Thread::new::thread_start::hd34fbf5607308b31
                               at /rustc/c475e2303b551d726307c646181e0677af1e0069/library/std/src/sys/pal/unix/thread.rs:108:17
  28:     0x7f267aa94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  29:     0x7f267ab26850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  30:                0x0 - <unknown>
$ rustc --version --verbose
rustc 1.78.0-nightly (c475e2303 2024-02-28)
binary: rustc
commit-hash: c475e2303b551d726307c646181e0677af1e0069
commit-date: 2024-02-28
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
@dtolnay dtolnay added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 29, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 29, 2024
@dtolnay
Copy link
Member Author

dtolnay commented Feb 29, 2024

Bisects to Rust 1.55.0, and nightly-2021-07-20. In older stable and nightly releases, this compiles successfully.

@dtolnay dtolnay added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Feb 29, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 29, 2024
@dtolnay dtolnay added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Feb 29, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 29, 2024
@apiraino
Copy link
Contributor

bisection points to rollup 27f5d83

If I had to guess, I'd say that #93590 looks like the one. It's the only one in the rollup touching diagnostic code. Possibly my reasoning is off (pls correct me).

@dtolnay
Copy link
Member Author

dtolnay commented Feb 29, 2024

Something went wrong with your bisect, as 27f5d83 is from 2022-02-02, whereas this ICE is present in nightly-2021-07-20.

#86970 looks the most likely to me.

@Nilstrieb
Copy link
Member

Either way, this is probably easier to debug from scratch instead of digging around commits.
Previous issue with this ICE message should reveal information on how to fix these issues, which arise from eagerly formatting paths in lints instead of only when they're emitted.

@Nilstrieb Nilstrieb added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 29, 2024
@chenyukang
Copy link
Member

Fix for a similar issue : #108162

@bors bors closed this as completed in 8e748c0 Mar 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 17, 2024
Rollup merge of rust-lang#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 rust-lang#121774.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants