[ICE]: `Cannot implement Reborrow on a type containing a &'static mut T field`
Nobody has claimed this yet.
- 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, Reborrow};
struct ReorderMut<'a> {
a: &'static mut u8,
b: &'a mut u16,
}
struct ReorderRef<'a> {
,
,
}
impl<'a> CoerceShared<> for ReorderMut<'a> {}
//~^ ERROR
fn read(value: ReorderRef<'_>) -> (u16, u8) {
}
fn main() {
let mut a = 1;
let mut b = 2;
let wrapped = ReorderMut { a: &mut a, b: &mut b };
assert_eq!(read(wrapped), (2, 1));
}
original:
#![feature(reborrow)]
#![allow(dead_code)]
use std::marker::{CoerceShared, Reborrow};
struct ReorderMut<'a> {
a: &'static mut u8,
b: &'a mut u16,
}
impl<'a> Reborrow for ReorderMut<'a> {}
#[derive(Clone, Copy)]
struct ReorderRef<'a> {
b: &'a u16,
a: &'a u8,
}
impl<'a> CoerceShared<ReorderRef<'a>> for ReorderMut<'a> {}
//~^ ERROR
fn read(value: ReorderRef<'_>) -> (u16, u8) {
(*value.b, *value.a)
}
fn main() {
let mut a = 1;
let mut b = 2;
let wrapped = ReorderMut { a: &mut a, b: &mut b };
assert_eq!(read(wrapped), (2, 1));
}
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/borrow_set.rs#L304-L316
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc
Program output
error: expected identifier, found `,`
--> /tmp/icemaker_global_tempdir.oxCtheU3rtFf/rustc_testrunner_tmpdir_reporting.qRBWn5QyOL8e/mvce.rs:15:5
|
14 | struct ReorderRef<'a> {
| ---------- while parsing this struct
15 | ,
| ^ expected identifier
warning: unused import: `Reborrow`
--> /tmp/icemaker_global_tempdir.oxCtheU3rtFf/rustc_testrunner_tmpdir_reporting.qRBWn5QyOL8e/mvce.rs:4:33
|
4 | use std::marker::{CoerceShared, Reborrow};
| ^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
--> /tmp/icemaker_global_tempdir.oxCtheU3rtFf/rustc_testrunner_tmpdir_reporting.qRBWn5QyOL8e/mvce.rs:19:10
|
19 | impl<'a> CoerceShared<> for ReorderMut<'a> {}
| ^^^^^^^^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `Target`
--> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/marker.rs:1369:11
|
1369 | pub trait CoerceShared<Target: Copy>: Reborrow {
| ^^^^^^^^^^^^ ------
help: add missing generic argument
|
19 | impl<'a> CoerceShared<Target> for ReorderMut<'a> {}
| ++++++
error[E0377]: the trait `CoerceShared` may only be implemented for a coercion between structures
--> /tmp/icemaker_global_tempdir.oxCtheU3rtFf/rustc_testrunner_tmpdir_reporting.qRBWn5QyOL8e/mvce.rs:19:1
|
19 | impl<'a> CoerceShared<> for ReorderMut<'a> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> /tmp/icemaker_global_tempdir.oxCtheU3rtFf/rustc_testrunner_tmpdir_reporting.qRBWn5QyOL8e/mvce.rs:22:35
|
22 | fn read(value: ReorderRef<'_>) -> (u16, u8) {
| ---- ^^^^^^^^^ expected `(u16, u8)`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected tuple `(u16, u8)`
found unit type `()`
error: internal compiler error: /rustc-dev/a4330234a776684c36428d001721d0320d24dd77/compiler/rustc_borrowck/src/borrow_set.rs:310:25: Cannot implement Reborrow on a type containing a &'static mut T field
thread 'rustc' (2938508) panicked at /rustc-dev/a4330234a776684c36428d001721d0320d24dd77/compiler/rustc_borrowck/src/borrow_set.rs:310:25:
Box<dyn Any>
stack backtrace:
0: 0x7fbbfd287576 - <<std[30cbc90d73eb2f7]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[37d23c544a63de81]::fmt::Display>::fmt
1: 0x7fbbfd81138f - core[37d23c544a63de81]::fmt::write
2: 0x7fbbfd29c64c - <std[30cbc90d73eb2f7]::sys::stdio::unix::Stderr as core[37d23c544a63de81]::io::write::Write>::write_fmt
3: 0x7fbbfd259e4a - std[30cbc90d73eb2f7]::panicking::default_hook::{closure#0}
4: 0x7fbbfd27b8a3 - std[30cbc90d73eb2f7]::panicking::default_hook
5: 0x7fbbfc1f1d8f - std[30cbc90d73eb2f7]::panicking::update_hook::<alloc[1ae459ecdd033a44]::boxed::Box<rustc_driver_impl[42633c3e3ce72fef]::install_ice_hook::{closure#1}>>::{closure#0}
6: 0x7fbbfd27bd42 - std[30cbc90d73eb2f7]::panicking::panic_with_hook
7: 0x7fbbfc220324 - std[30cbc90d73eb2f7]::panicking::begin_panic::<rustc_errors[9274a714df388628]::ExplicitBug>::{closure#0}
8: 0x7fbbfc2190d6 - std[30cbc90d73eb2f7]::sys::backtrace::__rust_end_short_backtrace::<std[30cbc90d73eb2f7]::panicking::begin_panic<rustc_errors[9274a714df388628]::ExplicitBug>::{closure#0}, !>
9: 0x7fbbfc218e0b - std[30cbc90d73eb2f7]::panicking::begin_panic::<rustc_errors[9274a714df388628]::ExplicitBug>
10: 0x7fbbfc22bd71 - <rustc_errors[9274a714df388628]::diagnostic::BugAbort as rustc_errors[9274a714df388628]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
11: 0x7fbbfc7b8d59 - rustc_middle[a86b7b2986aebea0]::util::bug::opt_span_bug_fmt::<rustc_span[b1cb78db3bb7e75b]::span_encoding::Span>::{closure#0}
12: 0x7fbbfc7b9152 - 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: 0x7fbbfc7a3f70 - 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: 0x7fbbf941e6f4 - rustc_middle[a86b7b2986aebea0]::util::bug::bug_fmt
15: 0x7fbbfbeff308 - <rustc_borrowck[1cacfe858ddd23c2]::borrow_set::GatherBorrows>::gather_reborrows
16: 0x7fbbf9d36c94 - <rustc_borrowck[1cacfe858ddd23c2]::borrow_set::BorrowSet>::build
17: 0x7fbbfea5522b - rustc_borrowck[1cacfe858ddd23c2]::borrowck_collect_region_constraints
18: 0x7fbbfea665f2 - <rustc_borrowck[1cacfe858ddd23c2]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
19: 0x7fbbfea65515 - rustc_borrowck[1cacfe858ddd23c2]::mir_borrowck
20: 0x7fbbfea65219 - rustc_query_impl[97c88ea65335a4b0]::query_vtables::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
21: 0x7fbbfe57eaf5 - 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>
22: 0x7fbbfe57e667 - rustc_query_impl[97c88ea65335a4b0]::query_vtables::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
23: 0x7fbbfe581223 - <rustc_middle[a86b7b2986aebea0]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[a3585332d3a3ff1e]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
24: 0x7fbbfe580580 - rustc_interface[a3585332d3a3ff1e]::passes::analysis
25: 0x7fbbfea051ca - rustc_query_impl[97c88ea65335a4b0]::execution::try_execute_query::<rustc_middle[a86b7b2986aebea0]::query::caches::SingleCache<rustc_middle[a86b7b2986aebea0]::query::erase::ErasedData<[u8; 0usize]>>, false>
26: 0x7fbbfea04f6b - rustc_query_impl[97c88ea65335a4b0]::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
27: 0x7fbbfeb5a659 - rustc_interface[a3585332d3a3ff1e]::interface::run_compiler::<(), rustc_driver_impl[42633c3e3ce72fef]::run_compiler::{closure#0}>::{closure#2}
28: 0x7fbbfebad7c2 - 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}, ()>
29: 0x7fbbfebad56d - <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}
30: 0x7fbbfebb5ec7 - <std[30cbc90d73eb2f7]::sys::thread::unix::Thread>::new::thread_start
31: 0x7fbbf7e980a2 - <unknown>
32: 0x7fbbf7f2080c - <unknown>
33: 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 5 previous errors; 1 warning emitted
Some errors have detailed explanations: E0107, E0308, E0377.
For more information about an error, try `rustc --explain E0107`.
@rustbot label +F-reborrow
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reduced and original reproducers in a.rs, then inspect compiler/rustc_borrowck/src/borrow_set.rs around lines 304-316 and the gather_reborrows call shown in the backtrace. Run the reproducer with the specified nightly; done means the valid Reborrow/CoerceShared case no longer triggers an internal compiler error and still reports the intended 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
- 52/100