Skip to content

ICE: None in compiler/rustc_borrowck/src/region_infer/opaque_types.rs #137015

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//

trait Trait {
    type Ty<'a>
    where
        Self: 'struct_span_err;
}

impl<T> Trait for T {
    type Ty<'a>;
}

struct Foo<T: Trait>(T)
where
    for<'x> T::Ty<'x>: Sized;

trait AnotherTrait {
    type Ty2<'a>: 'a;
}

mod pass {
    use super::*;

    fn test_alias<T: AnotherTrait>(_: Foo<T::Ty2<'static>>) {
        None::<&'static T::Ty2<'_>>;
    }
}
original code

original:

// Because of #109628, when we compute the implied bounds from `Foo<X>`,
// we incorrectly get `X: placeholder('x)`.
// Make sure we ignore these bogus bounds and not use them for anything useful.
//
//@ revisions: fail pass
//@ [fail] check-fail
//@ [pass] check-pass

trait Trait {
    type Ty<'a> where Self: 'struct_span_err;
}

impl<T> Trait for T {
    type Ty<'a> = () where Self: 'let_binding;
}

struct Foo<T: Trait>(T)
where
    for<'x> T::Ty<'x>: Sized;

trait AnotherTrait {
    type Ty2<'a>: 'a;
}

#[cfg(fail)]
mod fail {
    use super::*;

    // implied_bound: `'lt: placeholder('x)`.
    // don't use the bound to prove `'lt: 'static`.
    fn test_lifetime<'lt, T: Trait>(_: Foo<&'lt u8>) {}
    //[fail]~^ ERROR `&'lt u8` does not fulfill the required lifetime

    // implied bound: `T::Ty2<'lt>: placeholder('x)`.
    // don't use the bound to prove `T::Ty2<'lt>: 'static`.
    fn test_alias<'lt, T: AnotherTrait>(_: Foo<T::Ty2::<'lt>>) {}
    //[fail]~^ ERROR `<T as AnotherTrait>::Ty2<'lt>` does not fulfill the required lifetime
}


mod pass {
    use super::*;

    // implied_bound: 'static: placeholder('x).
    // don't ice.
    fn test_lifetime<T: Trait>(_: Foo<&'static u8>) {}

    // implied bound: T::Ty2<'static>: placeholder('x).
    // don't add the bound to the environment,
    // otherwise we would fail to infer a value for `'_`.
    fn test_alias<T: AnotherTrait>(_: Foo<T::Ty2::<'static>>) {
        None::<&'static T::Ty2<'_>>;
    }
}

fn main() {}

Version information

rustc 1.86.0-nightly (6dfeab5c9 2025-02-14)
binary: rustc
commit-hash: 6dfeab5c9e8a17a6636c1479037baabc4b1e9562
commit-date: 2025-02-14
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Possibly related line of code:

// region which cannot be mapped back to a universal.
// FIXME: We could probably compute the LUB if there is one.
let scc = self.constraint_sccs.scc(vid);
let upper_bounds: Vec<_> = self
.rev_scc_graph
.as_ref()
.unwrap()
.upper_bounds(scc)
.filter_map(|vid| self.definitions[vid].external_name)
.filter(|r| !r.is_static())
.collect();
match &upper_bounds[..] {
[universal_region] => *universal_region,

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

Program output

error: associated type in `impl` without body
  --> /tmp/icemaker_global_tempdir.hN8j0cdu6r1n/rustc_testrunner_tmpdir_reporting.79zD3G9GtaBT/mvce.rs:10:5
   |
10 |     type Ty<'a>;
   |     ^^^^^^^^^^^-
   |                |
   |                help: provide a definition for the type: `= <type>;`

error[E0261]: use of undeclared lifetime name `'struct_span_err`
 --> /tmp/icemaker_global_tempdir.hN8j0cdu6r1n/rustc_testrunner_tmpdir_reporting.79zD3G9GtaBT/mvce.rs:6:15
  |
6 |         Self: 'struct_span_err;
  |               ^^^^^^^^^^^^^^^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'struct_span_err` lifetime
  |
6 |         for<'struct_span_err> Self: 'struct_span_err;
  |         +++++++++++++++++++++
help: consider introducing lifetime `'struct_span_err` here
  |
4 |     type Ty<'struct_span_err, 'a>
  |             +++++++++++++++++
help: consider introducing lifetime `'struct_span_err` here
  |
3 | trait Trait<'struct_span_err> {
  |            ++++++++++++++++++

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.hN8j0cdu6r1n/rustc_testrunner_tmpdir_reporting.79zD3G9GtaBT/mvce.rs:27:2
   |
27 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.hN8j0cdu6r1n/rustc_testrunner_tmpdir_reporting.79zD3G9GtaBT/mvce.rs`


thread 'rustc' panicked at compiler/rustc_borrowck/src/region_infer/opaque_types.rs:242:22:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7d7531c437a0 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4f1eb161fd669751
   1:     0x7d75324289bc - core::fmt::write::h8f3d79d0bacbf38a
   2:     0x7d7533730211 - std::io::Write::write_fmt::he3fb3ce41f2c821e
   3:     0x7d7531c43602 - std::sys::backtrace::BacktraceLock::print::h566559f52abce1a4
   4:     0x7d7531c45a82 - std::panicking::default_hook::{{closure}}::h52d57926d1e0801d
   5:     0x7d7531c4590a - std::panicking::default_hook::hdddb4e5f129f3d7f
   6:     0x7d7530da6c59 - std[61950067e9255cb3]::panicking::update_hook::<alloc[e5979b76aea60545]::boxed::Box<rustc_driver_impl[92bbd7ccf005646e]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7d7531c46603 - std::panicking::rust_panic_with_hook::h5ebe3eb95e5390f4
   8:     0x7d7531c462c6 - std::panicking::begin_panic_handler::{{closure}}::hf8950f7ddefd197a
   9:     0x7d7531c43c89 - std::sys::backtrace::__rust_end_short_backtrace::he5b741057a4efbd2
  10:     0x7d7531c45fbd - rust_begin_unwind
  11:     0x7d752e840870 - core::panicking::panic_fmt::h51697c8ae8e0ddcc
  12:     0x7d752f22cd0c - core::panicking::panic::ha99887d0079ca452
  13:     0x7d752f90a319 - core::option::unwrap_failed::h2bef899941cbc9da
  14:     0x7d7530b6e010 - <rustc_borrowck[adf0091226712d0d]::region_infer::RegionInferenceContext>::name_regions::<rustc_type_ir[8a6fde73c0e8b0f7]::opaque_ty::OpaqueTypeKey<rustc_middle[dee534b662d42444]::ty::context::TyCtxt>>::{closure#0}
  15:     0x7d7532456a20 - <&rustc_middle[dee534b662d42444]::ty::list::RawList<(), rustc_middle[dee534b662d42444]::ty::generic_args::GenericArg> as rustc_type_ir[8a6fde73c0e8b0f7]::fold::TypeFoldable<rustc_middle[dee534b662d42444]::ty::context::TyCtxt>>::try_fold_with::<rustc_type_ir[8a6fde73c0e8b0f7]::fold::RegionFolder<rustc_middle[dee534b662d42444]::ty::context::TyCtxt>>
  16:     0x7d7532457eb0 - <rustc_middle[dee534b662d42444]::ty::Ty as rustc_type_ir[8a6fde73c0e8b0f7]::fold::TypeSuperFoldable<rustc_middle[dee534b662d42444]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_type_ir[8a6fde73c0e8b0f7]::fold::RegionFolder<rustc_middle[dee534b662d42444]::ty::context::TyCtxt>>
  17:     0x7d7533478827 - rustc_borrowck[adf0091226712d0d]::do_mir_borrowck
  18:     0x7d753345c32f - rustc_query_impl[23c339649fd70286]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[23c339649fd70286]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dee534b662d42444]::query::erase::Erased<[u8; 8usize]>>
  19:     0x7d7532861bd7 - rustc_query_system[d79beeb7d59ca235]::query::plumbing::try_execute_query::<rustc_query_impl[23c339649fd70286]::DynamicConfig<rustc_data_structures[c93e991b8af1d823]::vec_cache::VecCache<rustc_span[bb203ea5baae0fb]::def_id::LocalDefId, rustc_middle[dee534b662d42444]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[d79beeb7d59ca235]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[23c339649fd70286]::plumbing::QueryCtxt, false>
  20:     0x7d75328616cd - rustc_query_impl[23c339649fd70286]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7d753285b01c - rustc_interface[107b5265650a1327]::passes::run_required_analyses
  22:     0x7d7532e9c39e - rustc_interface[107b5265650a1327]::passes::analysis
  23:     0x7d7532e9c36f - rustc_query_impl[23c339649fd70286]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[23c339649fd70286]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dee534b662d42444]::query::erase::Erased<[u8; 0usize]>>
  24:     0x7d7533374255 - rustc_query_system[d79beeb7d59ca235]::query::plumbing::try_execute_query::<rustc_query_impl[23c339649fd70286]::DynamicConfig<rustc_query_system[d79beeb7d59ca235]::query::caches::SingleCache<rustc_middle[dee534b662d42444]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[23c339649fd70286]::plumbing::QueryCtxt, false>
  25:     0x7d7533373f8e - rustc_query_impl[23c339649fd70286]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7d75332eb9e9 - rustc_interface[107b5265650a1327]::passes::create_and_enter_global_ctxt::<core[220235166cfaad2]::option::Option<rustc_interface[107b5265650a1327]::queries::Linker>, rustc_driver_impl[92bbd7ccf005646e]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  27:     0x7d7533353d66 - rustc_interface[107b5265650a1327]::interface::run_compiler::<(), rustc_driver_impl[92bbd7ccf005646e]::run_compiler::{closure#0}>::{closure#1}
  28:     0x7d75332836c4 - std[61950067e9255cb3]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[107b5265650a1327]::util::run_in_thread_with_globals<rustc_interface[107b5265650a1327]::util::run_in_thread_pool_with_globals<rustc_interface[107b5265650a1327]::interface::run_compiler<(), rustc_driver_impl[92bbd7ccf005646e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x7d7533283399 - <<std[61950067e9255cb3]::thread::Builder>::spawn_unchecked_<rustc_interface[107b5265650a1327]::util::run_in_thread_with_globals<rustc_interface[107b5265650a1327]::util::run_in_thread_pool_with_globals<rustc_interface[107b5265650a1327]::interface::run_compiler<(), rustc_driver_impl[92bbd7ccf005646e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[220235166cfaad2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7d7533282b2b - std::sys::pal::unix::thread::Thread::new::thread_start::h731a53e3b2196cf6
  31:     0x7d752d45f39d - <unknown>
  32:     0x7d752d4e449c - <unknown>
  33:                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 (6dfeab5c9 2025-02-14) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `pass::test_alias`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions