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: escaping bound vars in predicate #131769

Closed
matthiaskrgr opened this issue Oct 16, 2024 · 0 comments · Fixed by #131789
Closed

ICE: escaping bound vars in predicate #131769

matthiaskrgr opened this issue Oct 16, 2024 · 0 comments · Fixed by #131789
Assignees
Labels
C-bug Category: This is a bug. F-precise_capturing `#![feature(precise_capturing)]` 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

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

fn size_of_val<'a>(x: &mut ()) -> impl Iterator<Item = impl Sized> + use<> {
    x
}

original:

fn lifetime_in_bounds<'a>(x: &'tr ()) -> impl Into<&'a ()> + use<> { x }
//~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list

fn size_of_val<'a>(x: &mut ()) -> impl Iterator<Item = impl Sized> + use<> { x }
//~^ ERROR hidden type for `impl Sized` captures lifetime that does not appear in bounds

fn main() {
            iter_raw -= 1;
        }

Version information

rustc 1.84.0-nightly (9ce3675b4 2024-10-15)
binary: rustc
commit-hash: 9ce3675b438aae22ef0c6147cde2003a418ab722
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zunstable-options --edition=2024

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.jJVes92ppekh/rustc_testrunner_tmpdir_reporting.5Srfjlvyeixq/mvce.rs:3:2
  |
3 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.jJVes92ppekh/rustc_testrunner_tmpdir_reporting.5Srfjlvyeixq/mvce.rs`

error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
 --> /tmp/icemaker_global_tempdir.jJVes92ppekh/rustc_testrunner_tmpdir_reporting.5Srfjlvyeixq/mvce.rs:1:35
  |
1 | fn size_of_val<'a>(x: &mut ()) -> impl Iterator<Item = impl Sized> + use<> {
  |                --                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait`
  |                |
  |                this lifetime parameter is captured

error: internal compiler error: compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs:106:13: escaping bound vars in predicate Obligation(predicate=Binder { value: ProjectionPredicate(AliasTerm { args: [?0t], def_id: DefId(2:8783 ~ core[fdc7]::iter::traits::iterator::Iterator::Item), .. }, Term::Ty(Alias(Opaque, AliasTy { args: ['a/#0, '^2_0.Named(DefId(0:7 ~ mvce[11b1]::size_of_val::'_), "'_"), 'a/#0], def_id: DefId(0:6 ~ mvce[11b1]::size_of_val::{opaque#0}::{opaque#0}), .. }))), bound_vars: [] }, depth=0)
 --> /tmp/icemaker_global_tempdir.jJVes92ppekh/rustc_testrunner_tmpdir_reporting.5Srfjlvyeixq/mvce.rs:1:35
  |
1 | fn size_of_val<'a>(x: &mut ()) -> impl Iterator<Item = impl Sized> + use<> {
  |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs:106:13:
Box<dyn Any>
stack backtrace:
   0:     0x7382d2c76daa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h525ca73b44ff3961
   1:     0x7382d340368a - core::fmt::write::h4e0877406968c391
   2:     0x7382d47a9111 - std::io::Write::write_fmt::h2bd0eeb556cd4584
   3:     0x7382d2c76c02 - std::sys::backtrace::BacktraceLock::print::h43c0f0423e8dc1a8
   4:     0x7382d2c790e6 - std::panicking::default_hook::{{closure}}::h15d7535f314f3156
   5:     0x7382d2c78f30 - std::panicking::default_hook::hdfe0b9b278f6a2d4
   6:     0x7382d1cfa68f - std[e857fc88149b8bb7]::panicking::update_hook::<alloc[14f3b7019767b1ae]::boxed::Box<rustc_driver_impl[12a88fbe870fdaff]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7382d2c797f8 - std::panicking::rust_panic_with_hook::h80214b0734ae1ad1
   8:     0x7382d1d345b1 - std[e857fc88149b8bb7]::panicking::begin_panic::<rustc_errors[9857333b1cca239b]::ExplicitBug>::{closure#0}
   9:     0x7382d1d275e6 - std[e857fc88149b8bb7]::sys::backtrace::__rust_end_short_backtrace::<std[e857fc88149b8bb7]::panicking::begin_panic<rustc_errors[9857333b1cca239b]::ExplicitBug>::{closure#0}, !>
  10:     0x7382d1d22e20 - std[e857fc88149b8bb7]::panicking::begin_panic::<rustc_errors[9857333b1cca239b]::ExplicitBug>
  11:     0x7382d1d3e061 - <rustc_errors[9857333b1cca239b]::diagnostic::BugAbort as rustc_errors[9857333b1cca239b]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7382d099d3a0 - <rustc_errors[9857333b1cca239b]::DiagCtxtHandle>::span_bug::<rustc_span[e1ff7264637c5d63]::span_encoding::Span, alloc[14f3b7019767b1ae]::string::String>
  13:     0x7382d1f93647 - rustc_middle[d8a02af54bfa0dde]::util::bug::opt_span_bug_fmt::<rustc_span[e1ff7264637c5d63]::span_encoding::Span>::{closure#0}
  14:     0x7382d1f9670a - rustc_middle[d8a02af54bfa0dde]::ty::context::tls::with_opt::<rustc_middle[d8a02af54bfa0dde]::util::bug::opt_span_bug_fmt<rustc_span[e1ff7264637c5d63]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7382d1f44c3b - rustc_middle[d8a02af54bfa0dde]::ty::context::tls::with_context_opt::<rustc_middle[d8a02af54bfa0dde]::ty::context::tls::with_opt<rustc_middle[d8a02af54bfa0dde]::util::bug::opt_span_bug_fmt<rustc_span[e1ff7264637c5d63]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7382d008fd97 - rustc_middle[d8a02af54bfa0dde]::util::bug::span_bug_fmt::<rustc_span[e1ff7264637c5d63]::span_encoding::Span>
  17:     0x7382d37c3fe9 - <rustc_hir_typeck[4162f95293710ac]::typeck_root_ctxt::TypeckRootCtxt>::register_predicate
  18:     0x7382d378ec7b - rustc_hir_typeck[4162f95293710ac]::check::check_fn
  19:     0x7382d3783393 - rustc_hir_typeck[4162f95293710ac]::typeck
  20:     0x7382d3782d0f - rustc_query_impl[6f041a62200b4f1f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f041a62200b4f1f]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>
  21:     0x7382d39044fd - rustc_query_system[6bc689bd08eb534a]::query::plumbing::try_execute_query::<rustc_query_impl[6f041a62200b4f1f]::DynamicConfig<rustc_query_system[6bc689bd08eb534a]::query::caches::VecCache<rustc_span[e1ff7264637c5d63]::def_id::LocalDefId, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6f041a62200b4f1f]::plumbing::QueryCtxt, false>
  22:     0x7382d390324d - rustc_query_impl[6f041a62200b4f1f]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7382d3d1207f - rustc_middle[d8a02af54bfa0dde]::query::plumbing::query_get_at::<rustc_query_system[6bc689bd08eb534a]::query::caches::VecCache<rustc_span[e1ff7264637c5d63]::def_id::LocalDefId, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>>
  24:     0x7382d43a26eb - rustc_hir_analysis[d00687496dda5c67]::collect::type_of::type_of_opaque
  25:     0x7382d43a2625 - rustc_query_impl[6f041a62200b4f1f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f041a62200b4f1f]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7382d34304ae - rustc_query_system[6bc689bd08eb534a]::query::plumbing::try_execute_query::<rustc_query_impl[6f041a62200b4f1f]::DynamicConfig<rustc_query_system[6bc689bd08eb534a]::query::caches::DefIdCache<rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6f041a62200b4f1f]::plumbing::QueryCtxt, false>
  27:     0x7382d45d6cf6 - rustc_query_impl[6f041a62200b4f1f]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7382d3cfc202 - rustc_middle[d8a02af54bfa0dde]::query::plumbing::query_get_at::<rustc_query_system[6bc689bd08eb534a]::query::caches::DefIdCache<rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>>
  29:     0x7382d04d5785 - rustc_hir_analysis[d00687496dda5c67]::collect::type_of::type_of
  30:     0x7382d34317b0 - rustc_query_impl[6f041a62200b4f1f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f041a62200b4f1f]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>
  31:     0x7382d34304ae - rustc_query_system[6bc689bd08eb534a]::query::plumbing::try_execute_query::<rustc_query_impl[6f041a62200b4f1f]::DynamicConfig<rustc_query_system[6bc689bd08eb534a]::query::caches::DefIdCache<rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6f041a62200b4f1f]::plumbing::QueryCtxt, false>
  32:     0x7382d3430067 - rustc_query_impl[6f041a62200b4f1f]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7382d3cfc202 - rustc_middle[d8a02af54bfa0dde]::query::plumbing::query_get_at::<rustc_query_system[6bc689bd08eb534a]::query::caches::DefIdCache<rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 8usize]>>>
  34:     0x7382d43acf90 - rustc_hir_analysis[d00687496dda5c67]::check::check::check_item_type
  35:     0x7382d0383600 - rustc_hir_analysis[d00687496dda5c67]::check::wfcheck::check_well_formed
  36:     0x7382d3bb103d - rustc_query_impl[6f041a62200b4f1f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f041a62200b4f1f]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 1usize]>>
  37:     0x7382d3bb0794 - rustc_query_system[6bc689bd08eb534a]::query::plumbing::try_execute_query::<rustc_query_impl[6f041a62200b4f1f]::DynamicConfig<rustc_query_system[6bc689bd08eb534a]::query::caches::VecCache<rustc_span[e1ff7264637c5d63]::def_id::LocalDefId, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6f041a62200b4f1f]::plumbing::QueryCtxt, false>
  38:     0x7382d3bb0410 - rustc_query_impl[6f041a62200b4f1f]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7382d3bb10bd - rustc_middle[d8a02af54bfa0dde]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[6bc689bd08eb534a]::query::caches::VecCache<rustc_span[e1ff7264637c5d63]::def_id::LocalDefId, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 1usize]>>, ()>
  40:     0x7382d3bb167f - rustc_hir_analysis[d00687496dda5c67]::check::wfcheck::check_mod_type_wf
  41:     0x7382d3bb10e5 - rustc_query_impl[6f041a62200b4f1f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f041a62200b4f1f]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 1usize]>>
  42:     0x7382d42d3afb - rustc_query_system[6bc689bd08eb534a]::query::plumbing::try_execute_query::<rustc_query_impl[6f041a62200b4f1f]::DynamicConfig<rustc_query_system[6bc689bd08eb534a]::query::caches::DefaultCache<rustc_span[e1ff7264637c5d63]::def_id::LocalModDefId, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6f041a62200b4f1f]::plumbing::QueryCtxt, false>
  43:     0x7382d42d38ad - rustc_query_impl[6f041a62200b4f1f]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7382d3900abb - rustc_hir_analysis[d00687496dda5c67]::check_crate
  45:     0x7382d38fd817 - rustc_interface[bbaab2745c9b053b]::passes::run_required_analyses
  46:     0x7382d429de1e - rustc_interface[bbaab2745c9b053b]::passes::analysis
  47:     0x7382d429ddf1 - rustc_query_impl[6f041a62200b4f1f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6f041a62200b4f1f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 1usize]>>
  48:     0x7382d42e81ae - rustc_query_system[6bc689bd08eb534a]::query::plumbing::try_execute_query::<rustc_query_impl[6f041a62200b4f1f]::DynamicConfig<rustc_query_system[6bc689bd08eb534a]::query::caches::SingleCache<rustc_middle[d8a02af54bfa0dde]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6f041a62200b4f1f]::plumbing::QueryCtxt, false>
  49:     0x7382d42e7e8f - rustc_query_impl[6f041a62200b4f1f]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  50:     0x7382d41aab5e - rustc_interface[bbaab2745c9b053b]::interface::run_compiler::<core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>, rustc_driver_impl[12a88fbe870fdaff]::run_compiler::{closure#0}>::{closure#1}
  51:     0x7382d423fe54 - std[e857fc88149b8bb7]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[bbaab2745c9b053b]::util::run_in_thread_with_globals<rustc_interface[bbaab2745c9b053b]::util::run_in_thread_pool_with_globals<rustc_interface[bbaab2745c9b053b]::interface::run_compiler<core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>, rustc_driver_impl[12a88fbe870fdaff]::run_compiler::{closure#0}>::{closure#1}, core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>>::{closure#0}, core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>>
  52:     0x7382d4240268 - <<std[e857fc88149b8bb7]::thread::Builder>::spawn_unchecked_<rustc_interface[bbaab2745c9b053b]::util::run_in_thread_with_globals<rustc_interface[bbaab2745c9b053b]::util::run_in_thread_pool_with_globals<rustc_interface[bbaab2745c9b053b]::interface::run_compiler<core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>, rustc_driver_impl[12a88fbe870fdaff]::run_compiler::{closure#0}>::{closure#1}, core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>>::{closure#0}, core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fdc7858511f3567b]::result::Result<(), rustc_span[e1ff7264637c5d63]::ErrorGuaranteed>>::{closure#1} as core[fdc7858511f3567b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:     0x7382d4240d2b - std::sys::pal::unix::thread::Thread::new::thread_start::hd84c48c307791fe8
  54:     0x7382ce4a339d - <unknown>
  55:     0x7382ce52849c - <unknown>
  56:                0x0 - <unknown>

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.84.0-nightly (9ce3675b4 2024-10-15) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck] type-checking `size_of_val`
#1 [type_of_opaque] computing type of opaque `size_of_val::{opaque#0}`
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0601`.

@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 Oct 16, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 16, 2024
@compiler-errors compiler-errors self-assigned this Oct 16, 2024
@fmease fmease added F-precise_capturing `#![feature(precise_capturing)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 16, 2024
@bors bors closed this as completed in bc22740 Oct 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 20, 2024
Rollup merge of rust-lang#131789 - compiler-errors:capture-more, r=fmease

Make sure that outer opaques capture inner opaques's lifetimes even with precise capturing syntax

When lowering an opaque, we must capture and duplicate all of the lifetimes in the opaque's bounds to correctly lower the opaque's bounds. We do this *even if* the lifetime is not captured according to the `+ use<>` precise capturing bound; in that case, we will later reject that captured lifetime. For example, Given an opaque like `impl Sized + 'a + use<>`, we will still duplicate `'a` but later error that it is not mentioned in the `use<>` bound.

The current heuristic was not properly handling cases like:

```
//@ edition: 2024
fn foo<'a>() -> impl Trait<Assoc = impl Trait2> + use<> {}
```

Which forces the outer `impl Trait` to capture `'a` since `impl Trait2` *implicitly* captures `'a` due to the new lifetime capture rules for edition 2024. We were only capturing lifetimes syntactically mentioned in the bounds. (Note that this still is an error; we just need to capture `'a` so it is handled later in the compiler correctly -- hence the ICE in rust-lang#131769 where a late-bound lifetime was being referenced outside of its binder).

This PR reworks the way we collect lifetimes to capture and duplicate in AST lowering to fix this.

Fixes rust-lang#131769
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. F-precise_capturing `#![feature(precise_capturing)]` 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
4 participants