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: None in compiler/rustc_borrowck/src/region_infer/opaque_types.rs #137015

Closed
matthiaskrgr opened this issue Feb 14, 2025 · 3 comments · Fixed by #137102
Closed

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

matthiaskrgr opened this issue Feb 14, 2025 · 3 comments · Fixed by #137102
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

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`.

@matthiaskrgr matthiaskrgr 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 14, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 14, 2025
@matthiaskrgr
Copy link
Member Author

bisects to #136559

@cyrgani
Copy link
Contributor

cyrgani commented Feb 14, 2025

simpler:

trait AnotherTrait {
    type Ty2<'a>;
}

fn test_alias<T: AnotherTrait>(_: &'static T::Ty2<'_>) {
    let _: &'static T::Ty2<'_>;
}

@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue S-has-bisection Status: a bisection has been found for this issue A-borrow-checker Area: The borrow checker and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 14, 2025
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Feb 14, 2025

//@ compile-flags: --edition=2024
fn opaque<'a: 'a>() -> impl Sized {}
fn assert_static<T: 'static>(_: T) {}

fn test_closure() {
    let closure = |_| {
        assert_static(opaque());
    };
    closure(&opaque());
}

pub fn main() {}

also gives a

error: internal compiler error: TypeTestError { type_test: TypeTest { generic_kind: AliasTy { args: ['?7, '?8], def_id: DefId(0:5 ~ oo[fc24]::opaque::{opaque#0}), .. }, lower_bound: '?0, span: oo.rs:6:9: 6:32 (#0), verify_bound: AnyBound([AnyBound([IfEq(Binder { value: VerifyIfEq { ty: Alias(Opaque, AliasTy { args: ['?2, '?3], def_id: DefId(0:5 ~ oo[fc24]::opaque::{opaque#0}), .. }), bound: '?1 }, bound_vars: [] })]), OutlivedBy('?8)]) } }
  |
  = note: delayed at compiler/rustc_borrowck/src/region_infer/mod.rs:941:31 - disabled backtrace

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: please attach the file at `/tmp/im/rustc-ice-2025-02-14T15_18_01-3965700.txt` to your bug report

query stack during panic:
end of query stack

on top, and goes from compile -> ice with --edition=2024

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 16, 2025
…li-obk

Rework `name_regions` to not rely on reverse scc graph for non-member-constrain usages

Fixes rust-lang#137015

Splits the `name_regions` into two versions: One meant for member region constraint error reporting (which I've renamed to `name_regions_for_member_constraint`), and one meant *just* to replace region vids with an external region.

Use the latter in the usage sites I added in rust-lang#136559, since the regions returned by `name_regions_for_member_constraint` are also not *totally* accurate (which is fine for how they're used for member region constraint error reporting -- they're intentionally returning overapproximated universal regions so that we have something to name in `+ use<'a>` suggestions, because opaques can only capture universal regions and since member region constraints don't insert any edges into the region graph, the error region is probably gonna be shorter than a universal region) and because that function requires the reverse scc graph to have been computed which isn't done for our usages in rust-lang#136559.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 16, 2025
…li-obk

Rework `name_regions` to not rely on reverse scc graph for non-member-constrain usages

Fixes rust-lang#137015

Splits the `name_regions` into two versions: One meant for member region constraint error reporting (which I've renamed to `name_regions_for_member_constraint`), and one meant *just* to replace region vids with an external region.

Use the latter in the usage sites I added in rust-lang#136559, since the regions returned by `name_regions_for_member_constraint` are also not *totally* accurate (which is fine for how they're used for member region constraint error reporting -- they're intentionally returning overapproximated universal regions so that we have something to name in `+ use<'a>` suggestions, because opaques can only capture universal regions and since member region constraints don't insert any edges into the region graph, the error region is probably gonna be shorter than a universal region) and because that function requires the reverse scc graph to have been computed which isn't done for our usages in rust-lang#136559.
@bors bors closed this as completed in ea9c8d9 Feb 17, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 17, 2025
Rollup merge of rust-lang#137102 - compiler-errors:name_regions2, r=oli-obk

Rework `name_regions` to not rely on reverse scc graph for non-member-constrain usages

Fixes rust-lang#137015

Splits the `name_regions` into two versions: One meant for member region constraint error reporting (which I've renamed to `name_regions_for_member_constraint`), and one meant *just* to replace region vids with an external region.

Use the latter in the usage sites I added in rust-lang#136559, since the regions returned by `name_regions_for_member_constraint` are also not *totally* accurate (which is fine for how they're used for member region constraint error reporting -- they're intentionally returning overapproximated universal regions so that we have something to name in `+ use<'a>` suggestions, because opaques can only capture universal regions and since member region constraints don't insert any edges into the region graph, the error region is probably gonna be shorter than a universal region) and because that function requires the reverse scc graph to have been computed which isn't done for our usages in rust-lang#136559.
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Feb 17, 2025
Rework `name_regions` to not rely on reverse scc graph for non-member-constrain usages

Fixes rust-lang/rust#137015

Splits the `name_regions` into two versions: One meant for member region constraint error reporting (which I've renamed to `name_regions_for_member_constraint`), and one meant *just* to replace region vids with an external region.

Use the latter in the usage sites I added in #136559, since the regions returned by `name_regions_for_member_constraint` are also not *totally* accurate (which is fine for how they're used for member region constraint error reporting -- they're intentionally returning overapproximated universal regions so that we have something to name in `+ use<'a>` suggestions, because opaques can only capture universal regions and since member region constraints don't insert any edges into the region graph, the error region is probably gonna be shorter than a universal region) and because that function requires the reverse scc graph to have been computed which isn't done for our usages in #136559.
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 C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants