Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling FnMut on immutable reference causes: internal compiler error: impossible case reached #82660

Closed
JakkuSakura opened this issue Mar 1, 2021 · 1 comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@JakkuSakura
Copy link

Code

Change &self.snapshot to &mut self.snapshot would make it work.

struct SnapshotMetadata {
    builder: Box<dyn FnMut() -> String>,
}

pub struct SnapshotCollector {
    snapshot: Vec<SnapshotMetadata>,
}

impl SnapshotCollector {
    pub fn collect_snapshots(&mut self) {
        for meta in &self.snapshot {
            (meta.builder)();
        }
    }
}

fn main() {
    println!("Hello, world!");
}

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (e9920ef77 2021-02-11)
binary: rustc
commit-hash: e9920ef7749d11fc71cc32ca4ba055bcfeaab945
commit-date: 2021-02-11
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Error output

/usr/bin/cargo build --color=always --message-format=json-diagnostic-rendered-ansi --package rust_test --bin rust_test
   Compiling rust_test v0.1.0 (/home/jack/Dev/rust_test)
error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:306:18: impossible case reached

thread 'rustc' panicked at 'Box<Any>', /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_middle::hir::map::Map::item
   8: rustc_mir::borrow_check::diagnostics::mutability_errors::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::report_mutability_error
   9: rustc_mir::borrow_check::MirBorrowckCtxt::access_place
  10: <rustc_mir::borrow_check::MirBorrowckCtxt as rustc_mir::dataflow::framework::visitor::ResultsVisitor>::visit_statement_before_primary_effect
  11: <rustc_mir::dataflow::framework::direction::Forward as rustc_mir::dataflow::framework::direction::Direction>::visit_results_in_block
  12: rustc_mir::dataflow::framework::visitor::visit_results
  13: rustc_mir::borrow_check::do_mir_borrowck
  14: rustc_infer::infer::InferCtxtBuilder::enter
  15: rustc_mir::borrow_check::mir_borrowck
  16: 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
  17: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  19: rustc_data_structures::stack::ensure_sufficient_stack
  20: rustc_query_system::query::plumbing::force_query_with_job
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_query_system::query::plumbing::ensure_query_impl
  23: rustc_interface::passes::analysis
  24: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  25: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_data_structures::stack::ensure_sufficient_stack
  28: rustc_query_system::query::plumbing::force_query_with_job
  29: rustc_query_system::query::plumbing::get_query_impl
  30: rustc_interface::passes::QueryContext::enter
  31: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  32: rustc_span::with_source_map
  33: rustc_interface::interface::create_compiler_and_run
  34: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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 (e9920ef77 2021-02-11) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [mir_borrowck] borrow-checking `SnapshotCollector::collect_snapshots`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `rust_test`
To learn more, run the command again with --verbose.
Process finished with 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/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/panic.rs:59:5
stack backtrace:
   0:     0x7f45775a3fa0 - std::backtrace_rs::backtrace::libunwind::trace::hb4de9797f80b7b8c
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f45775a3fa0 - std::backtrace_rs::backtrace::trace_unsynchronized::h59566d0bd20efff7
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f45775a3fa0 - std::sys_common::backtrace::_print_fmt::hcfa5ce6be50275d4
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f45775a3fa0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd8c307a38b9bab04
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f4577614ebc - core::fmt::write::h3868db8542c90941
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/core/src/fmt/mod.rs:1096:17
   5:     0x7f4577596ea2 - std::io::Write::write_fmt::hab90295d5a0f197d
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/io/mod.rs:1568:15
   6:     0x7f45775a7e85 - std::sys_common::backtrace::_print::h19224910b8700cf1
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f45775a7e85 - std::sys_common::backtrace::print::h25dedfa68c5fb84a
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f45775a7e85 - std::panicking::default_hook::{{closure}}::h12c5765653a72a42
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/panicking.rs:208:50
   9:     0x7f45775a79e3 - std::panicking::default_hook::he65cee71c4209f0c
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/panicking.rs:225:9
  10:     0x7f4577e09d6b - rustc_driver::report_ice::h9bfcf5769c15fbf2
  11:     0x7f45775a8786 - std::panicking::rust_panic_with_hook::h01a674d863fe0d8a
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/panicking.rs:595:17
  12:     0x7f45795f318e - std::panicking::begin_panic::{{closure}}::h04d9d59beaf7438f
  13:     0x7f45795f2ff9 - std::sys_common::backtrace::__rust_end_short_backtrace::h91912ecacddbde4e
  14:     0x7f45795f3132 - std::panicking::begin_panic::h3001af3848957078
  15:     0x7f45795d4ed0 - std::panic::panic_any::h4f4426de976e6adf
  16:     0x7f45795d82da - rustc_errors::HandlerInner::bug::hdf11185f92e2a22a
  17:     0x7f45795d7db3 - rustc_errors::Handler::bug::h2dfda4f443e5c9b7
  18:     0x7f45792df51a - rustc_middle::ty::context::tls::with_opt::h931a04da690f236d
  19:     0x7f457abf0e00 - rustc_middle::util::bug::opt_span_bug_fmt::h550b33bd70d0f311
  20:     0x7f45792e1d86 - rustc_middle::util::bug::bug_fmt::h36f36510cd9d6fb0
  21:     0x7f457a059ef3 - rustc_middle::hir::map::Map::item::h38779ea831b29407
  22:     0x7f457895fdb5 - rustc_mir::borrow_check::diagnostics::mutability_errors::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::report_mutability_error::h9f31953fdeab2a41
  23:     0x7f4579cb4de7 - rustc_mir::borrow_check::MirBorrowckCtxt::access_place::h7d6f5b9d65ba8ac9
  24:     0x7f4579cb2735 - <rustc_mir::borrow_check::MirBorrowckCtxt as rustc_mir::dataflow::framework::visitor::ResultsVisitor>::visit_statement_before_primary_effect::hfed3a82644adb2d8
  25:     0x7f4579bce408 - <rustc_mir::dataflow::framework::direction::Forward as rustc_mir::dataflow::framework::direction::Direction>::visit_results_in_block::hadc8c1a5509312c0
  26:     0x7f4579b5fcd7 - rustc_mir::dataflow::framework::visitor::visit_results::hc22c9f4ceef08c61
  27:     0x7f4579cae17a - rustc_mir::borrow_check::do_mir_borrowck::h3413661263ce29f4
  28:     0x7f4579ba9cb3 - rustc_infer::infer::InferCtxtBuilder::enter::hb74fd86320ea36f1
  29:     0x7f4579cacf57 - rustc_mir::borrow_check::mir_borrowck::h57947c7876ea879f
  30:     0x7f4579740bac - 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
  31:     0x7f457a18bfb7 - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::h2b9a3e2453557291
  32:     0x7f45797384d9 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::h90db12b228ddedb6
  33:     0x7f4579735661 - rustc_data_structures::stack::ensure_sufficient_stack::h22af48d26d15ef1a
  34:     0x7f4579745b81 - rustc_query_system::query::plumbing::force_query_with_job::h5fa612051f70510d
  35:     0x7f45797432f8 - rustc_query_system::query::plumbing::get_query_impl::h6055f87cc26b791b
  36:     0x7f4579745997 - rustc_query_system::query::plumbing::ensure_query_impl::he177fc338b1f472c
  37:     0x7f4579757932 - rustc_interface::passes::analysis::heddb9cef62da4ab1
  38:     0x7f457a133d89 - 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
  39:     0x7f4577db689f - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::he189719f47fb03a4
  40:     0x7f457a145854 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::h90cdb9d4b5390542
  41:     0x7f457a152835 - rustc_data_structures::stack::ensure_sufficient_stack::hc03964f1cadb8cd3
  42:     0x7f457a134ab1 - rustc_query_system::query::plumbing::force_query_with_job::h085fb2f93a800461
  43:     0x7f457a1340c1 - rustc_query_system::query::plumbing::get_query_impl::hc18a830d288c39e4
  44:     0x7f457a14c92a - rustc_interface::passes::QueryContext::enter::hf896adfd99e9040f
  45:     0x7f457a112c34 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h2ac7000621882a7f
  46:     0x7f457a14bf94 - rustc_span::with_source_map::h9c33ff8439fe9783
  47:     0x7f457a113d97 - rustc_interface::interface::create_compiler_and_run::h39c6799ffe196408
  48:     0x7f457a1525b8 - scoped_tls::ScopedKey<T>::set::h0eb8893a0191dbc1
  49:     0x7f457a152aa8 - std::sys_common::backtrace::__rust_begin_short_backtrace::hccc56e59b0e3233c
  50:     0x7f457a1339ba - core::ops::function::FnOnce::call_once{{vtable.shim}}::h09f6484b7e2514ef
  51:     0x7f45775b8daa - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h321523073ee11258
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/alloc/src/boxed.rs:1548:9
  52:     0x7f45775b8daa - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf0e85e12c83b99b3
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/alloc/src/boxed.rs:1548:9
  53:     0x7f45775b8daa - std::sys::unix::thread::Thread::new::thread_start::hba22c7961aa0e2f8
                               at /rustc/e9920ef7749d11fc71cc32ca4ba055bcfeaab945/library/std/src/sys/unix/thread.rs:71:17
  54:     0x7f45774bb299 - start_thread
  55:     0x7f45773d0153 - clone
  56:                0x0 - <unknown>

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 (e9920ef77 2021-02-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `SnapshotCollector::collect_snapshots`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `rust_test`

@JakkuSakura JakkuSakura added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 1, 2021
@JohnTitor
Copy link
Member

Duplicate of #82032, this should be fixed on the latest nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants