rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.84k stars 12.51k forks source link

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

Closed matthiaskrgr closed 1 day ago

matthiaskrgr commented 2 weeks ago

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 stack backtrace: 0: 0x79ccab5fed9a - ::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::>::{closure#0} 6: 0x79ccab601d87 - std::panicking::rust_panic_with_hook::h57f9e7cd2d85b015 7: 0x79ccaa799551 - std[70086fc653812fb1]::panicking::begin_panic::::{closure#0} 8: 0x79ccaa78cc16 - std[70086fc653812fb1]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x79ccaa787f66 - std[70086fc653812fb1]::panicking::begin_panic:: 10: 0x79ccaa7a2771 - ::emit_producing_guarantee 11: 0x79ccaad6b764 - rustc_middle[454e73a6dc67a815]::util::bug::opt_span_bug_fmt::::{closure#0} 12: 0x79ccaad5131a - rustc_middle[454e73a6dc67a815]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 13: 0x79ccaad511cb - rustc_middle[454e73a6dc67a815]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 14: 0x79cca88b3b40 - rustc_middle[454e73a6dc67a815]::util::bug::bug_fmt 15: 0x79ccad6c4b01 - ::region_param.cold 16: 0x79cca92b7418 - ::opt_param_def_id 17: 0x79ccaa8e6a0c - >::try_fold_region 18: 0x79ccaa86d7cf - >::try_fold_with:: 19: 0x79ccaa8e6325 - >::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::> 22: 0x79ccabfa9dee - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::>, 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::>> 25: 0x79cca8f5af7e - rustc_hir_analysis[7408769f7e89f40d]::collect::type_of::type_of 26: 0x79ccabfab1aa - rustc_query_impl[9d4e2ec78ebde536]::plumbing::__rust_begin_short_backtrace::> 27: 0x79ccabfa9dee - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::>, 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::>> 30: 0x79cca95946d0 - rustc_hir_analysis[7408769f7e89f40d]::check::wfcheck::check_well_formed 31: 0x79ccac779bc7 - rustc_query_impl[9d4e2ec78ebde536]::plumbing::__rust_begin_short_backtrace::> 32: 0x79ccac779e3e - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::>, 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::> 36: 0x79ccac778e7b - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::>, 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::> 42: 0x79ccacd79cae - rustc_query_system[d8e0298fbce79578]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[bde591410b6ce234]::run_compiler::{closure#0}>::{closure#1} 45: 0x79ccacc555d0 - std[70086fc653812fb1]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - 49: 0x79ccae39d49c - 50: 0x0 - 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 `::{synthetic#0}` end of query stack error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0601`. ```

matthiaskrgr commented 2 weeks ago

126049 cc @compiler-errors