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

const generics: rustc panicked at 'already borrowed: BorrowMutError' #69654

Closed
is8ac opened this issue Mar 3, 2020 · 3 comments · Fixed by #71286
Closed

const generics: rustc panicked at 'already borrowed: BorrowMutError' #69654

is8ac opened this issue Mar 3, 2020 · 3 comments · Fixed by #71286
Labels
A-const-generics Area: const generics (parameters and arguments) 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. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@is8ac
Copy link

is8ac commented Mar 3, 2020

Source code

#![feature(const_generics)]

trait Bar<O> {}
impl<O> Bar<O> for [u8; O] {}

struct Foo<const O: usize> {}
impl<const O: usize> Foo<O>
where
    [u8; O]: Bar<[(); O]>,
{
    fn foo() {}
}

fn main() {
    Foo::foo();
}

Result

$ rustc src/bin/borrow_mut_error_demo.rs
error[E0423]: expected value, found type parameter `O`
   --> src/bin/borrow_mut_error_demo.rs:4:25
    |
4   | impl<O> Bar<O> for [u8; O] {}
    |                         ^ help: a tuple variant with a similar name exists: `Ok`

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/bin/borrow_mut_error_demo.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

thread 'rustc' panicked at 'already borrowed: BorrowMutError', /rustc/18c275b423f9f13c0e404ae3804967d2ab66337c/src/libcore/cell.rs:878:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  12: rust_begin_unwind
             at src/libstd/panicking.rs:378
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  14: core::option::expect_none_failed
             at src/libcore/option.rs:1211
  15: <rustc_infer::infer::combine::Generalizer as rustc::ty::relate::TypeRelation>::tys
  16: <rustc::ty::subst::GenericArg as rustc::ty::relate::Relate>::relate
  17: <I as rustc::ty::context::InternAs<[T],R>>::intern_with
  18: rustc::ty::relate::super_relate_consts
  19: <rustc_infer::infer::combine::Generalizer as rustc::ty::relate::TypeRelation>::consts
  20: <rustc_infer::infer::combine::Generalizer as rustc::ty::relate::TypeRelation>::consts
  21: rustc::ty::relate::super_relate_tys
  22: <rustc_infer::infer::combine::Generalizer as rustc::ty::relate::TypeRelation>::tys
  23: rustc_infer::infer::combine::CombineFields::instantiate
  24: <rustc_infer::infer::equate::Equate as rustc::ty::relate::TypeRelation>::tys
  25: <rustc::ty::subst::GenericArg as rustc::ty::relate::Relate>::relate
  26: <I as rustc::ty::context::InternAs<[T],R>>::intern_with
  27: <rustc::ty::sty::TraitRef as rustc::ty::relate::Relate>::relate
  28: rustc_infer::infer::InferCtxt::commit_if_ok
  29: rustc_infer::traits::select::SelectionContext::match_impl
  30: rustc_infer::infer::InferCtxt::probe
  31: rustc::ty::trait_def::<impl rustc::ty::context::TyCtxt>::for_each_relevant_impl
  32: rustc_infer::traits::select::SelectionContext::assemble_candidates_from_impls
  33: rustc_infer::traits::select::SelectionContext::assemble_candidates
  34: rustc_infer::traits::select::SelectionContext::candidate_from_obligation_no_cache
  35: rustc::dep_graph::graph::DepGraph::with_anon_task
  36: rustc_infer::traits::select::SelectionContext::candidate_from_obligation
  37: rustc_infer::traits::select::SelectionContext::evaluate_stack
  38: rustc::dep_graph::graph::DepGraph::with_anon_task
  39: rustc_infer::traits::select::SelectionContext::evaluate_predicate_recursively
  40: rustc_infer::infer::InferCtxt::probe
  41: rustc_infer::traits::select::SelectionContext::evaluate_root_obligation
  42: rustc::ty::context::GlobalCtxt::enter_local
  43: rustc_traits::evaluate_obligation::evaluate_obligation
  44: rustc::ty::query::__query_compute::evaluate_obligation
  45: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::evaluate_obligation>::compute
  46: rustc::dep_graph::graph::DepGraph::with_task_impl
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  48: rustc_infer::traits::query::evaluate_obligation::<impl rustc_infer::infer::InferCtxt>::evaluate_obligation
  49: rustc_infer::traits::query::evaluate_obligation::<impl rustc_infer::infer::InferCtxt>::predicate_may_hold
  50: rustc_infer::infer::InferCtxt::probe
  51: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  52: rustc_typeck::check::method::probe::ProbeContext::pick_method
  53: rustc_typeck::check::method::probe::ProbeContext::pick_core
  54: rustc_typeck::check::method::probe::ProbeContext::pick
  55: rustc_infer::infer::InferCtxt::probe
  56: rustc_typeck::check::method::probe::<impl rustc_typeck::check::FnCtxt>::probe_for_name
  57: rustc_typeck::check::method::<impl rustc_typeck::check::FnCtxt>::resolve_ufcs
  58: rustc_typeck::check::FnCtxt::resolve_ty_and_res_ufcs
  59: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  60: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  61: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  62: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  63: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  64: rustc_typeck::check::FnCtxt::check_stmt
  65: rustc_typeck::check::FnCtxt::check_block_with_expected
  66: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  67: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  68: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  69: rustc_typeck::check::check_fn
  70: rustc::ty::context::GlobalCtxt::enter_local
  71: rustc_typeck::check::typeck_tables_of
  72: rustc::ty::query::__query_compute::typeck_tables_of
  73: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  74: rustc::dep_graph::graph::DepGraph::with_task_impl
  75: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  76: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  77: rustc_typeck::check::typeck_item_bodies
  78: rustc::ty::query::__query_compute::typeck_item_bodies
  79: rustc::dep_graph::graph::DepGraph::with_task_impl
  80: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  81: rustc_typeck::check_crate
  82: rustc_interface::passes::analysis
  83: rustc::ty::query::__query_compute::analysis
  84: rustc::dep_graph::graph::DepGraph::with_task_impl
  85: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  86: rustc::ty::context::tls::enter_global
  87: rustc_interface::interface::run_compiler_in_existing_thread_pool
  88: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.43.0-nightly (18c275b42 2020-03-02) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `[u8; _]: Bar<[(); _]>`
#1 [typeck_tables_of] type-checking `main`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

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

Meta

$ rustc --version --verbose
rustc 1.43.0-nightly (18c275b42 2020-03-02)
binary: rustc
commit-hash: 18c275b423f9f13c0e404ae3804967d2ab66337c
commit-date: 2020-03-02
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
@JohnTitor JohnTitor added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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 3, 2020
@jonas-schievink jonas-schievink added the requires-nightly This issue requires a nightly compiler in some way. label Mar 3, 2020
@pnkfelix
Copy link
Member

pnkfelix commented Mar 3, 2020

ran cargo-bisect-rustc on this.

It reports:

Regression found in the compiler

searched nightlies: from nightly-2019-11-18 to nightly-2019-12-02
regressed nightly: nightly-2019-12-02
searched commits: from d8bdb3f to 4007d4e
regressed commit: 135ccba

@pnkfelix
Copy link
Member

pnkfelix commented Mar 3, 2020

i.e. this was injected by (rollup) PR #66908

its not immediately obvious to me which associated PR from that rollup is to blame. Maybe #66883 ?

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 9, 2020
@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 18, 2020
@JohnTitor
Copy link
Member

The ICE no longer occurs with latest nightly, I guess #71049 fixed it. Marked as E-needs-test.

Alexendoo added a commit to Alexendoo/rust that referenced this issue Apr 18, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 28, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 29, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#71217 (Suggest `;` or assignment to drop borrows in tail exprs)
 - rust-lang#71286 (Add regression test for rust-lang#69654)
 - rust-lang#71296 (Change wording on read_vectored docs)
 - rust-lang#71654 (Update link to unstable book for llvm_asm macro)
 - rust-lang#71657 (Add rust-lang#24949 assoc constant static recursion test)

Failed merges:

r? @ghost
@bors bors closed this as completed in 65527cb Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) 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. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

5 participants