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: expected lifetime parameter, but found another generic parameter #129850

Closed
matthiaskrgr opened this issue Sep 1, 2024 · 1 comment · Fixed by #130412
Closed

ICE: expected lifetime parameter, but found another generic parameter #129850

matthiaskrgr opened this issue Sep 1, 2024 · 1 comment · Fixed by #130412
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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):

pub trait Foo2 {
    fn bar<'a: 'a>(&'a mut self) -> impl Sized + use<'static>;
}

impl Foo2 for () {
    fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a {}
}

original:

//@ check-pass
//@ edition:2021

pub trait Foo {
    #[allow(async_fn_in_trait)]
    async fn bar<'a: 'a>(&'a mut self);
}

impl Foo for () {
    async fn bar<'a: 'a>(&'a mut self) {}
}

pub trait Foo2 {
    fn bar<'a: 'a>(&'a mut self) -> impl Sized + use<'static>;
}

impl Foo2 for () {
    fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a {}
}

fn main() {}

Version information

rustc 1.82.0-nightly (a7399ba69 2024-08-31)
binary: rustc
commit-hash: a7399ba69d37b019677a9c47fe89ceb8dd82db2d
commit-date: 2024-08-31
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

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

Program output

error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
 --> /tmp/icemaker_global_tempdir.xgv2FYp3RLcf/rustc_testrunner_tmpdir_reporting.fx0w6Esy9qlw/mvce.rs:2:50
  |
2 |     fn bar<'a: 'a>(&'a mut self) -> impl Sized + use<'static>;
  |                                                  ^^^^^^^^^^^^
  |
  = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope

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

error: expected lifetime parameter in `use<...>` precise captures list, found `'static`
 --> /tmp/icemaker_global_tempdir.xgv2FYp3RLcf/rustc_testrunner_tmpdir_reporting.fx0w6Esy9qlw/mvce.rs:2:54
  |
2 |     fn bar<'a: 'a>(&'a mut self) -> impl Sized + use<'static>;
  |                                                      ^^^^^^^

error: `impl Trait` must mention the `Self` type of the trait in `use<...>`
 --> /tmp/icemaker_global_tempdir.xgv2FYp3RLcf/rustc_testrunner_tmpdir_reporting.fx0w6Esy9qlw/mvce.rs:2:37
  |
1 | pub trait Foo2 {
  | -------------- `Self` type parameter is implicitly captured by this `impl Trait`
2 |     fn bar<'a: 'a>(&'a mut self) -> impl Sized + use<'static>;
  |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: currently, all type parameters are required to be mentioned in the precise captures list

error: internal compiler error: compiler/rustc_middle/src/ty/generics.rs:258:18: expected lifetime parameter, but found another generic parameter

thread 'rustc' panicked at compiler/rustc_middle/src/ty/generics.rs:258:18:
Box<dyn Any>
stack backtrace:
   0:     0x79ccab5fed9a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::ha8b6a03154ea19c3
   1:     0x79ccabe03157 - core::fmt::write::hb1fec16e33daff29
   2:     0x79ccacde7fd1 - std::io::Write::write_fmt::h890fd89091c43625
   3:     0x79ccab60146b - std::panicking::default_hook::{{closure}}::h8e59b6e48c542f1f
   4:     0x79ccab6010de - std::panicking::default_hook::he45ee90607527b0d
   5:     0x79ccaa75f349 - std[70086fc653812fb1]::panicking::update_hook::<alloc[5793336eebe11ba]::boxed::Box<rustc_driver_impl[bde591410b6ce234]::install_ice_hook::{closure#0}>>::{closure#0}
   6:     0x79ccab601d87 - std::panicking::rust_panic_with_hook::h57f9e7cd2d85b015
   7:     0x79ccaa799551 - std[70086fc653812fb1]::panicking::begin_panic::<rustc_errors[d71da989a5965fd6]::ExplicitBug>::{closure#0}
   8:     0x79ccaa78cc16 - std[70086fc653812fb1]::sys::backtrace::__rust_end_short_backtrace::<std[70086fc653812fb1]::panicking::begin_panic<rustc_errors[d71da989a5965fd6]::ExplicitBug>::{closure#0}, !>
   9:     0x79ccaa787f66 - std[70086fc653812fb1]::panicking::begin_panic::<rustc_errors[d71da989a5965fd6]::ExplicitBug>
  10:     0x79ccaa7a2771 - <rustc_errors[d71da989a5965fd6]::diagnostic::BugAbort as rustc_errors[d71da989a5965fd6]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x79ccaad6b764 - rustc_middle[454e73a6dc67a815]::util::bug::opt_span_bug_fmt::<rustc_span[fcf79a5fd0f12046]::span_encoding::Span>::{closure#0}
  12:     0x79ccaad5131a - rustc_middle[454e73a6dc67a815]::ty::context::tls::with_opt::<rustc_middle[454e73a6dc67a815]::util::bug::opt_span_bug_fmt<rustc_span[fcf79a5fd0f12046]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x79ccaad511cb - rustc_middle[454e73a6dc67a815]::ty::context::tls::with_context_opt::<rustc_middle[454e73a6dc67a815]::ty::context::tls::with_opt<rustc_middle[454e73a6dc67a815]::util::bug::opt_span_bug_fmt<rustc_span[fcf79a5fd0f12046]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x79cca88b3b40 - rustc_middle[454e73a6dc67a815]::util::bug::bug_fmt
  15:     0x79ccad6c4b01 - <rustc_middle[454e73a6dc67a815]::ty::generics::Generics>::region_param.cold
  16:     0x79cca92b7418 - <rustc_middle[454e73a6dc67a815]::ty::region::Region>::opt_param_def_id
  17:     0x79ccaa8e6a0c - <rustc_hir_analysis[7408769f7e89f40d]::check::compare_impl_item::RemapHiddenTyRegions as rustc_type_ir[5ab55af5d1323a37]::fold::FallibleTypeFolder<rustc_middle[454e73a6dc67a815]::ty::context::TyCtxt>>::try_fold_region
  18:     0x79ccaa86d7cf - <rustc_middle[454e73a6dc67a815]::ty::generic_args::GenericArg as rustc_type_ir[5ab55af5d1323a37]::fold::TypeFoldable<rustc_middle[454e73a6dc67a815]::ty::context::TyCtxt>>::try_fold_with::<rustc_hir_analysis[7408769f7e89f40d]::check::compare_impl_item::RemapHiddenTyRegions>
  19:     0x79ccaa8e6325 - <rustc_hir_analysis[7408769f7e89f40d]::check::compare_impl_item::RemapHiddenTyRegions as rustc_type_ir[5ab55af5d1323a37]::fold::FallibleTypeFolder<rustc_middle[454e73a6dc67a815]::ty::context::TyCtxt>>::try_fold_ty
  20:     0x79ccaa92c8ee - rustc_hir_analysis[7408769f7e89f40d]::check::compare_impl_item::collect_return_position_impl_trait_in_trait_tys::{closure#0}
  21:     0x79ccab13bcf3 - rustc_query_impl[9d4e2ec78ebde536]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4e2ec78ebde536]::query_impl::collect_return_position_impl_trait_in_trait_tys::dynamic_query::{closure#2}::{closure#0}, rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 8usize]>>
  22:     0x79ccabfa9dee - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::<rustc_query_impl[9d4e2ec78ebde536]::DynamicConfig<rustc_query_system[d8e0298fbce79578]::query::caches::DefIdCache<rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9d4e2ec78ebde536]::plumbing::QueryCtxt, false>
  23:     0x79ccab13f6ce - rustc_query_impl[9d4e2ec78ebde536]::query_impl::collect_return_position_impl_trait_in_trait_tys::get_query_non_incr::__rust_end_short_backtrace
  24:     0x79ccac3cd0c0 - rustc_middle[454e73a6dc67a815]::query::plumbing::query_get_at::<rustc_query_system[d8e0298fbce79578]::query::caches::DefIdCache<rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 8usize]>>>
  25:     0x79cca8f5af7e - rustc_hir_analysis[7408769f7e89f40d]::collect::type_of::type_of
  26:     0x79ccabfab1aa - rustc_query_impl[9d4e2ec78ebde536]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4e2ec78ebde536]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 8usize]>>
  27:     0x79ccabfa9dee - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::<rustc_query_impl[9d4e2ec78ebde536]::DynamicConfig<rustc_query_system[d8e0298fbce79578]::query::caches::DefIdCache<rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9d4e2ec78ebde536]::plumbing::QueryCtxt, false>
  28:     0x79ccabfa99a7 - rustc_query_impl[9d4e2ec78ebde536]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  29:     0x79ccac3cd0c0 - rustc_middle[454e73a6dc67a815]::query::plumbing::query_get_at::<rustc_query_system[d8e0298fbce79578]::query::caches::DefIdCache<rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 8usize]>>>
  30:     0x79cca95946d0 - rustc_hir_analysis[7408769f7e89f40d]::check::wfcheck::check_well_formed
  31:     0x79ccac779bc7 - rustc_query_impl[9d4e2ec78ebde536]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4e2ec78ebde536]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 1usize]>>
  32:     0x79ccac779e3e - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::<rustc_query_impl[9d4e2ec78ebde536]::DynamicConfig<rustc_query_system[d8e0298fbce79578]::query::caches::VecCache<rustc_hir[efc26d3c0a3a24aa]::hir_id::OwnerId, rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9d4e2ec78ebde536]::plumbing::QueryCtxt, false>
  33:     0x79ccac779ba2 - rustc_query_impl[9d4e2ec78ebde536]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  34:     0x79ccac77a97f - rustc_hir_analysis[7408769f7e89f40d]::check::wfcheck::check_mod_type_wf
  35:     0x79ccac77a79f - rustc_query_impl[9d4e2ec78ebde536]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4e2ec78ebde536]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 1usize]>>
  36:     0x79ccac778e7b - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::<rustc_query_impl[9d4e2ec78ebde536]::DynamicConfig<rustc_query_system[d8e0298fbce79578]::query::caches::DefaultCache<rustc_span[fcf79a5fd0f12046]::def_id::LocalModDefId, rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9d4e2ec78ebde536]::plumbing::QueryCtxt, false>
  37:     0x79ccac778c2d - rustc_query_impl[9d4e2ec78ebde536]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  38:     0x79ccac0bb03b - rustc_hir_analysis[7408769f7e89f40d]::check_crate
  39:     0x79ccac5ed73f - rustc_interface[71f2dea45baddd28]::passes::run_required_analyses
  40:     0x79ccacc9a65e - rustc_interface[71f2dea45baddd28]::passes::analysis
  41:     0x79ccacc9a631 - rustc_query_impl[9d4e2ec78ebde536]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4e2ec78ebde536]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 1usize]>>
  42:     0x79ccacd79cae - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::<rustc_query_impl[9d4e2ec78ebde536]::DynamicConfig<rustc_query_system[d8e0298fbce79578]::query::caches::SingleCache<rustc_middle[454e73a6dc67a815]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9d4e2ec78ebde536]::plumbing::QueryCtxt, false>
  43:     0x79ccacd79a0f - rustc_query_impl[9d4e2ec78ebde536]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  44:     0x79ccacba2dae - rustc_interface[71f2dea45baddd28]::interface::run_compiler::<core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>, rustc_driver_impl[bde591410b6ce234]::run_compiler::{closure#0}>::{closure#1}
  45:     0x79ccacc555d0 - std[70086fc653812fb1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[71f2dea45baddd28]::util::run_in_thread_with_globals<rustc_interface[71f2dea45baddd28]::util::run_in_thread_pool_with_globals<rustc_interface[71f2dea45baddd28]::interface::run_compiler<core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>, rustc_driver_impl[bde591410b6ce234]::run_compiler::{closure#0}>::{closure#1}, core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>>::{closure#0}, core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>>
  46:     0x79ccacc55c3a - <<std[70086fc653812fb1]::thread::Builder>::spawn_unchecked_<rustc_interface[71f2dea45baddd28]::util::run_in_thread_with_globals<rustc_interface[71f2dea45baddd28]::util::run_in_thread_pool_with_globals<rustc_interface[71f2dea45baddd28]::interface::run_compiler<core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>, rustc_driver_impl[bde591410b6ce234]::run_compiler::{closure#0}>::{closure#1}, core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>>::{closure#0}, core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d1a550dca8d22a5b]::result::Result<(), rustc_span[fcf79a5fd0f12046]::ErrorGuaranteed>>::{closure#1} as core[d1a550dca8d22a5b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:     0x79ccacc55fab - std::sys::pal::unix::thread::Thread::new::thread_start::h6f36a038c6277257
  48:     0x79ccae31839d - <unknown>
  49:     0x79ccae39d49c - <unknown>
  50:                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.82.0-nightly (a7399ba69 2024-08-31) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [collect_return_position_impl_trait_in_trait_tys] comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process
#1 [type_of] computing type of `<impl at /tmp/icemaker_global_tempdir.xgv2FYp3RLcf/rustc_testrunner_tmpdir_reporting.fx0w6Esy9qlw/mvce.rs:5:1: 5:17>::{synthetic#0}`
end of query stack
error: aborting due to 5 previous errors

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

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Sep 1, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 1, 2024
@matthiaskrgr
Copy link
Member Author

#126049 cc @compiler-errors

@compiler-errors compiler-errors self-assigned this Sep 1, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 1, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 16, 2024
…, r=jieyouxu

Don't ICE when RPITIT captures more method args than trait definition

Make sure we don't ICE when an RPITIT captures more method args than the trait definition, which is not allowed. This was because we were using the wrong def id for error reporting.

Due to the default lifetime capture rules of RPITITs (capturing everything in scope), this is only doable if we use precise capturing, which isn't currently allowed for RPITITs anyways but we still end up reaching the relevant codepaths.

Fixes rust-lang#129850
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Sep 16, 2024
@bors bors closed this as completed in 4e68d06 Sep 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 16, 2024
Rollup merge of rust-lang#130412 - compiler-errors:rpitit-overcapture, r=jieyouxu

Don't ICE when RPITIT captures more method args than trait definition

Make sure we don't ICE when an RPITIT captures more method args than the trait definition, which is not allowed. This was because we were using the wrong def id for error reporting.

Due to the default lifetime capture rules of RPITITs (capturing everything in scope), this is only doable if we use precise capturing, which isn't currently allowed for RPITITs anyways but we still end up reaching the relevant codepaths.

Fixes rust-lang#129850
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) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

4 participants