rust-lang / rust

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

ICE with nested impl and closure capture #117802

Closed jruderman closed 10 months ago

jruderman commented 11 months ago

Found with a modified fuzz-rustc

Code

trait T {}

fn f() -> impl Fn(impl T) {
    let p = ();
    |_| p
}

fn main() {}

The ICE occurs with --edition=2021 but not with --edition=2018

Error output

error[E0666]: nested impl Trait is not allowed

error[E0562]: impl Trait only allowed in function and inherent method argument and return types, not in Fn trait params

thread 'rustc' panicked at compiler/rustc_mir_build/src/build/expr/as_place.rs:253:31: called Option::unwrap() on a None value

Full output including backtrace ``` error[E0666]: nested `impl Trait` is not allowed --> src/main.rs:3:19 | 3 | fn f() -> impl Fn(impl T) { | --------^^^^^^- | | | | | nested `impl Trait` here | outer `impl Trait` error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `Fn` trait params --> src/main.rs:3:19 | 3 | fn f() -> impl Fn(impl T) { | ^^^^^^ thread 'rustc' panicked at compiler/rustc_mir_build/src/build/expr/as_place.rs:253:31: called `Option::unwrap()` on a `None` value stack backtrace: 0: 0x101ba629b - ::fmt::h47b89dfc1056a325 1: 0x101c01f03 - core::fmt::write::h5d68fbe2da19f28b 2: 0x101b9c6ae - std::io::Write::write_fmt::h88f43327f33ae491 3: 0x101ba6079 - std::sys_common::backtrace::print::h5e901b20eaadd8d9 4: 0x101ba9245 - std::panicking::default_hook::{{closure}}::h8c7a1b1f76e41deb 5: 0x101ba8fc4 - std::panicking::default_hook::haa88fb66995109d3 6: 0x1118d27ae - as core[bc4f2b6eb0b2df1c]::ops::function::Fn<(&dyn for<'a, 'b> core[bc4f2b6eb0b2df1c]::ops::function::Fn<(&'a core[bc4f2b6eb0b2df1c]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[bc4f2b6eb0b2df1c]::marker::Send + core[bc4f2b6eb0b2df1c]::marker::Sync, &core[bc4f2b6eb0b2df1c]::panic::panic_info::PanicInfo)>>::call 7: 0x101ba98e5 - std::panicking::rust_panic_with_hook::h1d8fecf8796034a5 8: 0x101ba964c - std::panicking::begin_panic_handler::{{closure}}::hb6fd7b02e92de3d2 9: 0x101ba6779 - std::sys_common::backtrace::__rust_end_short_backtrace::hc0896fbb75ca2467 10: 0x101ba93d2 - _rust_begin_unwind 11: 0x101c2bb85 - core::panicking::panic_fmt::hbf1cd1e15e487a46 12: 0x101c2bc17 - core::panicking::panic::ha5648d053fcea7cf 13: 0x1125ca0f0 - ::expr_into_dest 14: 0x1125ccc78 - ::in_scope::<::expr_into_dest::{closure#0}::{closure#0}, ()> 15: 0x1125ca82d - ::expr_into_dest::{closure#0} 16: 0x1125c7656 - ::expr_into_dest 17: 0x1125ccc78 - ::in_scope::<::expr_into_dest::{closure#0}::{closure#0}, ()> 18: 0x1125ca82d - ::expr_into_dest::{closure#0} 19: 0x1125c7656 - ::expr_into_dest 20: 0x1125a3c09 - rustc_mir_build[27120349ba8a14dd]::build::mir_build::{closure#0} 21: 0x1125a22e3 - rustc_mir_build[27120349ba8a14dd]::build::mir_built 22: 0x112d5392f - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 23: 0x112eab90c - >::call_once 24: 0x112d0241f - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 25: 0x112d90ccb - rustc_query_impl[1f7dbace0c76e519]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 26: 0x1127496ca - rustc_middle[64d5e69fdab215c5]::query::plumbing::query_get_at::>> 27: 0x112765e70 - rustc_mir_transform[7673fa52c4d14ac1]::check_unsafety::unsafety_check_result 28: 0x112d5156f - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 29: 0x112ea94fc - >::call_once 30: 0x112d0241f - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 31: 0x112d990ab - rustc_query_impl[1f7dbace0c76e519]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace 32: 0x1127496ca - rustc_middle[64d5e69fdab215c5]::query::plumbing::query_get_at::>> 33: 0x1127642a6 - ::visit_rvalue 34: 0x112766120 - rustc_mir_transform[7673fa52c4d14ac1]::check_unsafety::unsafety_check_result 35: 0x112d5156f - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 36: 0x112ea94fc - >::call_once 37: 0x112d0241f - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 38: 0x112d990ab - rustc_query_impl[1f7dbace0c76e519]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace 39: 0x1128d456d - rustc_mir_transform[7673fa52c4d14ac1]::mir_const 40: 0x112d5394f - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 41: 0x112e664cc - >::call_once 42: 0x112d0241f - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 43: 0x112d90fbb - rustc_query_impl[1f7dbace0c76e519]::query_impl::mir_const::get_query_non_incr::__rust_end_short_backtrace 44: 0x1128bf65a - rustc_middle[64d5e69fdab215c5]::query::plumbing::query_get_at::>> 45: 0x1128d4acf - rustc_mir_transform[7673fa52c4d14ac1]::mir_promoted 46: 0x112d4e2c4 - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 47: 0x112e62a90 - >::call_once 48: 0x112cf446a - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 49: 0x112d91c5b - rustc_query_impl[1f7dbace0c76e519]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace 50: 0x1111c64d3 - rustc_borrowck[80340335ac9afbc1]::mir_borrowck 51: 0x112d4e26f - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 52: 0x112e626ac - >::call_once 53: 0x112d0241f - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 54: 0x112d9d39b - rustc_query_impl[1f7dbace0c76e519]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace 55: 0x111be239a - rustc_middle[64d5e69fdab215c5]::query::plumbing::query_get_at::>> 56: 0x111bf7331 - rustc_hir_analysis[cebd03adaf2a8c68]::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit 57: 0x112d4ecd4 - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 58: 0x112f3bfbf - >::call_once 59: 0x112ca0f7f - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 60: 0x112d8c74a - rustc_query_impl[1f7dbace0c76e519]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace 61: 0x111bbfd37 - rustc_middle[64d5e69fdab215c5]::query::plumbing::query_get_at::>> 62: 0x111bd6593 - rustc_hir_analysis[cebd03adaf2a8c68]::collect::type_of::type_of 63: 0x112d535b1 - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 64: 0x112f4269f - >::call_once 65: 0x112ca0f7f - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 66: 0x112d8c42a - rustc_query_impl[1f7dbace0c76e519]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace 67: 0x111bbfd37 - rustc_middle[64d5e69fdab215c5]::query::plumbing::query_get_at::>> 68: 0x111bc6604 - rustc_hir_analysis[cebd03adaf2a8c68]::check::check::check_item_type 69: 0x111bceafc - rustc_hir_analysis[cebd03adaf2a8c68]::check::check::check_mod_item_types 70: 0x112d50e2f - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 71: 0x112f3e86c - >::call_once 72: 0x112c82040 - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 73: 0x112d9b09a - rustc_query_impl[1f7dbace0c76e519]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace 74: 0x111c1c0fe - rustc_hir_analysis[cebd03adaf2a8c68]::check_crate 75: 0x1120d386f - rustc_interface[33ae589e04b46ee6]::passes::analysis 76: 0x112d535cd - rustc_query_impl[1f7dbace0c76e519]::plumbing::__rust_begin_short_backtrace::> 77: 0x112f13559 - >::call_once 78: 0x112c39ba0 - rustc_query_system[a9a8fa527be5a562]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1f7dbace0c76e519]::plumbing::QueryCtxt, false> 79: 0x112d8d601 - rustc_query_impl[1f7dbace0c76e519]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 80: 0x1118d6dc1 - ::enter::> 81: 0x111879ccd - ::enter::, rustc_span[5ac116ba370720eb]::ErrorGuaranteed>> 82: 0x1118ae400 - rustc_span[5ac116ba370720eb]::set_source_map::, rustc_interface[33ae589e04b46ee6]::interface::run_compiler, rustc_driver_impl[e6cc4300320f3020]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 83: 0x1118b0110 - rustc_span[5ac116ba370720eb]::create_session_globals_then::, rustc_interface[33ae589e04b46ee6]::util::run_in_thread_pool_with_globals, rustc_driver_impl[e6cc4300320f3020]::run_compiler::{closure#1}>::{closure#0}, core[bc4f2b6eb0b2df1c]::result::Result<(), rustc_span[5ac116ba370720eb]::ErrorGuaranteed>>::{closure#0}> 84: 0x1118ec635 - std[32cc99a1e09f1cb9]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[e6cc4300320f3020]::run_compiler::{closure#1}>::{closure#0}, core[bc4f2b6eb0b2df1c]::result::Result<(), rustc_span[5ac116ba370720eb]::ErrorGuaranteed>>::{closure#0}, core[bc4f2b6eb0b2df1c]::result::Result<(), rustc_span[5ac116ba370720eb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bc4f2b6eb0b2df1c]::result::Result<(), rustc_span[5ac116ba370720eb]::ErrorGuaranteed>> 85: 0x1118f11e9 - <::spawn_unchecked_, rustc_driver_impl[e6cc4300320f3020]::run_compiler::{closure#1}>::{closure#0}, core[bc4f2b6eb0b2df1c]::result::Result<(), rustc_span[5ac116ba370720eb]::ErrorGuaranteed>>::{closure#0}, core[bc4f2b6eb0b2df1c]::result::Result<(), rustc_span[5ac116ba370720eb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bc4f2b6eb0b2df1c]::result::Result<(), rustc_span[5ac116ba370720eb]::ErrorGuaranteed>>::{closure#1} as core[bc4f2b6eb0b2df1c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 86: 0x101bb3a99 - std::sys::unix::thread::Thread::new::thread_start::h3e0c38234bb5890f 87: 0x7ff81e7c04e1 - __pthread_start 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 attach the file at `/Users/jruderman/code/tt/b1/rustc-ice-2023-11-11T02_04_53-7516.txt` to your bug report query stack during panic: #0 [mir_built] building MIR for `f::{closure#0}` #1 [unsafety_check_result] unsafety-checking `f::{closure#0}` #2 [unsafety_check_result] unsafety-checking `f` #3 [mir_const] preparing `f` for borrow checking #4 [mir_promoted] promoting constants in MIR for `f` #5 [mir_borrowck] borrow-checking `f` #6 [type_of_opaque] computing type of opaque `f::{opaque#0}` #7 [type_of] computing type of `f::{opaque#0}` #8 [check_mod_item_types] checking item types in top-level module #9 [analysis] running analysis passes on this crate end of query stack error: aborting due to 2 previous errors Some errors have detailed explanations: E0562, E0666. For more information about an error, try `rustc --explain E0562`. ```

Regression

Regression in nightly-2022-01-15, possibly due to #89861

Commits in range ``` commit[0] 2022-01-13UTC: Auto merge of #89861 - nbdd0121:closure, r=wesleywiser commit[1] 2022-01-14UTC: Auto merge of #92844 - matthiaskrgr:rollup-z5wb6yi, r=matthiaskrgr commit[2] 2022-01-14UTC: Auto merge of #92781 - lambinoo:I-92755-no-mir-missing-reachable, r=petrochenkov commit[3] 2022-01-14UTC: Auto merge of #92681 - Aaron1011:task-deps-ref, r=cjgillot commit[4] 2022-01-14UTC: Auto merge of #92883 - matthiaskrgr:rollup-uoudywx, r=matthiaskrgr ```

Version

rustc 1.75.0-nightly (fdaaaf9f9 2023-11-08)
binary: rustc
commit-hash: fdaaaf9f923281ab98b865259aa40fbf93d72c7a
commit-date: 2023-11-08
host: x86_64-apple-darwin
release: 1.75.0-nightly
LLVM version: 17.0.4
matthiaskrgr commented 11 months ago

I think this is a duplicate of https://github.com/rust-lang/rust/issues/110453

matthiaskrgr commented 10 months ago

Fixed by #118751