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

borrow-checking panic when mutating unwrapped immutable reference #92015

Closed
aaronjanse opened this issue Dec 17, 2021 · 4 comments · Fixed by #92389
Closed

borrow-checking panic when mutating unwrapped immutable reference #92015

aaronjanse opened this issue Dec 17, 2021 · 4 comments · Fixed by #92389
Assignees
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@aaronjanse
Copy link

aaronjanse commented Dec 17, 2021

Code

fn main() {
    let foo = Some(&0).unwrap();
    *foo = 1;
}

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (65c55bf93 2021-11-23)
binary: rustc
commit-hash: 65c55bf931a55e6b1e5ed14ad8623814a7386424
commit-date: 2021-11-23
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

~/foobar> cargo run
cargo run
   Compiling foobar v0.1.0 (/home/ajanse/foobar)
thread 'rustc' panicked at 'index out of bounds: the len is 7 but the index is 7', compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs:450:53
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.58.0-nightly (65c55bf93 2021-11-23) 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 `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `foobar`
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 7 but the index is 7', compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs:450:53
stack backtrace:
   0: rust_begin_unwind
             at /rustc/65c55bf931a55e6b1e5ed14ad8623814a7386424/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/65c55bf931a55e6b1e5ed14ad8623814a7386424/library/core/src/panicking.rs:107:14
   2: core::panicking::panic_bounds_check
             at /rustc/65c55bf931a55e6b1e5ed14ad8623814a7386424/library/core/src/panicking.rs:75:5
   3: <core::option::Option<&rustc_middle::mir::Location>>::map::<rustc_span::span_encoding::Span, <rustc_borrowck::MirBorrowckCtxt>::report_mutability_error::{closure#2}>
   4: <rustc_borrowck::MirBorrowckCtxt>::report_mutability_error
   5: <rustc_borrowck::MirBorrowckCtxt as rustc_mir_dataflow::framework::visitor::ResultsVisitor>::visit_statement_before_primary_effect
   6: <rustc_mir_dataflow::framework::direction::Forward as rustc_mir_dataflow::framework::direction::Direction>::visit_results_in_block::<rustc_borrowck::dataflow::BorrowckAnalyses<rustc_index::bit_set::BitSet<rustc_borrowck::dataflow::BorrowIndex>, rustc_index::bit_set::BitSet<rustc_mir_dataflow::move_paths::MovePathIndex>, rustc_index::bit_set::BitSet<rustc_mir_dataflow::move_paths::InitIndex>>, rustc_borrowck::dataflow::BorrowckAnalyses<rustc_mir_dataflow::framework::engine::Results<rustc_borrowck::dataflow::Borrows>, rustc_mir_dataflow::framework::engine::Results<rustc_mir_dataflow::impls::MaybeUninitializedPlaces>, rustc_mir_dataflow::framework::engine::Results<rustc_mir_dataflow::impls::EverInitializedPlaces>>, rustc_borrowck::MirBorrowckCtxt>
   7: rustc_borrowck::do_mir_borrowck
   8: <rustc_infer::infer::InferCtxtBuilder>::enter::<rustc_middle::mir::query::BorrowCheckResult, rustc_borrowck::mir_borrowck::{closure#0}>
   9: rustc_borrowck::mir_borrowck
  10: <rustc_borrowck::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
  11: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::mir::query::BorrowCheckResult>
  12: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::mir::query::BorrowCheckResult, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::mir::query::BorrowCheckResult>::{closure#3}>
  13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::mir::query::BorrowCheckResult>>
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  15: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
  16: rustc_interface::passes::analysis
  17: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>
  18: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<(), rustc_errors::ErrorReported>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>::{closure#3}>
  19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  20: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  21: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  22: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  23: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  24: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  25: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@aaronjanse aaronjanse 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 Dec 17, 2021
@chordtoll
Copy link
Contributor

This panic appears to be fixed in PR #91212. Duplicate of #91206?

@camelid
Copy link
Member

camelid commented Dec 29, 2021

Perhaps worth adding a regression test for this issue in particular.

@camelid camelid added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 29, 2021
@chordtoll
Copy link
Contributor

Sounds like a good idea- I'll get going on that

@chordtoll
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2022
…crum

Regression test for borrowck ICE rust-lang#92015

This issue has come up a few times. Creating a regression test.
Closes rust-lang#92015.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2022
…crum

Regression test for borrowck ICE rust-lang#92015

This issue has come up a few times. Creating a regression test.
Closes rust-lang#92015.
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 6, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#92058 (Make Run button visible on hover)
 - rust-lang#92288 (Fix a pair of mistyped test cases in `std::net::ip`)
 - rust-lang#92349 (Fix rustdoc::private_doc_tests lint for public re-exported items)
 - rust-lang#92360 (Some cleanups around check_argument_types)
 - rust-lang#92389 (Regression test for borrowck ICE rust-lang#92015)
 - rust-lang#92404 (Fix font size for [src] links in headers)
 - rust-lang#92443 (Rustdoc: resolve associated traits for non-generic primitive types)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 96a267e Jan 6, 2022
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

Successfully merging a pull request may close this issue.

3 participants