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

[ICE] With closure on mutable ref #81700

Closed
leonardo-m opened this issue Feb 3, 2021 · 4 comments · Fixed by #81717
Closed

[ICE] With closure on mutable ref #81700

leonardo-m opened this issue Feb 3, 2021 · 4 comments · Fixed by #81717
Assignees
Labels
A-closures Area: Closures (`|…| { … }`) C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@leonardo-m
Copy link

fn foo(x: &mut u32) {
    let bar = || { foo(x); };
    bar();
}
fn main() {}

Compiled with rustc bug2.rs gives:

error: internal compiler error: compiler\rustc_mir\src\borrow_check\diagnostics\mutability_errors.rs:525:22: upvar `x` borrowed, but not mutably

thread 'rustc' panicked at 'Box<Any>', compiler\rustc_errors\src\lib.rs:958:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   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_mir::borrow_check::diagnostics::mutability_errors::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::show_mutating_upvar
   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: core::ops::function::FnOnce::call_once
  17: 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
  18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  19: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  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_session::utils::<impl rustc_session::session::Session>::time
  24: rustc_interface::passes::analysis
  25: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  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
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:/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (d4e3570db 2021-02-01) running on x86_64-pc-windows-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `foo`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
@leonardo-m leonardo-m added the C-bug Category: This is a bug. label Feb 3, 2021
@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 3, 2021

This was caused by 74500b9
@rustbot prioritize

edit:
in beta, this gives the following error:

error[E0596]: cannot borrow `bar` as mutable, as it is not declared as mutable
 --> src/main.rs:3:5
  |
2 |     let bar = || { foo(x); };
  |         --- help: consider changing this to be mutable: `mut bar`
3 |     bar();
  |     ^^^ cannot borrow as mutable

error: aborting due to previous error

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

@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 3, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 3, 2021
@apiraino
Copy link
Contributor

apiraino commented Feb 3, 2021

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@apiraino apiraino added the P-medium Medium priority label Feb 3, 2021
@camelid
Copy link
Member

camelid commented Feb 3, 2021

Looks likely that #81158 is the cause. cc @Aaron1011

@camelid
Copy link
Member

camelid commented Feb 3, 2021

Re-prioritizing as P-high and removing I-prioritize as discussed in the prioritization working group.

@rustbot label: +regression-from-stable-to-nightly +P-high -P-medium -I-prioritize

@rustbot rustbot added P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. P-medium Medium priority labels Feb 3, 2021
@camelid camelid added the A-closures Area: Closures (`|…| { … }`) label Feb 3, 2021
@Aaron1011 Aaron1011 self-assigned this Feb 3, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 3, 2021
Fix panic when emitting diagnostic for closure mutable binding error

Fixes rust-lang#81700

The upvar borrow kind may be `ty::BorrowKind::UniqueImmBorrow`, which is
still a mutable borrow for the purposes of this diagnostic code.
@bors bors closed this as completed in bc84e21 Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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.

6 participants