rust-lang / rust-lang/rust

ICE ` with ref binding has wrong type Pin`

Open
#148,893 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

auto-reduced (treereduce-rust):

fn main() {
    let ref pin mut x: i32 = 0;
}

original:

//@ check-pass
#![feature(pin_ergonomics)]
#![allow(dead_code, incomplete_features)]

// Handle the case where there's ambiguity between pin as a contextual keyword and pin as a path.

struct Foo;

mod pin {
    pub struct Foo;
    #[expect(non_camel_case_types)]
    pub struct pin;

    fn foo() {
        let _x: &pin = &pin;
    }
}

fn main() {
    let _x: &pin::Foo = &pin::Foo;
    let &pin: &i32 = &0;
    let ref pin mut x: i32 = 0;
}

Version information

rustc 1.93.0-nightly (01867557c 2025-11-12)
binary: rustc
commit-hash: 01867557cd7dbe256a031a7b8e28d05daecd75ab
commit-date: 2025-11-12
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

Possibly related line of code:
https://github.com/rust-lang/rust/blob/01867557cd7dbe256a031a7b8e28d05daecd75ab/compiler/rustc_borrowck/src/type_check/mod.rs#L954-L966

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0658]: pinned reference syntax is experimental
 --> /tmp/icemaker_global_tempdir.7SooKOcSJ79S/rustc_testrunner_tmpdir_reporting.RNGrQLi7P2yd/mvce.rs:2:13
  |
2 |     let ref pin mut x: i32 = 0;
  |             ^^^
  |
  = note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information
  = help: add `#![feature(pin_ergonomics)]` to the crate attributes to enable
  = note: this compiler was built on 2025-11-12; consider upgrading it if it is out of date

error: internal compiler error: compiler/rustc_borrowck/src/type_check/mod.rs:960:17: _1 with ref binding has wrong type Pin<&mut i32>


thread 'rustc' (3304180) panicked at compiler/rustc_borrowck/src/type_check/mod.rs:960:17:
Box<dyn Any>
stack backtrace:
   0:     0x7f5936875033 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h95ffa264faac5c9f
   1:     0x7f5937001afc - core::fmt::write::ha17326c1edd231a1
   2:     0x7f59368298c3 - std::io::Write::write_fmt::h71bdf7213b9ae5e6
   3:     0x7f593683afc2 - std::sys::backtrace::BacktraceLock::print::ha4f7741bafad9575
   4:     0x7f5936841159 - std::panicking::default_hook::{{closure}}::h840bce9c0e1f4479
   5:     0x7f5936840c83 - std::panicking::default_hook::h373530ca2faaac30
   6:     0x7f5935831e61 - std[c8d4bb381711e68]::panicking::update_hook::<alloc[2508525745eabac6]::boxed::Box<rustc_driver_impl[3c4699642b322592]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f593684157b - std::panicking::panic_with_hook::he0d479546e4ce5b9
   8:     0x7f593586e3d1 - std[c8d4bb381711e68]::panicking::begin_panic::<rustc_errors[4a6b3a26dff7b902]::ExplicitBug>::{closure#0}
   9:     0x7f5935860876 - std[c8d4bb381711e68]::sys::backtrace::__rust_end_short_backtrace::<std[c8d4bb381711e68]::panicking::begin_panic<rustc_errors[4a6b3a26dff7b902]::ExplicitBug>::{closure#0}, !>
  10:     0x7f593585dfc9 - std[c8d4bb381711e68]::panicking::begin_panic::<rustc_errors[4a6b3a26dff7b902]::ExplicitBug>
  11:     0x7f593588cc01 - <rustc_errors[4a6b3a26dff7b902]::diagnostic::BugAbort as rustc_errors[4a6b3a26dff7b902]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7f5935e1792a - rustc_middle[8d85ffaee97d78d]::util::bug::opt_span_bug_fmt::<rustc_span[5a5bd85de0de1f2b]::span_encoding::Span>::{closure#0}
  13:     0x7f5935e17aaa - rustc_middle[8d85ffaee97d78d]::ty::context::tls::with_opt::<rustc_middle[8d85ffaee97d78d]::util::bug::opt_span_bug_fmt<rustc_span[5a5bd85de0de1f2b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f5935e084bb - rustc_middle[8d85ffaee97d78d]::ty::context::tls::with_context_opt::<rustc_middle[8d85ffaee97d78d]::ty::context::tls::with_opt<rustc_middle[8d85ffaee97d78d]::util::bug::opt_span_bug_fmt<rustc_span[5a5bd85de0de1f2b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f5933a24dc0 - rustc_middle[8d85ffaee97d78d]::util::bug::bug_fmt
  16:     0x7f59385de42f - <rustc_borrowck[27f101a42cc742b5]::type_check::TypeChecker as rustc_middle[8d85ffaee97d78d]::mir::visit::Visitor>::visit_body
  17:     0x7f5934049be1 - rustc_borrowck[27f101a42cc742b5]::type_check::type_check
  18:     0x7f5937f58a06 - <rustc_borrowck[27f101a42cc742b5]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  19:     0x7f5937f51d6a - rustc_borrowck[27f101a42cc742b5]::mir_borrowck
  20:     0x7f5937f51bd9 - rustc_query_impl[a5b196b04c634821]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a5b196b04c634821]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d85ffaee97d78d]::query::erase::Erased<[u8; 8usize]>>
  21:     0x7f5937273577 - rustc_query_system[4710bc6056744570]::query::plumbing::try_execute_query::<rustc_query_impl[a5b196b04c634821]::DynamicConfig<rustc_data_structures[ae499ee93fe3a250]::vec_cache::VecCache<rustc_span[5a5bd85de0de1f2b]::def_id::LocalDefId, rustc_middle[8d85ffaee97d78d]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[4710bc6056744570]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[a5b196b04c634821]::plumbing::QueryCtxt, false>
  22:     0x7f5937f4cb4b - rustc_query_impl[a5b196b04c634821]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7f5937f4cd77 - <rustc_middle[8d85ffaee97d78d]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[23742b77bf084c1c]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  24:     0x7f5937f4a618 - rustc_interface[23742b77bf084c1c]::passes::analysis
  25:     0x7f5937f49ab3 - rustc_query_impl[a5b196b04c634821]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a5b196b04c634821]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d85ffaee97d78d]::query::erase::Erased<[u8; 0usize]>>
  26:     0x7f59380901da - rustc_query_system[4710bc6056744570]::query::plumbing::try_execute_query::<rustc_query_impl[a5b196b04c634821]::DynamicConfig<rustc_query_system[4710bc6056744570]::query::caches::SingleCache<rustc_middle[8d85ffaee97d78d]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[a5b196b04c634821]::plumbing::QueryCtxt, false>
  27:     0x7f593808fe14 - rustc_query_impl[a5b196b04c634821]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7f59382c3a83 - <rustc_interface[23742b77bf084c1c]::passes::create_and_enter_global_ctxt<core[9a42bb1793c5c9a8]::option::Option<rustc_interface[23742b77bf084c1c]::queries::Linker>, rustc_driver_impl[3c4699642b322592]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[9a42bb1793c5c9a8]::ops::function::FnOnce<(&rustc_session[158844ada7f0f676]::session::Session, rustc_middle[8d85ffaee97d78d]::ty::context::CurrentGcx, alloc[2508525745eabac6]::sync::Arc<rustc_data_structures[ae499ee93fe3a250]::jobserver::Proxy>, &std[c8d4bb381711e68]::sync::once_lock::OnceLock<rustc_middle[8d85ffaee97d78d]::ty::context::GlobalCtxt>, &rustc_data_structures[ae499ee93fe3a250]::sync::worker_local::WorkerLocal<rustc_middle[8d85ffaee97d78d]::arena::Arena>, &rustc_data_structures[ae499ee93fe3a250]::sync::worker_local::WorkerLocal<rustc_hir[3a966f3954156600]::Arena>, rustc_driver_impl[3c4699642b322592]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  29:     0x7f59381223a9 - rustc_interface[23742b77bf084c1c]::interface::run_compiler::<(), rustc_driver_impl[3c4699642b322592]::run_compiler::{closure#0}>::{closure#1}
  30:     0x7f593814cf7b - std[c8d4bb381711e68]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[23742b77bf084c1c]::util::run_in_thread_with_globals<rustc_interface[23742b77bf084c1c]::util::run_in_thread_pool_with_globals<rustc_interface[23742b77bf084c1c]::interface::run_compiler<(), rustc_driver_impl[3c4699642b322592]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  31:     0x7f593814cc54 - <<std[c8d4bb381711e68]::thread::Builder>::spawn_unchecked_<rustc_interface[23742b77bf084c1c]::util::run_in_thread_with_globals<rustc_interface[23742b77bf084c1c]::util::run_in_thread_pool_with_globals<rustc_interface[23742b77bf084c1c]::interface::run_compiler<(), rustc_driver_impl[3c4699642b322592]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[9a42bb1793c5c9a8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7f5938150faf - std::sys::thread::unix::Thread::new::thread_start::hfb7aed7a74f6cac0
  33:     0x7f59318969cb - <unknown>
  34:     0x7f593191aa0c - <unknown>
  35:                0x0 - <unknown>

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: rustc 1.93.0-nightly (01867557c 2025-11-12) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `main`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 2 previous errors

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

@rustbot label +F-pin_ergonomics

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

Start with the reduced Rust program in the issue and the related check in compiler/rustc_borrowck/src/type_check/mod.rs around line 960. Run the reproducer with the reported nightly and inspect the borrow-checking path for ref bindings involving Pin. Done means the program no longer triggers an internal compiler error and produces the expected diagnostic behavior.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.