rust-lang / rust-lang/rust

[ICE]: `mismatched projections in place_element_conflict`

Open
#162,143 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

auto-reduced (treereduce-rust):

#![feature(reborrow)]
use std::marker::{CoerceShared, PhantomData, Reborrow};

#[derive(Reborrow, CoerceShared)]
#[coerce_shared(CustomMarkerRef<'a>)]
struct CustomMarker<'a>(PhantomData<&'a ()>);

struct CustomMarkerRef<'a>();

fn method<'a>(_a: CustomMarkerRef<'a>) -> &'a () {
    &()
}

fn main() {
    let a = CustomMarker(PhantomData);

    let c = method(a);

    let x = &a.0;
    let _ = c;
}

original:

//! Test that CoerceShared of custom ZST marker type reborrows the type automatically as shared but
//! moving the original invalidates the results.

#![feature(reborrow)]
use std::marker::{CoerceShared, PhantomData, Reborrow};

#[derive(Reborrow, CoerceShared)]
#[coerce_shared(CustomMarkerRef<'a>)]
struct CustomMarker<'a>(PhantomData<&'a ()>);
#[derive(Clone, Copy)]
struct CustomMarkerRef<'a>(PhantomData<&'a ()>);

fn method<'a>(_a: CustomMarkerRef<'a>) -> &'a () {
    &()
}

fn move_into<T>(_: T) {}

fn main() {
    let a = CustomMarker(PhantomData);
    let b = method(a);
    let c = method(a);
    move_into(a);
    //~^ ERROR: cannot move out of `a` because it is borrowed
    let x = &a.0;
    let _ = c;
}

Version information

rustc 1.100.0-nightly (a4330234a 2026-09-01)
binary: rustc
commit-hash: a4330234a776684c36428d001721d0320d24dd77
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.0

Possibly related line of code:
https://github.com/rust-lang/rust/blob/a4330234a776684c36428d001721d0320d24dd77/compiler/rustc_borrowck/src/places_conflict.rs#L524-L536

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

Program output

error[E0277]: the trait bound `CustomMarkerRef<'a>: Copy` is not satisfied
    --> /tmp/icemaker_global_tempdir.PzPKVRlZ5j2C/rustc_testrunner_tmpdir_reporting.cycmjFyyopNr/mvce.rs:4:20
     |
   4 | #[derive(Reborrow, CoerceShared)]
     |                    ^^^^^^^^^^^^ the trait `Copy` is not implemented for `CustomMarkerRef<'a>`
     |
note: required by a bound in `CoerceShared`
    --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/marker.rs:1369:32
     |
1369 | pub trait CoerceShared<Target: Copy>: Reborrow {
     |                                ^^^^ required by this bound in `CoerceShared`
help: consider annotating `CustomMarkerRef<'a>` with `#[derive(Copy)]`
     |
   8 + #[derive(Copy)]
   9 | struct CustomMarkerRef<'a>();
     |

error[E0392]: lifetime parameter `'a` is never used
 --> /tmp/icemaker_global_tempdir.PzPKVRlZ5j2C/rustc_testrunner_tmpdir_reporting.cycmjFyyopNr/mvce.rs:8:24
  |
8 | struct CustomMarkerRef<'a>();
  |                        ^^ unused lifetime parameter
  |
  = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

error: internal compiler error: /rustc-dev/a4330234a776684c36428d001721d0320d24dd77/compiler/rustc_borrowck/src/places_conflict.rs:530:14: mismatched projections in place_element_conflict: PhantomDeref and Field(0, std::marker::PhantomData<&'?6 ()>)


thread 'rustc' (3583970) panicked at /rustc-dev/a4330234a776684c36428d001721d0320d24dd77/compiler/rustc_borrowck/src/places_conflict.rs:530:14:
Box<dyn Any>
stack backtrace:
   0:     0x7f174c887576 - <<std[30cbc90d73eb2f7]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[37d23c544a63de81]::fmt::Display>::fmt
   1:     0x7f174ce1138f - core[37d23c544a63de81]::fmt::write
   2:     0x7f174c89c64c - <std[30cbc90d73eb2f7]::sys::stdio::unix::Stderr as core[37d23c544a63de81]::io::write::Write>::write_fmt
   3:     0x7f174c859e4a - std[30cbc90d73eb2f7]::panicking::default_hook::{closure#0}
   4:     0x7f174c87b8a3 - std[30cbc90d73eb2f7]::panicking::default_hook
   5:     0x7f174b7f1d8f - std[30cbc90d73eb2f7]::panicking::update_hook::<alloc[1ae459ecdd033a44]::boxed::Box<rustc_driver_impl[42633c3e3ce72fef]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f174c87bd42 - std[30cbc90d73eb2f7]::panicking::panic_with_hook
   7:     0x7f174b820324 - std[30cbc90d73eb2f7]::panicking::begin_panic::<rustc_errors[9274a714df388628]::ExplicitBug>::{closure#0}
   8:     0x7f174b8190d6 - std[30cbc90d73eb2f7]::sys::backtrace::__rust_end_short_backtrace::<std[30cbc90d73eb2f7]::panicking::begin_panic<rustc_errors[9274a714df388628]::ExplicitBug>::{closure#0}, !>
   9:     0x7f174b818e0b - std[30cbc90d73eb2f7]::panicking::begin_panic::<rustc_errors[9274a714df388628]::ExplicitBug>
  10:     0x7f174b82bd71 - <rustc_errors[9274a714df388628]::diagnostic::BugAbort as rustc_errors[9274a714df388628]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f174bdb8d59 - rustc_middle[a86b7b2986aebea0]::util::bug::opt_span_bug_fmt::<rustc_span[b1cb78db3bb7e75b]::span_encoding::Span>::{closure#0}
  12:     0x7f174bdb9152 - rustc_middle[a86b7b2986aebea0]::ty::context::tls::with_opt::<rustc_middle[a86b7b2986aebea0]::util::bug::opt_span_bug_fmt<rustc_span[b1cb78db3bb7e75b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f174bda3f70 - rustc_middle[a86b7b2986aebea0]::ty::context::tls::with_context_opt::<rustc_middle[a86b7b2986aebea0]::ty::context::tls::with_opt<rustc_middle[a86b7b2986aebea0]::util::bug::opt_span_bug_fmt<rustc_span[b1cb78db3bb7e75b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f1748a1e6f4 - rustc_middle[a86b7b2986aebea0]::util::bug::bug_fmt
  15:     0x7f174e0a0d77 - rustc_borrowck[1cacfe858ddd23c2]::borrowck_check_region_constraints
  16:     0x7f174e066b18 - <rustc_borrowck[1cacfe858ddd23c2]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  17:     0x7f174e065515 - rustc_borrowck[1cacfe858ddd23c2]::mir_borrowck
  18:     0x7f174e065219 - rustc_query_impl[97c88ea65335a4b0]::query_vtables::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7f174db7eaf5 - rustc_query_impl[97c88ea65335a4b0]::execution::try_execute_query::<rustc_data_structures[2f5d70850e22934]::vec_cache::VecCache<rustc_span[b1cb78db3bb7e75b]::def_id::LocalDefId, rustc_middle[a86b7b2986aebea0]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[a86b7b2986aebea0]::dep_graph::graph::DepNodeIndex>, false>
  20:     0x7f174db7e667 - rustc_query_impl[97c88ea65335a4b0]::query_vtables::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7f174db81223 - <rustc_middle[a86b7b2986aebea0]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[a3585332d3a3ff1e]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  22:     0x7f174db80580 - rustc_interface[a3585332d3a3ff1e]::passes::analysis
  23:     0x7f174e0051ca - rustc_query_impl[97c88ea65335a4b0]::execution::try_execute_query::<rustc_middle[a86b7b2986aebea0]::query::caches::SingleCache<rustc_middle[a86b7b2986aebea0]::query::erase::ErasedData<[u8; 0usize]>>, false>
  24:     0x7f174e004f6b - rustc_query_impl[97c88ea65335a4b0]::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f174e15a659 - rustc_interface[a3585332d3a3ff1e]::interface::run_compiler::<(), rustc_driver_impl[42633c3e3ce72fef]::run_compiler::{closure#0}>::{closure#2}
  26:     0x7f174e1ad7c2 - std[30cbc90d73eb2f7]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a3585332d3a3ff1e]::util::run_in_thread_with_globals<rustc_interface[a3585332d3a3ff1e]::util::run_in_thread_pool_with_globals<rustc_interface[a3585332d3a3ff1e]::interface::run_compiler<(), rustc_driver_impl[42633c3e3ce72fef]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27:     0x7f174e1ad56d - <std[30cbc90d73eb2f7]::thread::lifecycle::spawn_unchecked<rustc_interface[a3585332d3a3ff1e]::util::run_in_thread_with_globals<rustc_interface[a3585332d3a3ff1e]::util::run_in_thread_pool_with_globals<rustc_interface[a3585332d3a3ff1e]::interface::run_compiler<(), rustc_driver_impl[42633c3e3ce72fef]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[37d23c544a63de81]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7f174e1b5ec7 - <std[30cbc90d73eb2f7]::sys::thread::unix::Thread>::new::thread_start
  29:     0x7f17474980a2 - <unknown>
  30:     0x7f174752080c - <unknown>
  31:                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.100.0-nightly (a4330234a 2026-09-01) 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 3 previous errors

Some errors have detailed explanations: E0277, E0392.
For more information about an error, try `rustc --explain E0277`.

@rustbot label +F-reborrow

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 by compiling the reduced a.rs reproducer with rustc and inspect compiler/rustc_borrowck/src/places_conflict.rs around lines 524-536, where the mismatched projections ICE is reported. Trace the borrow-checking path for PhantomDeref and Field projections; done means the reproducer no longer panics while producing appropriate compiler diagnostics.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.