Skip to content

ICE: unmatched subst and hir arg #82126

Closed
@edward-shen

Description

@edward-shen

Code

The following is an attempted minimum reproducible sample that causes ICE. From a few minutes of experimentation, I wasn't able to further minimize the example, but I feel as if it should be possible (perhaps an example can be formed with just an async boundary and a mutex?).

use tokio::sync::Mutex;

trait Buffered {
    fn buffer(&mut self) -> &mut Vec<usize>;
}

trait MarketMultiplierIterator: Buffered {
    fn peek_n(&mut self, n: usize) -> &[usize];
}

impl<T: Buffered> MarketMultiplierIterator for T {
    fn peek_n(&mut self, n: usize) -> &[usize] {
        &self.buffer()[..n]
    }
}

struct MarketMultiplier {
    buy: BuyMarketMultiplier,
}

impl MarketMultiplier {
    fn buy(&mut self) -> &mut BuyMarketMultiplier {
        &mut self.buy
    }
}

struct BuyMarketMultiplier {
    buffer: Vec<usize>,
}

impl Buffered for &mut BuyMarketMultiplier {
    fn buffer(&mut self) -> &mut Vec<usize> {
        &mut self.buffer
    }
}

pub(crate) struct Market {
    generator: Mutex<MarketMultiplier>,
}

impl Market {
    pub(crate) async fn buy_lock(&self) -> LockedMarket<'_> {
        LockedMarket(self.generator.lock().await.buy())
    }
}

pub(crate) struct LockedMarket<T: MarketMultiplierIterator>(T);

Meta

rustc --version --verbose:

rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.50.0

Also saw the ICE on nightly, but I can't seem to get my instance of cargo to recognize the 1.52 toolchain. Testing on playgound shows this still is present:

rustc 1.52.0-nightly (8e54a2113 2021-02-13) running on x86_64-unknown-linux-gnu

Error output

The following outputs are the result of building on nightly playgound:

Compiling playground v0.0.1 (/playground)
error[E0107]: this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
  --> src/lib.rs:42:44
   |
42 |     pub(crate) async fn buy_lock(&self) -> LockedMarket<'_> {
   |                                            ^^^^^^^^^^^^---- help: remove these generics
   |                                            |
   |                                            expected 0 lifetime arguments
   |
note: struct defined here, with 0 lifetime parameters
  --> src/lib.rs:47:19
   |
47 | pub(crate) struct LockedMarket<T: MarketMultiplierIterator>(T);
   |                   ^^^^^^^^^^^^

error[E0107]: this struct takes 1 type argument but 0 type arguments were supplied
  --> src/lib.rs:42:44
   |
42 |     pub(crate) async fn buy_lock(&self) -> LockedMarket<'_> {
   |                                            ^^^^^^^^^^^^ expected 1 type argument
   |
note: struct defined here, with 1 type parameter: `T`
  --> src/lib.rs:47:19
   |
47 | pub(crate) struct LockedMarket<T: MarketMultiplierIterator>(T);
   |                   ^^^^^^^^^^^^ -
help: add missing type argument
   |
42 |     pub(crate) async fn buy_lock(&self) -> LockedMarket<'_, T> {
   |                                                           ^^^

error: internal compiler error: compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs:640:21: unmatched subst and hir arg: found &mut BuyMarketMultiplier vs Lifetime(lifetime(HirId { owner: DefId(0:23 ~ playground[2f39]::{impl#3}::buy_lock::{opaque#0}), local_id: 2 }: '_))
  --> src/lib.rs:42:57
   |
42 |     pub(crate) async fn buy_lock(&self) -> LockedMarket<'_> {
   |                                                         ^^
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/8e54a21139ae96a2aca3129100b057662e2799b9/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::span_bug
   3: rustc_errors::Handler::span_bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::span_bug_fmt
   7: rustc_mir::borrow_check::diagnostics::region_name::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::highlight_if_we_can_match_hir_ty
   8: rustc_mir::borrow_check::diagnostics::region_name::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::give_region_a_name
   9: rustc_mir::borrow_check::diagnostics::explain_borrow::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::explain_why_borrow_contains_point
  10: rustc_mir::borrow_check::diagnostics::conflict_errors::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::report_borrowed_value_does_not_live_long_enough
  11: rustc_mir::borrow_check::path_utils::each_borrow_involving_path
  12: rustc_mir::borrow_check::MirBorrowckCtxt::access_place
  13: <rustc_mir::borrow_check::MirBorrowckCtxt as rustc_mir::dataflow::framework::visitor::ResultsVisitor>::visit_terminator_before_primary_effect
  14: <rustc_mir::dataflow::framework::direction::Forward as rustc_mir::dataflow::framework::direction::Direction>::visit_results_in_block
  15: rustc_mir::dataflow::framework::visitor::visit_results
  16: rustc_mir::borrow_check::do_mir_borrowck
  17: rustc_infer::infer::InferCtxtBuilder::enter
  18: rustc_mir::borrow_check::mir_borrowck
  19: 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
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_data_structures::stack::ensure_sufficient_stack
  22: rustc_query_system::query::plumbing::force_query_with_job
  23: rustc_query_system::query::plumbing::get_query_impl
  24: rustc_mir::borrow_check::type_check::TypeChecker::check_rvalue
  25: rustc_mir::borrow_check::type_check::TypeChecker::typeck_mir
  26: rustc_mir::borrow_check::type_check::type_check
  27: rustc_mir::borrow_check::nll::compute_regions
  28: rustc_mir::borrow_check::do_mir_borrowck
  29: rustc_infer::infer::InferCtxtBuilder::enter
  30: rustc_mir::borrow_check::mir_borrowck
  31: 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
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::force_query_with_job
  35: rustc_query_system::query::plumbing::get_query_impl
  36: rustc_typeck::collect::type_of::type_of
  37: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::type_of>::compute
  38: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  39: rustc_data_structures::stack::ensure_sufficient_stack
  40: rustc_query_system::query::plumbing::force_query_with_job
  41: rustc_query_system::query::plumbing::get_query_impl
  42: rustc_typeck::check::check::check_item_type
  43: rustc_middle::hir::map::Map::visit_item_likes_in_module
  44: rustc_typeck::check::check::check_mod_item_types
  45: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_item_types>::compute
  46: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  47: rustc_data_structures::stack::ensure_sufficient_stack
  48: rustc_query_system::query::plumbing::force_query_with_job
  49: rustc_query_system::query::plumbing::get_query_impl
  50: rustc_query_system::query::plumbing::ensure_query_impl
  51: rustc_session::utils::<impl rustc_session::session::Session>::time
  52: rustc_typeck::check_crate
  53: rustc_interface::passes::analysis
  54: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  55: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  56: rustc_data_structures::stack::ensure_sufficient_stack
  57: rustc_query_system::query::plumbing::force_query_with_job
  58: rustc_query_system::query::plumbing::get_query_impl
  59: rustc_interface::passes::QueryContext::enter
  60: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  61: rustc_span::with_source_map
  62: 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 (8e54a2113 2021-02-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `Market::buy_lock::{closure#0}`
#1 [mir_borrowck] borrow-checking `Market::buy_lock`
#2 [type_of] computing type of `Market::buy_lock::{opaque#0}`
#3 [check_mod_item_types] checking item types in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0107`.
error: could not compile `playground`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions