Skip to content

ICE: trimmed_def_paths called, diagnostics were expected but none were emitted. #138979

New issue

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

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

Already on GitHub? # to your account

Closed
sosthene-nitrokey opened this issue Mar 26, 2025 · 12 comments · Fixed by #139025
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sosthene-nitrokey
Copy link

sosthene-nitrokey commented Mar 26, 2025

Code

The error shows up on a heapless PRhttps://github.com/rust-embedded/heapless/actions/runs/14080602762/job/39432486570

Meta

The error reproduces on the latest nightly.

rustc --version --verbose:

rustc 1.87.0-nightly (43f0014ef 2025-03-25)
binary: rustc
commit-hash: 43f0014ef0f242418674f49052ed39b70f73bc1c
commit-date: 2025-03-25
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.1

Error output

thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:702:17:
`trimmed_def_paths` called, diagnostics were expected but none were emitted. Use `with_no_trimmed_paths` for debugging. This happened in the following `must_produce_diag` call's backtrace:

The file Rustc tells me to include in the report: rustc-ice-2025-03-26T10_16_27-247085.txt

Backtrace

$ RUST_BACKTRACE=1 cargo +nightly test --test cpass --target=x86_64-unknown-linux-gnu --features=serde --release
   Compiling heapless v0.8.0 (/path/to/heapless)
   Compiling ufmt-macros v0.3.0
   Compiling ufmt v0.2.0

thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:702:17:
`trimmed_def_paths` called, diagnostics were expected but none were emitted. Use `with_no_trimmed_paths` for debugging. This happened in the following `must_produce_diag` call's backtrace:
   0: <rustc_errors::DiagCtxtHandle>::set_must_produce_diag
   1: <rustc_session::session::Session>::record_trimmed_def_paths
   2: rustc_middle::ty::print::pretty::trimmed_def_paths
   3: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::trimmed_def_paths::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
   4: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
   5: rustc_query_impl::query_impl::trimmed_def_paths::get_query_non_incr::__rust_end_short_backtrace
   6: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::Printer>::print_def_path
   7: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::Printer>::print_def_path
   8: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_type
   9: <rustc_type_ir::ty_kind::TypeAndMut<rustc_middle::ty::context::TyCtxt> as rustc_middle::ty::print::Print<rustc_middle::ty::print::pretty::FmtPrinter>>::print
  10: <rustc_middle::ty::print::pretty::FmtPrinter as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_type
  11: <rustc_middle::ty::Ty as core::fmt::Display>::fmt
  12: core::fmt::write
  13: alloc::fmt::format::format_inner
  14: rustc_mir_transform::validate::validate_types
  15: rustc_mir_transform::inline::process_blocks::<rustc_mir_transform::inline::NormalInliner>
  16: <rustc_mir_transform::inline::Inline as rustc_mir_transform::pass_manager::MirPass>::run_pass
  17: rustc_mir_transform::pass_manager::run_passes_inner
  18: rustc_mir_transform::optimized_mir
  19: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
  21: rustc_query_impl::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  22: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  23: rustc_metadata::rmeta::encoder::encode_metadata
  24: rustc_metadata::fs::encode_and_write_metadata
  25: <rustc_interface::queries::Linker>::codegen_and_build_linker
  26: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  27: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  28: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30: std::sys::pal::unix::thread::Thread::new::thread_start
  31: <unknown>
  32: <unknown>

stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_errors::DiagCtxtInner as core::ops::drop::Drop>::drop
   3: core::ptr::drop_in_place::<rustc_errors::DiagCtxt>
   4: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
   5: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
   6: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `//heapless/rustc-ice-2025-03-26T10_16_27-247085.txt` to your bug report

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C strip=debuginfo

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `heapless` (lib)

Caused by:
  process didn't exit successfully: `/path/to/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name heapless --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=118 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="serde"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("defmt-03", "mpmc_large", "nightly", "portable-atomic", "portable-atomic-critical-section", "portable-atomic-unsafe-assume-single-core", "serde", "ufmt"))' -C metadata=6044f4ee7b749481 -C extra-filename=-f464495b68b6a9ee --out-dir /path/to/heapless/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C strip=debuginfo -L dependency=/path/to/heapless/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/path/to/heapless/target/release/deps --extern hash32=/path/to/heapless/target/x86_64-unknown-linux-gnu/release/deps/libhash32-3e9b94b42a8a0b01.rmeta --extern serde=/path/to/heapless/target/x86_64-unknown-linux-gnu/release/deps/libserde-66dbe2816a197a10.rmeta --extern stable_deref_trait=/path/to/heapless/target/x86_64-unknown-linux-gnu/release/deps/libstable_deref_trait-2c16bd63df11f843.rmeta --check-cfg 'cfg(arm_llsc)' --check-cfg 'cfg(has_atomic_load_store)'` (exit status: 101)

I saw #135673, which seems to be the same issue, but should be fixed (at least in the latest nightly), but as tested on nightly it fails.

@sosthene-nitrokey sosthene-nitrokey added C-bug Category: This is a bug. 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. labels Mar 26, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 26, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Mar 26, 2025

reduction:

trait Storage {
    type Buffer: ?Sized;
}

struct Array<const N: usize>;
impl<const N: usize> Storage for Array<N> {
    type Buffer = [(); N];
}

struct Slice;
impl Storage for Slice {
    type Buffer = [()];
}

struct Wrap<S: Storage> {
    _b: S::Buffer,
}

fn coerce<const N: usize>(this: &Wrap<Array<N>>) -> &Wrap<Slice>
where
    Array<N>: Storage,
{
    coerce_again(this)
}

fn coerce_again<const N: usize>(this: &Wrap<Array<N>>) -> &Wrap<Slice> {
    this
}

fn main() {
    let inner: Wrap<Array<1>> = Wrap { _b: [(); 1] };
    let _: &Wrap<Slice> = coerce(&inner);
}

requires rustc -C opt-level=2 to reproduces
@rustbot label S-has-mcve

@rustbot rustbot added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Mar 26, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Mar 26, 2025

bisection:
searched toolchains nightly-2024-06-05 through nightly-2024-10-05


Regression in nightly-2024-09-28


fetching https://static.rust-lang.org/dist/2024-09-27/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-09-27: 40 B / 40 B [======================================================] 100.00 % 452.14 KB/s converted 2024-09-27 to 2bd1e89
fetching https://static.rust-lang.org/dist/2024-09-28/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-09-28: 40 B / 40 B [======================================================] 100.00 % 439.01 KB/s converted 2024-09-28 to fa724e5
looking for regression commit between 2024-09-27 and 2024-09-28
fetching (via remote github) commits from max(2bd1e89, 2024-09-25) to fa724e5
ending github query because we found starting sha: 2bd1e89
get_commits_between returning commits, len: 5
commit[0] 2024-09-26: Auto merge of #129624 - tgross35:cargo-update, r=Mark-Simulacrum
commit[1] 2024-09-26: Auto merge of #130907 - GuillaumeGomez:rollup-423r4i4, r=GuillaumeGomez
commit[2] 2024-09-27: Auto merge of #130919 - workingjubilee:rollup-4diycoy, r=workingjubilee
commit[3] 2024-09-27: Auto merge of #130857 - lukas-code:no-clones-allowed, r=notriddle
commit[4] 2024-09-27: Auto merge of #130934 - matthiaskrgr:rollup-4puticr, r=matthiaskrgr

@rustbot label S-has-bisection

@rustbot rustbot added the S-has-bisection Status: a bisection has been found for this issue label Mar 26, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Mar 26, 2025

also
@rustbot label regression-from-stable-to-stable

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 26, 2025
@jieyouxu jieyouxu added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 26, 2025
@apiraino
Copy link
Contributor

I get a different result when bisecting the provided repro.


Regression in rust-lang-ci@5b5ad01
The PR introducing the regression in this rollup is #132947: clarify must_produce_diag ICE for debugging

searched nightlies: from nightly-2024-08-30 to nightly-2025-03-27
regressed nightly: nightly-2024-11-13
searched commit range: 81eef2d...f7273e0
regressed commit: f7273e0

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc 2024-08-30 --script test.sh 

cc @lqd does it ring a bell? thanks

@apiraino
Copy link
Contributor

apiraino commented Mar 27, 2025

Assigning priority (discussion on Zulip).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 27, 2025
@lqd
Copy link
Member

lqd commented Mar 27, 2025

Seeing that I only changed the ICE message, you likely were bisecting too precisely for that and not the ICE in general?

@jieyouxu
Copy link
Member

jieyouxu commented Mar 27, 2025

I had a quick look and nothing in either bisection stands out to me... I looked at the first bisection and tried to revert a few potential ones, didn't fix the ICE. The second bisection seems unrelated too as that shouldn't be causing a new ICE.

EDIT: I'm getting 2024-09-26, not 2024-09-28.

@jieyouxu jieyouxu removed the S-has-bisection Status: a bisection has been found for this issue label Mar 27, 2025
@jieyouxu
Copy link
Member


Regression in nightly-2024-09-26


fetching https://static.rust-lang.org/dist/2024-09-25/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-09-25: 40 B / 40 B [===========================================================================] 100.00 % 281.02 KB/s converted 2024-09-25 to 363ae41
fetching https://static.rust-lang.org/dist/2024-09-26/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-09-26: 40 B / 40 B [============================================================================] 100.00 % 79.51 KB/s converted 2024-09-26 to 9e394f5
looking for regression commit between 2024-09-25 and 2024-09-26
fetching (via remote github) commits from max(363ae41, 2024-09-23) to 9e394f5
ending github query because we found starting sha: 363ae41
get_commits_between returning commits, len: 11
commit[0] 2024-09-24: Auto merge of #129587 - Voultapher:opt-for-size-variants-of-sort-impls, r=cuviper
commit[1] 2024-09-24: Auto merge of #130739 - jieyouxu:stage0_run_make, r=Kobzol
commit[2] 2024-09-25: Auto merge of #130807 - tgross35:rollup-p304vzf, r=tgross35
commit[3] 2024-09-25: Auto merge of #130803 - cuviper:file-buffered, r=joshtriplett
commit[4] 2024-09-25: Auto merge of #18184 - Veykril:veykril/push-wsqsyxynttps, r=Veykril
commit[5] 2024-09-25: Auto merge of #18183 - lnicola:sync-from-rust, r=lnicola
commit[6] 2024-09-25: Auto merge of #130816 - matthiaskrgr:rollup-jy25phv, r=matthiaskrgr
commit[7] 2024-09-25: Auto merge of #130778 - flip1995:clippy-subtree-update, r=Manishearth
commit[8] 2024-09-25: Auto merge of #130812 - lnicola:sync-from-ra, r=lnicola
commit[9] 2024-09-25: Auto merge of #130847 - matthiaskrgr:rollup-f0n80bw, r=matthiaskrgr
commit[10] 2024-09-25: Auto merge of #120752 - compiler-errors:more-relevant-bounds, r=lcnr
ERROR: no CI builds available between 363ae41 and 9e394f5 within last 167 days

@compiler-errors
Copy link
Member

It's probably (at least root cause) due to 8fc8e03, which added new validation to the MIR validator.

@compiler-errors compiler-errors self-assigned this Mar 27, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 27, 2025
@bors bors closed this as completed in d837ab4 Mar 28, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 28, 2025
Rollup merge of rust-lang#139025 - compiler-errors:trim-validator-err, r=jieyouxu

Do not trim paths in MIR validator

From my inline comment:

```
// The type checker formats a bunch of strings with type names in it, but these strings
// are not always going to be encountered on the error path since the inliner also uses
// the validator, and there are certain kinds of inlining (even for valid code) that
// can cause validation errors (mostly around where clauses and rigid projections).
```

Fixes rust-lang#138979

r? `@jieyouxu`
@sosthene-nitrokey
Copy link
Author

sosthene-nitrokey commented Mar 28, 2025

Thanks for the quick fix! I'm not sure how it falls in the release schedule. Will this fix be included as part of 1.86 or will it have to wait for 1.87 since 1.86 is already branched of main ?

And if we have to wait for 1.87, are you aware of a workaround we could use in the meantime?

@cyrgani
Copy link
Contributor

cyrgani commented Mar 28, 2025

A simple workaround could be to intentionally cause a warning temporarily, such as adding fn dead_code_ice_workaround() {} to lib.rs to trigger dead_code and supress the ICE.

@sosthene-nitrokey
Copy link
Author

sosthene-nitrokey commented Mar 28, 2025

Thanks. Looks like it's even possible to silence the warning and still make it work by using #[expect(dead_code)] (#[allow(dead_code)] would not prevent the crash).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

7 participants