Skip to content

[ICE]: hir-typeck passed but Reborrow does not have a lifetime argument #156308

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

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

struct CustomMarker<'a>(PhantomData<&'a ()>);
impl<'a> Reborrow for PhantomData<'a> {}

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

original:

//@ run-pass

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

struct CustomMarker<'a>(PhantomData<&'a ()>);
impl<'a> Reborrow for PhantomData<'a> {}

impl<'a> std::ops::Deref for CustomMarker<'a> {
    type Target = CustomMarker<'a>;
    fn deref(&self) -> &Self::Target {
        self
    }
}

impl<'a> std::ops::DerefMut for CustomMarker<'a> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        self
    }
}

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

    *a = CustomMarker(PhantomData);
}

Version information

rustc 1.97.0-nightly (3e353d735 2026-05-08)
binary: rustc
commit-hash: 3e353d7353b0cd6fa4eefd5c882457cc2708184c
commit-date: 2026-05-08
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Possibly related line of code:

let &ty::Adt(reborrowed_adt, _reborrowed_args) = borrowed_place_ty.kind() else {
unreachable!()
};
let &ty::Adt(target_adt, assigned_args) = target.kind() else { unreachable!() };
let Some(ty::GenericArgKind::Lifetime(region)) = assigned_args.get(0).map(|r| r.kind())
else {
bug!(
"hir-typeck passed but {} does not have a lifetime argument",
if mutability == Mutability::Mut { "Reborrow" } else { "CoerceShared" }
);
};
let region = region.as_var();
let kind = if mutability == Mutability::Mut {

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

Program output

error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied
   --> /tmp/icemaker_global_tempdir.HFhzK8XG8tRD/rustc_testrunner_tmpdir_reporting.ZH8KibTRlyKp/mvce.rs:5:23
    |
  5 | impl<'a> Reborrow for PhantomData<'a> {}
    |                       ^^^^^^^^^^^---- help: remove the unnecessary generics
    |                       |
    |                       expected 0 lifetime arguments
    |
note: struct defined here, with 0 lifetime parameters
   --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/marker.rs:811:12
    |
811 | pub struct PhantomData<T: PointeeSized>;
    |            ^^^^^^^^^^^

error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
   --> /tmp/icemaker_global_tempdir.HFhzK8XG8tRD/rustc_testrunner_tmpdir_reporting.ZH8KibTRlyKp/mvce.rs:5:23
    |
  5 | impl<'a> Reborrow for PhantomData<'a> {}
    |                       ^^^^^^^^^^^ expected 1 generic argument
    |
note: struct defined here, with 1 generic parameter: `T`
   --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/marker.rs:811:12
    |
811 | pub struct PhantomData<T: PointeeSized>;
    |            ^^^^^^^^^^^ -
help: add missing generic argument
    |
  5 | impl<'a> Reborrow for PhantomData<'a, T> {}
    |                                     +++

error: implementing `Reborrow` does not allow multiple lifetimes or fields to be coerced
 --> /tmp/icemaker_global_tempdir.HFhzK8XG8tRD/rustc_testrunner_tmpdir_reporting.ZH8KibTRlyKp/mvce.rs:5:1
  |
5 | impl<'a> Reborrow for PhantomData<'a> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: /rustc-dev/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_borrowck/src/borrow_set.rs:313:17: hir-typeck passed but Reborrow does not have a lifetime argument


thread 'rustc' (4044579) panicked at /rustc-dev/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_borrowck/src/borrow_set.rs:313:17:
Box<dyn Any>
stack backtrace:
   0:     0x7fba3d874239 - <<std[db65628f2330fd11]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[b3c617e8375f9bd0]::fmt::Display>::fmt
   1:     0x7fba3de1b788 - core[b3c617e8375f9bd0]::fmt::write
   2:     0x7fba3d88ac66 - <std[db65628f2330fd11]::sys::stdio::unix::Stderr as std[db65628f2330fd11]::io::Write>::write_fmt
   3:     0x7fba3d84a2de - std[db65628f2330fd11]::panicking::default_hook::{closure#0}
   4:     0x7fba3d8678f3 - std[db65628f2330fd11]::panicking::default_hook
   5:     0x7fba3c7544d1 - std[db65628f2330fd11]::panicking::update_hook::<alloc[b10a1c065189447]::boxed::Box<rustc_driver_impl[1f444ccaa450aabc]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fba3d867bd2 - std[db65628f2330fd11]::panicking::panic_with_hook
   7:     0x7fba3c781f51 - std[db65628f2330fd11]::panicking::begin_panic::<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>::{closure#0}
   8:     0x7fba3c77af46 - std[db65628f2330fd11]::sys::backtrace::__rust_end_short_backtrace::<std[db65628f2330fd11]::panicking::begin_panic<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>::{closure#0}, !>
   9:     0x7fba3c77acab - std[db65628f2330fd11]::panicking::begin_panic::<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>
  10:     0x7fba3c78d431 - <rustc_errors[4e25407aa9dfcb98]::diagnostic::BugAbort as rustc_errors[4e25407aa9dfcb98]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fba3cd9cf69 - rustc_middle[4a2cff3451d2bad5]::util::bug::opt_span_bug_fmt::<rustc_span[749aae40fdac821d]::span_encoding::Span>::{closure#0}
  12:     0x7fba3cd9d0d2 - rustc_middle[4a2cff3451d2bad5]::ty::context::tls::with_opt::<rustc_middle[4a2cff3451d2bad5]::util::bug::opt_span_bug_fmt<rustc_span[749aae40fdac821d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7fba3cd8b82b - rustc_middle[4a2cff3451d2bad5]::ty::context::tls::with_context_opt::<rustc_middle[4a2cff3451d2bad5]::ty::context::tls::with_opt<rustc_middle[4a2cff3451d2bad5]::util::bug::opt_span_bug_fmt<rustc_span[749aae40fdac821d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7fba3a731134 - rustc_middle[4a2cff3451d2bad5]::util::bug::bug_fmt
  15:     0x7fba3b287486 - <rustc_borrowck[543291a75b63dc2a]::borrow_set::BorrowSet>::build
  16:     0x7fba3e8d6e5b - <rustc_borrowck[543291a75b63dc2a]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  17:     0x7fba3e8d2b1b - rustc_borrowck[543291a75b63dc2a]::mir_borrowck
  18:     0x7fba3e8d28e9 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7fba3df6d6a6 - rustc_query_impl[3b9ecabc2cca1a8f]::execution::try_execute_query::<rustc_data_structures[4a3bb46d707d6722]::vec_cache::VecCache<rustc_span[749aae40fdac821d]::def_id::LocalDefId, rustc_middle[4a2cff3451d2bad5]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[4a2cff3451d2bad5]::dep_graph::graph::DepNodeIndex>, false>
  20:     0x7fba3df6fdc3 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7fba3df6ff94 - <rustc_middle[4a2cff3451d2bad5]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[232b63f46aa35c0e]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  22:     0x7fba3df6f276 - rustc_interface[232b63f46aa35c0e]::passes::analysis
  23:     0x7fba3ef822c9 - rustc_query_impl[3b9ecabc2cca1a8f]::execution::try_execute_query::<rustc_middle[4a2cff3451d2bad5]::query::caches::SingleCache<rustc_middle[4a2cff3451d2bad5]::query::erase::ErasedData<[u8; 0usize]>>, false>
  24:     0x7fba3ef81f33 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7fba3efc765b - rustc_interface[232b63f46aa35c0e]::interface::run_compiler::<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}
  26:     0x7fba3ef75c3e - std[db65628f2330fd11]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_with_globals<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_pool_with_globals<rustc_interface[232b63f46aa35c0e]::interface::run_compiler<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27:     0x7fba3ef7632d - <std[db65628f2330fd11]::thread::lifecycle::spawn_unchecked<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_with_globals<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_pool_with_globals<rustc_interface[232b63f46aa35c0e]::interface::run_compiler<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[b3c617e8375f9bd0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7fba3ef7712c - <std[db65628f2330fd11]::sys::thread::unix::Thread>::new::thread_start
  29:     0x7fba38aa597a - <unknown>
  30:     0x7fba38b292bc - <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.97.0-nightly (3e353d735 2026-05-08) 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 4 previous errors

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

@rustbot label +F-reborrow

Activity

  1. added
    I-ICE
    T-compiler
    C-bug
    on May 8, 2026
  2. added
    needs-triage
    F-reborrow
    on May 8, 2026
  3. matthiaskrgr commented on May 8, 2026

    @matthiaskrgr
    MemberAuthor

    smaller

    #![feature(reborrow)]
    use std::marker::{PhantomData, Reborrow};
    struct CustomMarker<'a>(PhantomData<&'a ()>);
    impl<T> Reborrow for PhantomData<T> {}
    fn main() {
        CustomMarker(PhantomData);
    }
  4. theemathas commented on May 8, 2026

    @theemathas
    Contributor

    Related to #156307. cc @aapoalas

  5. matthiaskrgr commented on May 8, 2026

    @matthiaskrgr
    MemberAuthor

    ah lol 😆

  6. matthiaskrgr commented on May 8, 2026

    @matthiaskrgr
    MemberAuthor

    to hit the CoerceShared branch:

    #![feature(reborrow)]
    use std::marker::{CoerceShared, PhantomData};
    struct CustomMarker<'a>(PhantomData<&'a ()>);
    struct CustomMarkerRef;
    impl<'a> CoerceShared<CustomMarkerRef> for CustomMarker<'a> {}
    fn method<'a>(_a: CustomMarkerRef) -> &'a () {}
    fn main() {
        let a = CustomMarker(PhantomData);
        method(a);
    }
  7. removed
    needs-triage
    on Oct 7, 2026
  8. added a commit that references this issue on Oct 25, 2026
    5638085
  9. added a commit that references this issue on Oct 25, 2026
    7a7d053
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugF-reborrowI-ICET-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions