Closed
Description
I tried to minimize the code as much as possible. Basically in this code, we are trying to write using an immutable reference.
For some reason, it panics instead of pointing out the problem.
I created a repository with a proof of concept. If you need more info I'm happy to help.
Code
struct Field (usize);
struct Crasherini {
field: Field,
}
impl Crasherini {
pub fn write_to_immut_ref(&mut self){
for value in vec![&self.field] {
value.0 = 10;
}
}
}
Meta
rustc --version --verbose
:
rustc 1.52.0-nightly (5fa22fe6f 2021-02-14)
binary: rustc
commit-hash: 5fa22fe6f821ac3801d05f624b123dda25fde32c
commit-date: 2021-02-14
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
Error output
Compiling rustc_crash v0.1.0 (/Workspace/Github/rustc_crash)
Running `rustc --crate-name rustc_crash --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=3d2379ed6d914a3d -C extra-filename=-3d2379ed6d914a3d --out-dir /Workspace/Github/rustc_crash/target/debug/deps -C incremental=/Workspace/Github/rustc_crash/target/debug/incremental -L dependency=/Workspace/Github/rustc_crash/target/debug/deps`
error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:306:18: impossible case reached
thread 'rustc' panicked at 'Box<Any>', /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: 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: rustc 1.52.0-nightly (5fa22fe6f 2021-02-14) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [mir_borrowck] borrow-checking `Crasherini::write_to_immut_ref`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
error: could not compile `rustc_crash`
Caused by:
process didn't exit successfully: `rustc --crate-name rustc_crash --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=3d2379ed6d914a3d -C extra-filename=-3d2379ed6d914a3d --out-dir /Workspace/Github/rustc_crash/target/debug/deps -C incremental=/Workspace/Github/rustc_crash/target/debug/incremental -L dependency=/Workspace/Github/rustc_crash/target/debug/deps` (exit code: 101)
Backtrace
error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:306:18: impossible case reached
thread 'rustc' panicked at 'Box<Any>', /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panic.rs:59:5
stack backtrace:
0: 0x7fe5a101da90 - std::backtrace_rs::backtrace::libunwind::trace::hb4de9797f80b7b8c
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
1: 0x7fe5a101da90 - std::backtrace_rs::backtrace::trace_unsynchronized::h59566d0bd20efff7
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7fe5a101da90 - std::sys_common::backtrace::_print_fmt::hcfa5ce6be50275d4
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/sys_common/backtrace.rs:67:5
3: 0x7fe5a101da90 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd8c307a38b9bab04
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/sys_common/backtrace.rs:46:22
4: 0x7fe5a108ef5c - core::fmt::write::h3868db8542c90941
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/core/src/fmt/mod.rs:1096:17
5: 0x7fe5a10109c2 - std::io::Write::write_fmt::hab90295d5a0f197d
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/io/mod.rs:1568:15
6: 0x7fe5a1021985 - std::sys_common::backtrace::_print::h19224910b8700cf1
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/sys_common/backtrace.rs:49:5
7: 0x7fe5a1021985 - std::sys_common::backtrace::print::h25dedfa68c5fb84a
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/sys_common/backtrace.rs:36:9
8: 0x7fe5a1021985 - std::panicking::default_hook::{{closure}}::h12c5765653a72a42
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panicking.rs:208:50
9: 0x7fe5a1021433 - std::panicking::default_hook::he65cee71c4209f0c
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panicking.rs:225:9
10: 0x7fe5a187d14b - rustc_driver::report_ice::h9bfcf5769c15fbf2
11: 0x7fe5a1022286 - std::panicking::rust_panic_with_hook::h01a674d863fe0d8a
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panicking.rs:595:17
12: 0x7fe5a3050fde - std::panicking::begin_panic::{{closure}}::h04d9d59beaf7438f
13: 0x7fe5a3050d19 - std::sys_common::backtrace::__rust_end_short_backtrace::h91912ecacddbde4e
14: 0x7fe5a3050f82 - std::panicking::begin_panic::h3001af3848957078
15: 0x7fe5a3043730 - std::panic::panic_any::h4f4426de976e6adf
16: 0x7fe5a3046b3a - rustc_errors::HandlerInner::bug::hdf11185f92e2a22a
17: 0x7fe5a3046613 - rustc_errors::Handler::bug::h2dfda4f443e5c9b7
18: 0x7fe5a2d464ca - rustc_middle::ty::context::tls::with_opt::h931a04da690f236d
19: 0x7fe5a4666430 - rustc_middle::util::bug::opt_span_bug_fmt::h550b33bd70d0f311
20: 0x7fe5a2d48946 - rustc_middle::util::bug::bug_fmt::h36f36510cd9d6fb0
21: 0x7fe5a3ac4e53 - rustc_middle::hir::map::Map::item::h38779ea831b29407
22: 0x7fe5a23c4fc5 - rustc_mir::borrow_check::diagnostics::mutability_errors::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::report_mutability_error::h9f31953fdeab2a41
23: 0x7fe5a371e777 - rustc_mir::borrow_check::MirBorrowckCtxt::access_place::h7d6f5b9d65ba8ac9
24: 0x7fe5a371ecc9 - rustc_mir::borrow_check::MirBorrowckCtxt::mutate_place::hea6a7404e13ec6bc
25: 0x7fe5a371c03e - <rustc_mir::borrow_check::MirBorrowckCtxt as rustc_mir::dataflow::framework::visitor::ResultsVisitor>::visit_statement_before_primary_effect::hfed3a82644adb2d8
26: 0x7fe5a36386ea - <rustc_mir::dataflow::framework::direction::Forward as rustc_mir::dataflow::framework::direction::Direction>::visit_results_in_block::hadc8c1a5509312c0
27: 0x7fe5a35c28e7 - rustc_mir::dataflow::framework::visitor::visit_results::hc22c9f4ceef08c61
28: 0x7fe5a3717aca - rustc_mir::borrow_check::do_mir_borrowck::h3413661263ce29f4
29: 0x7fe5a3610053 - rustc_infer::infer::InferCtxtBuilder::enter::hb74fd86320ea36f1
30: 0x7fe5a37168a7 - rustc_mir::borrow_check::mir_borrowck::h57947c7876ea879f
31: 0x7fe5a31ae87c - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute::h626f7b9e9b78ef2d
32: 0x7fe5a3c007c7 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::h2b9a3e2453557291
33: 0x7fe5a31a3d99 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::h90db12b228ddedb6
34: 0x7fe5a31c2f95 - rustc_data_structures::stack::ensure_sufficient_stack::h22af48d26d15ef1a
35: 0x7fe5a31b3851 - rustc_query_system::query::plumbing::force_query_with_job::h5fa612051f70510d
36: 0x7fe5a31b0fc8 - rustc_query_system::query::plumbing::get_query_impl::h6055f87cc26b791b
37: 0x7fe5a31b3667 - rustc_query_system::query::plumbing::ensure_query_impl::he177fc338b1f472c
38: 0x7fe5a31b52b9 - rustc_session::utils::<impl rustc_session::session::Session>::time::h6c2f1e639f350429
39: 0x7fe5a3c134dd - rustc_interface::passes::analysis::heddb9cef62da4ab1
40: 0x7fe5a3b90a49 - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute::hc584fab50c0e9742
41: 0x7fe5a183971a - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::he189719f47fb03a4
42: 0x7fe5a3ba2ee4 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::h90cdb9d4b5390542
43: 0x7fe5a3bb1d85 - rustc_data_structures::stack::ensure_sufficient_stack::hc03964f1cadb8cd3
44: 0x7fe5a3b91771 - rustc_query_system::query::plumbing::force_query_with_job::h085fb2f93a800461
45: 0x7fe5a3b90d81 - rustc_query_system::query::plumbing::get_query_impl::hc18a830d288c39e4
46: 0x7fe5a3baa02a - rustc_interface::passes::QueryContext::enter::hf896adfd99e9040f
47: 0x7fe5a3bb0e14 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h2ac7000621882a7f
48: 0x7fe5a3ba9911 - rustc_span::with_source_map::h9c33ff8439fe9783
49: 0x7fe5a3bb05e3 - scoped_tls::ScopedKey<T>::set::h0eb8893a0191dbc1
50: 0x7fe5a3bb1ff8 - std::sys_common::backtrace::__rust_begin_short_backtrace::hccc56e59b0e3233c
51: 0x7fe5a3b9071a - core::ops::function::FnOnce::call_once{{vtable.shim}}::h09f6484b7e2514ef
52: 0x7fe5a1032fda - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h321523073ee11258
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/alloc/src/boxed.rs:1546:9
53: 0x7fe5a1032fda - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf0e85e12c83b99b3
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/alloc/src/boxed.rs:1546:9
54: 0x7fe5a1032fda - std::sys::unix::thread::Thread::new::thread_start::hba22c7961aa0e2f8
at /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/sys/unix/thread.rs:71:17
55: 0x7fe5a0f3b3e9 - start_thread
56: 0x7fe5a0e58293 - __GI___clone
57: 0x0 - <unknown>