Skip to content

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

Closed
@sosthene-nitrokey

Description

@sosthene-nitrokey

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.

Activity

added
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 26, 2025
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Mar 26, 2025
cyrgani

cyrgani commented on Mar 26, 2025

@cyrgani
Contributor

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

added
S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
on Mar 26, 2025
cyrgani

cyrgani commented on Mar 26, 2025

@cyrgani
Contributor

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

cyrgani

cyrgani commented on Mar 26, 2025

@cyrgani
Contributor

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

added
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Mar 26, 2025
apiraino

apiraino commented on Mar 27, 2025

@apiraino
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

apiraino commented on Mar 27, 2025

@apiraino
Contributor

Assigning priority (discussion on Zulip).

@rustbot label -I-prioritize +P-high

18 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @lqd@compiler-errors@apiraino@jieyouxu@rustbot

    Issue actions

      ICE: `trimmed_def_paths` called, diagnostics were expected but none were emitted. · Issue #138979 · rust-lang/rust