rust-lang / rust-lang/rust

[ICE]: autodiff normalize_erasing_regions fails when moving a struct with reference + unnormalised type

Open
#162,322 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Ran into this ICE when using the std::autodiff feature on nightly, I get the compiler error when I have the combination of an unnormalised type and a Box/reference. See MRE below (generated with help of an LLM):

Code
trait Op { type V; }
struct Eqn;
impl Op for Eqn { type V = f64; }
struct State<V> { y: V }
struct Inner<'a, E: Op> { s: &'a State<E::V>, a: u64, b: u64 }

fn main() {
    let s = State { y: 1.0f64 };
    let i = Inner::<Eqn> { s: &s, a: 1, b: 2 };
    let m = std::hint::black_box(i);
    println!("{}", m.a + m.b + m.s.y as u64);
}
Meta

rustc --version --verbose:

rustc 1.98.1 (48a229cea 2026-09-01)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.98.1
LLVM version: 22.1.8
Error output
❯ RUSTFLAGS="-Zautodiff=Enable" cargo +nightly run --release
   Compiling autodiff-ice v0.1.0 (/home/mrobins/git/tmp/autodiff-ice)

thread 'rustc' (1294985) panicked at /rustc-dev/0ed41eb4142dda2df61eb1145a312c1a9d62eb56/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:76:13:
assertion `left == right` failed
  left: State<Alias(No, Alias { kind: Projection { def_id: DefId(0:4 ~ autodiff_ice[349e]::Op::V) }, args: [Eqn], .. })>
 right: State<f64>
stack backtrace:
   0:     0x79257a091516 - <<std[d4c1480f659289a4]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[645f4c3e01480c61]::fmt::Display>::fmt
   1:     0x79257a80ba8f - core[645f4c3e01480c61]::fmt::write
   2:     0x79257a0a660c - <std[d4c1480f659289a4]::sys::stdio::unix::Stderr as core[645f4c3e01480c61]::io::write::Write>::write_fmt
   3:     0x79257a063dba - std[d4c1480f659289a4]::panicking::default_hook::{closure#0}
   4:     0x79257a085813 - std[d4c1480f659289a4]::panicking::default_hook
   5:     0x792578fdcaef - std[d4c1480f659289a4]::panicking::update_hook::<alloc[85239869be382ab2]::boxed::Box<rustc_driver_impl[52b061d793d3365c]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x79257a085cb2 - std[d4c1480f659289a4]::panicking::panic_with_hook
   7:     0x79257a063e72 - std[d4c1480f659289a4]::panicking::panic_handler::{closure#0}
   8:     0x79257a05ccd9 - std[d4c1480f659289a4]::sys::backtrace::__rust_end_short_backtrace::<std[d4c1480f659289a4]::panicking::panic_handler::{closure#0}, !>
   9:     0x79257a065a4d - __rustc[d3fd7ef964226397]::rust_begin_unwind
  10:     0x792576db721c - core[645f4c3e01480c61]::panicking::panic_fmt
  11:     0x792578960c93 - core[645f4c3e01480c61]::panicking::assert_failed_inner
  12:     0x79257959c5b3 - core[645f4c3e01480c61]::panicking::assert_failed::<rustc_middle[7aa4fce01e3768ef]::ty::Ty, rustc_middle[7aa4fce01e3768ef]::ty::Ty>
  13:     0x79257b0210df - <rustc_middle[7aa4fce01e3768ef]::ty::context::TyCtxt>::struct_tail_for_codegen
  14:     0x7925795ed5c5 - rustc_middle[7aa4fce01e3768ef]::ty::typetree::handle_indirection
  15:     0x7925795ee22e - rustc_middle[7aa4fce01e3768ef]::ty::typetree::typetree_from_ty_impl_inner
  16:     0x7925795ee367 - rustc_middle[7aa4fce01e3768ef]::ty::typetree::typetree_from_ty_impl_inner
  17:     0x79257ab97ef5 - <rustc_codegen_ssa[ce71d2ce136ae586]::mir::operand::OperandValue<&rustc_codegen_llvm[757fffd0e17f0ef5]::llvm::ffi::Value>>::store_with_flags::<rustc_codegen_llvm[757fffd0e17f0ef5]::builder::GenericBuilder<rustc_codegen_llvm[757fffd0e17f0ef5]::context::FullCx>>
  18:     0x79257bbabb11 - <rustc_codegen_llvm[757fffd0e17f0ef5]::builder::GenericBuilder<rustc_codegen_llvm[757fffd0e17f0ef5]::context::FullCx> as rustc_codegen_ssa[ce71d2ce136ae586]::traits::intrinsic::IntrinsicCallBuilderMethods>::codegen_intrinsic_call
  19:     0x79257bba70c0 - <rustc_codegen_ssa[ce71d2ce136ae586]::mir::FunctionCx<rustc_codegen_llvm[757fffd0e17f0ef5]::builder::GenericBuilder<rustc_codegen_llvm[757fffd0e17f0ef5]::context::FullCx>>>::codegen_intrinsic_call
  20:     0x79257be62343 - rustc_codegen_ssa[ce71d2ce136ae586]::mir::codegen_mir::<rustc_codegen_llvm[757fffd0e17f0ef5]::builder::GenericBuilder<rustc_codegen_llvm[757fffd0e17f0ef5]::context::FullCx>>
  21:     0x79257aba749c - rustc_codegen_llvm[757fffd0e17f0ef5]::base::compile_codegen_unit::module_codegen
  22:     0x79257b983a36 - <rustc_codegen_llvm[757fffd0e17f0ef5]::LlvmCodegenBackend as rustc_codegen_ssa[ce71d2ce136ae586]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  23:     0x79257b97f958 - rustc_codegen_ssa[ce71d2ce136ae586]::base::codegen_crate::<rustc_codegen_llvm[757fffd0e17f0ef5]::LlvmCodegenBackend, rustc_codegen_llvm[757fffd0e17f0ef5]::ModuleLlvm>
  24:     0x79257b97e30c - <rustc_codegen_llvm[757fffd0e17f0ef5]::LlvmCodegenBackend as rustc_codegen_ssa[ce71d2ce136ae586]::traits::backend::CodegenBackend>::codegen_crate
  25:     0x79257bc037cc - <rustc_interface[facc905b6ccf4600]::queries::Linker>::codegen_and_build_linker
  26:     0x79257bbfae41 - rustc_interface[facc905b6ccf4600]::interface::run_compiler::<(), rustc_driver_impl[52b061d793d3365c]::run_compiler::{closure#0}>::{closure#2}
  27:     0x79257bc89602 - std[d4c1480f659289a4]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[facc905b6ccf4600]::util::run_in_thread_with_globals<rustc_interface[facc905b6ccf4600]::util::run_in_thread_pool_with_globals<rustc_interface[facc905b6ccf4600]::interface::run_compiler<(), rustc_driver_impl[52b061d793d3365c]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x79257bc893ad - <std[d4c1480f659289a4]::thread::lifecycle::spawn_unchecked<rustc_interface[facc905b6ccf4600]::util::run_in_thread_with_globals<rustc_interface[facc905b6ccf4600]::util::run_in_thread_pool_with_globals<rustc_interface[facc905b6ccf4600]::interface::run_compiler<(), rustc_driver_impl[52b061d793d3365c]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[645f4c3e01480c61]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x79257bc86f47 - <std[d4c1480f659289a4]::sys::thread::unix::Thread>::new::thread_start
  30:     0x792574e8307a - start_thread
                               at ./nptl/pthread_create.c:454:8
  31:     0x792574f16534 - clone
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:100:0
  32:                0x0 - <unknown>

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 `/home/mrobins/git/tmp/autodiff-ice/rustc-ice-2026-09-05T08_00_20-1294983.txt` to your bug report

note: rustc 1.100.0-nightly (0ed41eb41 2026-09-04) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C opt-level=3 -C embed-bitcode=no -C strip=debuginfo -Z autodiff=Enable

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

query stack during panic:
end of query stack
error: could not compile `autodiff-ice` (bin "autodiff-ice")

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the supplied MRE using nightly and RUSTFLAGS="-Zautodiff=Enable". Start at compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:76, then follow the typetree and codegen paths named in the stack trace. Done means the example no longer panics and coverage protects this autodiff case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.