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: thread 'rustc' panicked at 'region constraints already solved' #87657

Closed
hkmatsumoto opened this issue Jul 31, 2021 · 6 comments · Fixed by #87795
Closed

ICE: thread 'rustc' panicked at 'region constraints already solved' #87657

hkmatsumoto opened this issue Jul 31, 2021 · 6 comments · Fixed by #87795
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

@hkmatsumoto
Copy link
Member

hkmatsumoto commented Jul 31, 2021

Code

#![feature(rustc_private)]

extern crate rustc_middle;

use rustc_middle::ty::TyCtxt;

fn foo(tcx: TyCtxt<'_>) {
    let krate = tcx.hir().krate();
    for &item in krate.items() {
        todo!()
    }
}

Compiles with &item replaced for item

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (1f0a591b3 2021-07-30)
binary: rustc
commit-hash: 1f0a591b3a5963a0ab11a35dc525ad9d46f612e4
commit-date: 2021-07-30
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

Error output

    Checking ice v0.1.0 (/home/xxx/ice)
warning: unused variable: `item`
 --> src/lib.rs:9:10
  |
9 |     for &item in krate.items() {
  |          ^^^^ help: if this is intentional, prefix it with an underscore: `_item`
  |
  = note: `#[warn(unused_variables)]` on by default

thread 'rustc' panicked at 'region constraints already solved', compiler/rustc_infer/src/infer/mod.rs:268:14
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.56.0-nightly (1f0a591b3 2021-07-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `foo`
#1 [analysis] running analysis passes on this crate
end of query stack
warning: `ice` (lib) generated 1 warning
error: could not compile `ice`; 1 warning emitted
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/1f0a591b3a5963a0ab11a35dc525ad9d46f612e4/library/std/src/panicking.rs:516:5
   1: core::panicking::panic_fmt
             at /rustc/1f0a591b3a5963a0ab11a35dc525ad9d46f612e4/library/core/src/panicking.rs:93:14
   2: core::option::expect_failed
             at /rustc/1f0a591b3a5963a0ab11a35dc525ad9d46f612e4/library/core/src/option.rs:1578:5
   3: <rustc_infer::infer::canonical::canonicalizer::Canonicalizer as rustc_middle::ty::fold::TypeFolder>::fold_region
   4: rustc_middle::ty::fold::TypeFoldable::fold_with
   5: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
   6: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
   7: rustc_middle::ty::fold::TypeFoldable::fold_with
   8: rustc_middle::ty::fold::TypeFoldable::fold_with
   9: rustc_infer::infer::canonical::canonicalizer::Canonicalizer::canonicalize
  10: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  11: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  12: rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions
  13: rustc_mir::borrow_check::diagnostics::move_errors::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::report_move_errors
  14: rustc_mir::borrow_check::do_mir_borrowck
  15: rustc_infer::infer::InferCtxtBuilder::enter
  16: rustc_mir::borrow_check::mir_borrowck
  17: core::ops::function::FnOnce::call_once
  18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  19: rustc_data_structures::stack::ensure_sufficient_stack
  20: rustc_query_system::query::plumbing::force_query_with_job
  21: rustc_query_system::query::plumbing::get_query_impl
  22: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  23: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  24: rustc_interface::passes::analysis
  25: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  28: rustc_data_structures::stack::ensure_sufficient_stack
  29: rustc_query_system::query::plumbing::force_query_with_job
  30: rustc_query_system::query::plumbing::get_query_impl
  31: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  32: rustc_interface::passes::QueryContext::enter
  33: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  34: rustc_span::with_source_map
  35: rustc_interface::interface::create_compiler_and_run
  36: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@hkmatsumoto hkmatsumoto 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 Jul 31, 2021
@chorman0773
Copy link
Contributor

I got the same issue on the latest nightly and on play.rust-lang.org, without using rustc-private

// lazy_static::lazy_static! {
//     static ref LOADERS: Vec<&'static u8> = Vec::new();
// }

const LOADERS: &Vec<&'static u8> = &Vec::new();

pub fn break_code() -> Option<&'static u8> {
    for loader in *LOADERS {
        return Some(loader);
    }
    None
}

The commented out lazy_static! block was used originally and triggers the ICE as well.

@SkiFire13
Copy link
Contributor

searched nightlies: from nightly-2021-07-29 to nightly-2021-08-02
regressed nightly: nightly-2021-07-31
searched commits: from 4927238 to 1f0a591
regressed commit: 1f0a591

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-pc-windows-msvc
Reproduce with:

cargo bisect-rustc --regress=ice

I think this might have been introduced by #87559, in particular this piece of code:

Some(def_id) => type_known_to_meet_bound_modulo_regions(
&self.infcx,
self.param_env,
self.infcx.tcx.mk_imm_ref(self.infcx.tcx.lifetimes.re_erased, ty),
def_id,
DUMMY_SP,
),

@lqd
Copy link
Member

lqd commented Aug 4, 2021

If that's indeed caused by #87559 then we should let its author know: @estebank.

@estebank estebank added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Aug 5, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 5, 2021
@estebank
Copy link
Contributor

estebank commented Aug 5, 2021

Just checked and thankfully it didn't land in beta.

@estebank
Copy link
Contributor

estebank commented Aug 5, 2021

@rustbot claim

@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 12, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 13, 2021
…ion, r=oli-obk

Avoid ICE caused by suggestion

When suggesting dereferencing something that can be iterable in a `for`
loop, erase lifetimes and use a fresh `ty::ParamEnv` to avoid 'region
constraints already solved' panic.

Fix rust-lang#87657, fix rust-lang#87709, fix rust-lang#87651.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 13, 2021
…ion, r=oli-obk

Avoid ICE caused by suggestion

When suggesting dereferencing something that can be iterable in a `for`
loop, erase lifetimes and use a fresh `ty::ParamEnv` to avoid 'region
constraints already solved' panic.

Fix rust-lang#87657, fix rust-lang#87709, fix rust-lang#87651.
@bors bors closed this as completed in a0bf7d2 Aug 13, 2021
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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.

7 participants