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: unmatched subst and hir arg #82126

Closed
edward-shen opened this issue Feb 15, 2021 · 4 comments · Fixed by #82136
Closed

ICE: unmatched subst and hir arg #82126

edward-shen opened this issue Feb 15, 2021 · 4 comments · Fixed by #82136
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. glacier ICE tracked in rust-lang/glacier. 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

@edward-shen
Copy link
Contributor

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`

@edward-shen edward-shen 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 Feb 15, 2021
@jyn514 jyn514 added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Feb 15, 2021
@jyn514
Copy link
Member

jyn514 commented Feb 15, 2021

Smaller:

use std::sync::Mutex;

struct MarketMultiplier {}

impl MarketMultiplier {
    fn buy(&mut self) -> &mut usize {
        todo!()
    }
}

async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
    LockedMarket(generator.lock().unwrap().buy())
}

struct LockedMarket<T>(T);

fn main() {}

@jyn514 jyn514 removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Feb 15, 2021
@jyn514
Copy link
Member

jyn514 commented Feb 15, 2021

Relevant code:

// I *think* that HIR lowering should ensure this
// doesn't happen, even in erroneous
// programs. Else we should use delay-span-bug.
span_bug!(
hir_arg.span(),
"unmatched subst and hir arg: found {:?} vs {:?}",
kind,
hir_arg,
);

So I think that just needs to be a delay_span_bug.

@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints E-help-wanted Call for participation: Help is requested to fix this issue. labels Feb 15, 2021
@edward-shen
Copy link
Contributor Author

I've actually been looking to contribute to Rust—would this be a good first issue to tackle?

@jyn514
Copy link
Member

jyn514 commented Feb 15, 2021

This would definitely be a good first issue!

fanninpm added a commit to fanninpm/glacier that referenced this issue Feb 16, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 16, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 16, 2021
…r, r=lcnr

Fix ICE: Use delay_span_bug for mismatched subst/hir arg

Fixes rust-lang#82126.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 17, 2021
…r, r=lcnr

Fix ICE: Use delay_span_bug for mismatched subst/hir arg

Fixes rust-lang#82126.
@bors bors closed this as completed in 13730e9 Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. glacier ICE tracked in rust-lang/glacier. 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