Skip to content

ICE: region constraints already solved #136335

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

pub struct Query<'a: 'a, 'b: 'b, T>(Q);

pub trait SystemParam {
    type State;
}
impl SystemParam for Query<Q> {}

pub struct ParamSet<T: SystemParam>(T)
where
    T::State: Sized;

fn ref_handler<'a>(_: &ParamSet<Query<&'a u8>>) {}

original:

//@ check-pass

// We currently special case bevy from erroring on incorrect implied bounds
// from normalization (issue #109628).
// Otherwise, we would expect this to hit that error.

pub trait WorldQuery {}
impl WorldQuery for &u8 {}

pub struct Query<'a: 'a, 'b: 'b, T>(Q);

pub trait SystemParam {
    type State;
}
impl<Q: WorldQuery + 'static> SystemParam for Query<Q> {
    type State = ();
    // `Q: 'static` is required because we need the TypeId of Q ...
}

pub struct ParamSet<T: SystemParam>(T) where T::State: Sized;

fn handler<'a>(x: ParamSet<Query<&'in_ u8>>) {
    let _: ParamSet<_> = x;
}

fn ref_handler<'a>(_: &ParamSet<Query<&'a u8>>) {}

fn badboi3<'in_, 'out, T>(a: Foo<'in_, 'out, (&'in_ T, &'out T)>, sadness: &'in_ T) {
    //~^ ERROR lifetime mismatch
    let _: &'out T = sadness.cast();
    //~^ ERROR may not live long enough
}

Version information

rustc 1.86.0-nightly (6c1d960d8 2025-01-30)
binary: rustc
commit-hash: 6c1d960d88dd3755548b3818630acb63fa98187e
commit-date: 2025-01-30
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Possibly related line of code:

}
#[inline]
pub fn unwrap_region_constraints(&mut self) -> RegionConstraintCollector<'_, 'tcx> {
self.region_constraint_storage
.as_mut()
.expect("region constraints already solved")
.with_log(&mut self.undo_log)
}
// Iterates through the opaque type definitions without taking them; this holds the
// `InferCtxtInner` lock, so make sure to not do anything with `InferCtxt` side-effects
// while looping through this.

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0726]: implicit elided lifetime not allowed here
 --> /tmp/icemaker_global_tempdir.QuPptJFGBt0t/rustc_testrunner_tmpdir_reporting.P3ypXr6fxMi8/mvce.rs:6:22
  |
6 | impl SystemParam for Query<Q> {}
  |                      ^^^^^^^^ expected lifetime parameters
  |
help: indicate the anonymous lifetimes
  |
6 | impl SystemParam for Query<'_, '_, Q> {}
  |                            +++++++

error[E0412]: cannot find type `Q` in this scope
 --> /tmp/icemaker_global_tempdir.QuPptJFGBt0t/rustc_testrunner_tmpdir_reporting.P3ypXr6fxMi8/mvce.rs:1:37
  |
1 | pub struct Query<'a: 'a, 'b: 'b, T>(Q);
  |                                  -  ^
  |                                  |
  |                                  similarly named type parameter `T` defined here
  |
help: a type parameter with a similar name exists
  |
1 | pub struct Query<'a: 'a, 'b: 'b, T>(T);
  |                                     ~
help: you might be missing a type parameter
  |
1 | pub struct Query<'a: 'a, 'b: 'b, T, Q>(Q);
  |                                   +++

error[E0412]: cannot find type `Q` in this scope
 --> /tmp/icemaker_global_tempdir.QuPptJFGBt0t/rustc_testrunner_tmpdir_reporting.P3ypXr6fxMi8/mvce.rs:6:28
  |
6 | impl SystemParam for Query<Q> {}
  |                            ^ not found in this scope
  |
help: you might be missing a type parameter
  |
6 | impl<Q> SystemParam for Query<Q> {}
  |     +++

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.QuPptJFGBt0t/rustc_testrunner_tmpdir_reporting.P3ypXr6fxMi8/mvce.rs:12:51
   |
12 | fn ref_handler<'a>(_: &ParamSet<Query<&'a u8>>) {}
   |                                                   ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.QuPptJFGBt0t/rustc_testrunner_tmpdir_reporting.P3ypXr6fxMi8/mvce.rs`


thread 'rustc' panicked at compiler/rustc_infer/src/infer/mod.rs:227:14:
region constraints already solved
stack backtrace:
   0:     0x709ff1c27100 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h98094058176981c2
   1:     0x709ff24138e6 - core::fmt::write::h8bb9b5c90c3c6b09
   2:     0x709ff3322391 - std::io::Write::write_fmt::hc16cbd4774dd8405
   3:     0x709ff1c26f62 - std::sys::backtrace::BacktraceLock::print::h2630ee44f7e8aa88
   4:     0x709ff1c293e2 - std::panicking::default_hook::{{closure}}::h2be931de6b167295
   5:     0x709ff1c2926a - std::panicking::default_hook::h98b97c37343be27d
   6:     0x709ff0d85859 - std[b9fe1580bce53cbe]::panicking::update_hook::<alloc[b37c01f5c3be96d]::boxed::Box<rustc_driver_impl[c7b34afe4b5b317]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x709ff1c29f23 - std::panicking::rust_panic_with_hook::h7e31ddb106e67131
   8:     0x709ff1c29c1a - std::panicking::begin_panic_handler::{{closure}}::he6481253f3049abe
   9:     0x709ff1c275d9 - std::sys::backtrace::__rust_end_short_backtrace::h291e53122599639b
  10:     0x709ff1c298dd - rust_begin_unwind
  11:     0x709fee850370 - core::panicking::panic_fmt::h6721276b1f84ecda
  12:     0x709fef9b0bfb - core::option::expect_failed::h0e460c2e4ff6181b
  13:     0x709ff2601120 - <rustc_infer[3d7b53041222df8f]::infer::InferCtxt>::sub_regions
  14:     0x709ff2d61255 - <rustc_trait_selection[df5a885d60312d47]::traits::fulfill::FulfillProcessor as rustc_data_structures[a6636e4bea046b9d]::obligation_forest::ObligationProcessor>::process_obligation
  15:     0x709ff2407b4b - <rustc_data_structures[a6636e4bea046b9d]::obligation_forest::ObligationForest<rustc_trait_selection[df5a885d60312d47]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[df5a885d60312d47]::traits::fulfill::FulfillProcessor>
  16:     0x709ff2653562 - <rustc_trait_selection[df5a885d60312d47]::traits::fulfill::FulfillmentContext<rustc_infer[3d7b53041222df8f]::traits::engine::ScrubbedTraitError> as rustc_infer[3d7b53041222df8f]::traits::engine::TraitEngine<rustc_infer[3d7b53041222df8f]::traits::engine::ScrubbedTraitError>>::select_all_or_error
  17:     0x709ff30668be - rustc_trait_selection[df5a885d60312d47]::traits::outlives_bounds::implied_outlives_bounds
  18:     0x709ff29be0ef - <rustc_infer[3d7b53041222df8f]::infer::outlives::env::OutlivesEnvironment as rustc_trait_selection[df5a885d60312d47]::regions::OutlivesEnvironmentBuildExt>::new_with_implied_bounds_compat::<indexmap[a9b14da2e389f1f4]::set::IndexSet<rustc_middle[12fcca5210661983]::ty::Ty, core[6f4bacb0707a325d]::hash::BuildHasherDefault<rustc_hash[d6a72c803d0a6ed8]::FxHasher>>>
  19:     0x709ff2999b00 - rustc_hir_analysis[dcbbfbfe730e0440]::check::wfcheck::check_item_fn
  20:     0x709ff29a8291 - rustc_hir_analysis[dcbbfbfe730e0440]::check::wfcheck::check_well_formed
  21:     0x709ff29a6cc7 - rustc_query_impl[bdf670d0b9840f13]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bdf670d0b9840f13]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[12fcca5210661983]::query::erase::Erased<[u8; 1usize]>>
  22:     0x709ff29a6769 - rustc_query_system[57b45adcca80f492]::query::plumbing::try_execute_query::<rustc_query_impl[bdf670d0b9840f13]::DynamicConfig<rustc_data_structures[a6636e4bea046b9d]::vec_cache::VecCache<rustc_span[27da1c5d61fb523f]::def_id::LocalDefId, rustc_middle[12fcca5210661983]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[57b45adcca80f492]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[bdf670d0b9840f13]::plumbing::QueryCtxt, false>
  23:     0x709ff29a61c6 - rustc_query_impl[bdf670d0b9840f13]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  24:     0x709ff29a3dde - rustc_hir_analysis[dcbbfbfe730e0440]::check::wfcheck::check_mod_type_wf
  25:     0x709ff29a3be3 - rustc_query_impl[bdf670d0b9840f13]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bdf670d0b9840f13]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[12fcca5210661983]::query::erase::Erased<[u8; 1usize]>>
  26:     0x709ff335ee88 - rustc_query_system[57b45adcca80f492]::query::plumbing::try_execute_query::<rustc_query_impl[bdf670d0b9840f13]::DynamicConfig<rustc_query_system[57b45adcca80f492]::query::caches::DefaultCache<rustc_span[27da1c5d61fb523f]::def_id::LocalModDefId, rustc_middle[12fcca5210661983]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[bdf670d0b9840f13]::plumbing::QueryCtxt, false>
  27:     0x709ff335ec30 - rustc_query_impl[bdf670d0b9840f13]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  28:     0x709ff276f3e6 - rustc_hir_analysis[dcbbfbfe730e0440]::check_crate
  29:     0x709ff276bde2 - rustc_interface[215e699f6d71029]::passes::run_required_analyses
  30:     0x709ff331da9e - rustc_interface[215e699f6d71029]::passes::analysis
  31:     0x709ff331da6f - rustc_query_impl[bdf670d0b9840f13]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bdf670d0b9840f13]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[12fcca5210661983]::query::erase::Erased<[u8; 0usize]>>
  32:     0x709ff3387cd5 - rustc_query_system[57b45adcca80f492]::query::plumbing::try_execute_query::<rustc_query_impl[bdf670d0b9840f13]::DynamicConfig<rustc_query_system[57b45adcca80f492]::query::caches::SingleCache<rustc_middle[12fcca5210661983]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[bdf670d0b9840f13]::plumbing::QueryCtxt, false>
  33:     0x709ff3387a0e - rustc_query_impl[bdf670d0b9840f13]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  34:     0x709ff3428fe9 - rustc_interface[215e699f6d71029]::passes::create_and_enter_global_ctxt::<core[6f4bacb0707a325d]::option::Option<rustc_interface[215e699f6d71029]::queries::Linker>, rustc_driver_impl[c7b34afe4b5b317]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  35:     0x709ff3335358 - rustc_interface[215e699f6d71029]::interface::run_compiler::<(), rustc_driver_impl[c7b34afe4b5b317]::run_compiler::{closure#0}>::{closure#1}
  36:     0x709ff328a435 - std[b9fe1580bce53cbe]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[215e699f6d71029]::util::run_in_thread_with_globals<rustc_interface[215e699f6d71029]::util::run_in_thread_pool_with_globals<rustc_interface[215e699f6d71029]::interface::run_compiler<(), rustc_driver_impl[c7b34afe4b5b317]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:     0x709ff328a119 - <<std[b9fe1580bce53cbe]::thread::Builder>::spawn_unchecked_<rustc_interface[215e699f6d71029]::util::run_in_thread_with_globals<rustc_interface[215e699f6d71029]::util::run_in_thread_pool_with_globals<rustc_interface[215e699f6d71029]::interface::run_compiler<(), rustc_driver_impl[c7b34afe4b5b317]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6f4bacb0707a325d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x709ff32898af - std::sys::pal::unix::thread::Thread::new::thread_start::ha0015455dea58c72
  39:     0x709fed4a339d - <unknown>
  40:     0x709fed52849c - <unknown>
  41:                0x0 - <unknown>

error: 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: please make sure that you have updated to the latest nightly

note: rustc 1.86.0-nightly (6c1d960d8 2025-01-30) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `ref_handler` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0412, E0601, E0726.
For more information about an error, try `rustc --explain E0412`.

Metadata

Metadata

Assignees

Labels

A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityS-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions