Repository: rust
Issue: ICE: entered unreachable code: FieldsShape::offset: `Primitive`s have no fields
Labels: I-ICE,E-needs-test,T-compiler,C-bug,A-mir-opt,A-mir-opt-inlining,-Zvalidate-mir

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

```Rust
//@ run-pass
use std::ops::{Index, IndexMut};

struct Foo {
    x: isize,
    y: isize,
}

impl Index<isize> for Foo {
    type Output = isize;

    fn index(&self, z: isize) -> &isize {
        if z == 0 {
            &self.x
        } else {
            &self.y
        }
    }
}

impl IndexMut<isize> for Foo {
    fn index_mut(&mut self, z: isize) -> &mut isize {
        if z == 0 {
            &mut self.x
        } else {
            &mut self.y
        }
    }
}

trait Int {
    fn get(self) -> isize;
    fn get_from_ref(&self) -> isize;
    fn inc(&mut self);
}

impl Int for isize {
    fn get(self) -> isize { self }
    fn get_from_ref(&self) -> isize { *self }
    fn inc(&mut self, z: isize) { *self += 1; }
}

fn main() {
    let mut f = Foo {
        x: 1,
        y: 2,
    };
    assert_eq!(f[1], 2);
    f[0] = 3;
    assert_eq!(f[0], 3);
    {
        let p = &mut f[1];
        *p = 4;
    }
    {
        let p = &f[1];
        assert_eq!(*p, 4);
    }

    // Test calling methods with `&mut self`, `self, and `&self` receivers:
    f[1].inc();
    assert_eq!(f[1].get(), 5);
    assert_eq!(f[1].get_from_ref(), 5);
}
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.85.0-nightly (cb2bd2bb0 2024-11-29)
binary: rustc
commit-hash: cb2bd2bb06380896368b0edb02ada0117cc856be
commit-date: 2024-11-29
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4
```

### Error output
`rustc -Zmir-opt-level=5  -Zvalidate-mir -Zcross-crate-inline-threshold=always`
```
error[E0050]: method `inc` has 2 parameters but the declaration in trait `Int::inc` has 1
  --> b.rs:40:12
   |
34 |     fn inc(&mut self);
   |            --------- trait requires 1 parameter
...
40 |     fn inc(&mut self, z: isize) { *self += 1; }
   |            ^^^^^^^^^^^^^^^^^^^ expected 1 parameter, found 2

warning: unused variable: `z`
  --> b.rs:40:23
   |
40 |     fn inc(&mut self, z: isize) { *self += 1; }
   |                       ^ help: if this is intentional, prefix it with an underscore: `_z`
   |
   = note: `#[warn(unused_variables)]` on by default
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
thread 'rustc' panicked at /rustc/cb2bd2bb06380896368b0edb02ada0117cc856be/compiler/rustc_abi/src/lib.rs:1279:17:
internal error: entered unreachable code: FieldsShape::offset: `Primitive`s have no fields
stack backtrace:
   0:     0x73db1615a52a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6c57494279711599
   1:     0x73db16813ce2 - core::fmt::write::h3cad130fa8f43609
   2:     0x73db17bc6751 - std::io::Write::write_fmt::hb86a90f8009f8eb9
   3:     0x73db1615a382 - std::sys::backtrace::BacktraceLock::print::hb87e1976e8deede9
   4:     0x73db1615c88a - std::panicking::default_hook::{{closure}}::hf27528882c284812
   5:     0x73db1615c6d3 - std::panicking::default_hook::h2e4e154622bd23bd
   6:     0x73db152d7458 - std[26132d93986e58f8]::panicking::update_hook::<alloc[ce9158905f7620dd]::boxed::Box<rustc_driver_impl[4e4c9531434a88da]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x73db1615d048 - std::panicking::rust_panic_with_hook::hbc36709f273d6692
   8:     0x73db1615cd06 - std::panicking::begin_panic_handler::{{closure}}::hdaf35ac8208622f3
   9:     0x73db1615a9e9 - std::sys::backtrace::__rust_end_short_backtrace::h77be1680146547f4
  10:     0x73db1615c9fd - rust_begin_unwind
  11:     0x73db13697550 - core::panicking::panic_fmt::h7e7c15009d6c0ed9
  12:     0x73db182a4dfb - <rustc_abi[e5f09d209a26d145]::FieldsShape<rustc_abi[e5f09d209a26d145]::layout::ty::FieldIdx>>::offset.cold
  13:     0x73db172f9138 - <rustc_const_eval[a260793c7dd70fb7]::interpret::eval_context::InterpCx<rustc_const_eval[a260793c7dd70fb7]::const_eval::dummy_machine::DummyMachine>>::project_field::<rustc_const_eval[a260793c7dd70fb7]::interpret::operand::OpTy>
  14:     0x73db15ade63a - <rustc_mir_transform[b565ecd2e11aba68]::dataflow_const_prop::ConstAnalysis>::assign_constant::{closure#0}
  15:     0x73db159eb8cf - <rustc_mir_dataflow[235f8b34f07bfca]::value_analysis::Map>::for_each_projection_value::<rustc_const_eval[a260793c7dd70fb7]::interpret::operand::OpTy, <rustc_mir_transform[b565ecd2e11aba68]::dataflow_const_prop::ConstAnalysis>::assign_constant::{closure#0}, <rustc_mir_transform[b565ecd2e11aba68]::dataflow_const_prop::ConstAnalysis>::assign_constant::{closure#1}>
  16:     0x73db15ade5fe - <rustc_mir_transform[b565ecd2e11aba68]::dataflow_const_prop::ConstAnalysis>::assign_constant
  17:     0x73db15aa018e - <rustc_mir_transform[b565ecd2e11aba68]::dataflow_const_prop::ConstAnalysis>::assign_operand
  18:     0x73db15a9eb0f - <rustc_mir_transform[b565ecd2e11aba68]::dataflow_const_prop::ConstAnalysis as rustc_mir_dataflow[235f8b34f07bfca]::framework::Analysis>::apply_statement_effect
  19:     0x73db15adf306 - <rustc_mir_transform[b565ecd2e11aba68]::dataflow_const_prop::DataflowConstProp as rustc_mir_transform[b565ecd2e11aba68]::pass_manager::MirPass>::run_pass
  20:     0x73db1680f32e - rustc_mir_transform[b565ecd2e11aba68]::pass_manager::run_passes_inner
  21:     0x73db16da84da - rustc_mir_transform[b565ecd2e11aba68]::optimized_mir
  22:     0x73db16da7dab - rustc_query_impl[a54b6583e60c070e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a54b6583e60c070e]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8f8812feb7945426]::query::erase::Erased<[u8; 8usize]>>
  23:     0x73db1683e208 - rustc_query_system[4ef38b7e62ca61e0]::query::plumbing::try_execute_query::<rustc_query_impl[a54b6583e60c070e]::DynamicConfig<rustc_query_system[4ef38b7e62ca61e0]::query::caches::DefIdCache<rustc_middle[8f8812feb7945426]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a54b6583e60c070e]::plumbing::QueryCtxt, false>
  24:     0x73db1683d7b3 - rustc_query_impl[a54b6583e60c070e]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  25:     0x73db13046650 - <rustc_middle[8f8812feb7945426]::ty::context::TyCtxt>::instance_mir
  26:     0x73db1715d429 - rustc_interface[c86b95b32cbbd6f5]::passes::run_required_analyses
  27:     0x73db1715645e - rustc_interface[c86b95b32cbbd6f5]::passes::analysis
  28:     0x73db1715642f - rustc_query_impl[a54b6583e60c070e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a54b6583e60c070e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8f8812feb7945426]::query::erase::Erased<[u8; 1usize]>>
  29:     0x73db1775483a - rustc_query_system[4ef38b7e62ca61e0]::query::plumbing::try_execute_query::<rustc_query_impl[a54b6583e60c070e]::DynamicConfig<rustc_query_system[4ef38b7e62ca61e0]::query::caches::SingleCache<rustc_middle[8f8812feb7945426]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a54b6583e60c070e]::plumbing::QueryCtxt, false>
  30:     0x73db1775450e - rustc_query_impl[a54b6583e60c070e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  31:     0x73db177eab87 - rustc_interface[c86b95b32cbbd6f5]::interface::run_compiler::<core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>, rustc_driver_impl[4e4c9531434a88da]::run_compiler::{closure#0}>::{closure#1}
  32:     0x73db177324c7 - std[26132d93986e58f8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c86b95b32cbbd6f5]::util::run_in_thread_with_globals<rustc_interface[c86b95b32cbbd6f5]::util::run_in_thread_pool_with_globals<rustc_interface[c86b95b32cbbd6f5]::interface::run_compiler<core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>, rustc_driver_impl[4e4c9531434a88da]::run_compiler::{closure#0}>::{closure#1}, core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>>::{closure#0}, core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>>
  33:     0x73db17732162 - <<std[26132d93986e58f8]::thread::Builder>::spawn_unchecked_<rustc_interface[c86b95b32cbbd6f5]::util::run_in_thread_with_globals<rustc_interface[c86b95b32cbbd6f5]::util::run_in_thread_pool_with_globals<rustc_interface[c86b95b32cbbd6f5]::interface::run_compiler<core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>, rustc_driver_impl[4e4c9531434a88da]::run_compiler::{closure#0}>::{closure#1}, core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>>::{closure#0}, core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[10e5919d76f1e6dc]::result::Result<(), rustc_span[2eb738640235e66]::ErrorGuaranteed>>::{closure#1} as core[10e5919d76f1e6dc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x73db177318ab - std::sys::pal::unix::thread::Thread::new::thread_start::h2571e9214e43aed4
  35:     0x73db18f3339d - <unknown>
  36:     0x73db18fb849c - <unknown>
  37:                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 `/tmp/im/rustc-ice-2024-11-29T11_27_25-3367734.txt` to your bug report

note: compiler flags: -Z mir-opt-level=5 -Z validate-mir -Z cross-crate-inline-threshold=always

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0050`.
```

</p>
</details>