Closed
Description
Code
trait FnOnceForGenericRef<T>: FnOnce(&T) -> Self::FnOutput {
type FnOutput;
}
impl<T, R, F: FnOnce(&T) -> R> FnOnceForGenericRef<T> for F {
type FnOutput = R;
}
struct Data<T, D: FnOnceForGenericRef<T>> {
value: Option<T>,
output: Option<D::FnOutput>,
}
impl<T, D: FnOnceForGenericRef<T>> Data<T, D> {
fn new(value: T, f: D) -> Self {
let output = f(&value);
Self {
value: Some(value),
output: Some(output),
}
}
}
fn test() {
Data::new(String::new(), |_| {});
// It is very weird that the following code doesn't panic but
// emit error as expected: "implementation of `FnOnce` is not general enough"
// Data::new(1, |_| {});
}
Here is the playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=aba30e89981874a854cb8252c652b7f2
This might be related to #99665 and #102800 .
Meta
rustc --version --verbose
:
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: aarch64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.0.6
The bug also exists for rustc 1.66.0-nightly (bf15a9e52 2022-10-14)
Error output
thread 'rustc' panicked at 'no entry found for key', compiler/rustc_borrowck/src/region_infer/mod.rs:2237:9
Backtrace
thread 'rustc' panicked at 'no entry found for key', compiler/rustc_borrowck/src/region_infer/mod.rs:2237:9
stack backtrace:
0: 0x7f9c41ebf510 - std::backtrace_rs::backtrace::libunwind::trace::hc83d2ca9877ed15f
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
1: 0x7f9c41ebf510 - std::backtrace_rs::backtrace::trace_unsynchronized::h761490c78a8d3c90
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7f9c41ebf510 - std::sys_common::backtrace::_print_fmt::h74c2d9c05b36a5cb
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/sys_common/backtrace.rs:66:5
3: 0x7f9c41ebf510 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb42a8b90000bb024
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/sys_common/backtrace.rs:45:22
4: 0x7f9c41f1b52e - core::fmt::write::h5ee7341ed55b8805
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/core/src/fmt/mod.rs:1209:17
5: 0x7f9c41eaf7d5 - std::io::Write::write_fmt::hacce97c59cf194e4
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/io/mod.rs:1680:15
6: 0x7f9c41ec2143 - std::sys_common::backtrace::_print::h6884fdd5ab3f424d
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/sys_common/backtrace.rs:48:5
7: 0x7f9c41ec2143 - std::sys_common::backtrace::print::hb66e100356b39aaa
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/sys_common/backtrace.rs:35:9
8: 0x7f9c41ec2143 - std::panicking::default_hook::{{closure}}::h437804d1a6836d5e
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/panicking.rs:267:22
9: 0x7f9c41ec1e1a - std::panicking::default_hook::h65e830729b214390
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/panicking.rs:286:9
10: 0x7f9c448083c4 - rustc_driver[f331bf04a31a4474]::DEFAULT_HOOK::{closure#0}::{closure#0}
11: 0x7f9c41ec2a79 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hef73fb3e3355d020
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/alloc/src/boxed.rs:1952:9
12: 0x7f9c41ec2a79 - std::panicking::rust_panic_with_hook::hcab2853c64105b40
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/panicking.rs:692:13
13: 0x7f9c41ec27f7 - std::panicking::begin_panic_handler::{{closure}}::hd9c5ea26691d8270
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/panicking.rs:579:13
14: 0x7f9c41ebf9bc - std::sys_common::backtrace::__rust_end_short_backtrace::hd8a22d71267b4b61
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/sys_common/backtrace.rs:138:18
15: 0x7f9c41ec2512 - rust_begin_unwind
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/panicking.rs:575:5
16: 0x7f9c41f17f13 - core::panicking::panic_fmt::h4c6b07d94019a3f0
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/core/src/panicking.rs:65:14
17: 0x7f9c41f18061 - core::panicking::panic_display::hafe927c06584f593
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/core/src/panicking.rs:139:5
18: 0x7f9c41f1800b - core::panicking::panic_str::hab929c599078f017
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/core/src/panicking.rs:123:5
19: 0x7f9c41f17c86 - core::option::expect_failed::ha0bacc385d0a2f07
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/core/src/option.rs:1876:5
20: 0x7f9c44e9bebe - <rustc_borrowck[8ef346bc23d797c8]::region_infer::RegionInferenceContext>::universe_info
21: 0x7f9c43681b7e - rustc_borrowck[8ef346bc23d797c8]::do_mir_borrowck
22: 0x7f9c4367c9d0 - rustc_borrowck[8ef346bc23d797c8]::mir_borrowck
23: 0x7f9c4367c361 - <rustc_borrowck[8ef346bc23d797c8]::provide::{closure#0} as core[2c5081d8f0108272]::ops::function::FnOnce<(rustc_middle[3d73d7ef627e8bf]::ty::context::TyCtxt, rustc_span[c16ea33475d6785f]::def_id::LocalDefId)>>::call_once
24: 0x7f9c43dfcd75 - rustc_query_system[5f73ab021976280c]::query::plumbing::try_execute_query::<rustc_query_impl[84f7ded2d44823f6]::plumbing::QueryCtxt, rustc_query_system[5f73ab021976280c]::query::caches::DefaultCache<rustc_span[c16ea33475d6785f]::def_id::LocalDefId, &rustc_middle[3d73d7ef627e8bf]::mir::query::BorrowCheckResult>>
25: 0x7f9c4470db8e - <rustc_query_impl[84f7ded2d44823f6]::Queries as rustc_middle[3d73d7ef627e8bf]::ty::query::QueryEngine>::mir_borrowck
26: 0x7f9c441f72d3 - rustc_data_structures[5f783117a6880793]::sync::par_for_each_in::<&[rustc_span[c16ea33475d6785f]::def_id::LocalDefId], <rustc_middle[3d73d7ef627e8bf]::hir::map::Map>::par_body_owners<rustc_interface[24040f739c3f95dc]::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
27: 0x7f9c441f7033 - <rustc_session[665a57f624cd1b0d]::session::Session>::time::<(), rustc_interface[24040f739c3f95dc]::passes::analysis::{closure#2}>
28: 0x7f9c441f62a5 - rustc_interface[24040f739c3f95dc]::passes::analysis
29: 0x7f9c4459a284 - rustc_query_system[5f73ab021976280c]::query::plumbing::try_execute_query::<rustc_query_impl[84f7ded2d44823f6]::plumbing::QueryCtxt, rustc_query_system[5f73ab021976280c]::query::caches::DefaultCache<(), core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>>>
30: 0x7f9c44599fb7 - rustc_query_system[5f73ab021976280c]::query::plumbing::get_query::<rustc_query_impl[84f7ded2d44823f6]::queries::analysis, rustc_query_impl[84f7ded2d44823f6]::plumbing::QueryCtxt>
31: 0x7f9c434c0f93 - <rustc_interface[24040f739c3f95dc]::passes::QueryContext>::enter::<rustc_driver[f331bf04a31a4474]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>>
32: 0x7f9c434b9db8 - rustc_interface[24040f739c3f95dc]::interface::create_compiler_and_run::<core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>, rustc_driver[f331bf04a31a4474]::run_compiler::{closure#1}>
33: 0x7f9c434b8be2 - <scoped_tls[fdb5e1dcf3b8ea2]::ScopedKey<rustc_span[c16ea33475d6785f]::SessionGlobals>>::set::<rustc_interface[24040f739c3f95dc]::interface::run_compiler<core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>, rustc_driver[f331bf04a31a4474]::run_compiler::{closure#1}>::{closure#0}, core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>>
34: 0x7f9c434b80bf - std[eb0ada501a1276bc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[24040f739c3f95dc]::util::run_in_thread_pool_with_globals<rustc_interface[24040f739c3f95dc]::interface::run_compiler<core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>, rustc_driver[f331bf04a31a4474]::run_compiler::{closure#1}>::{closure#0}, core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>>::{closure#0}, core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>>
35: 0x7f9c4462582f - <<std[eb0ada501a1276bc]::thread::Builder>::spawn_unchecked_<rustc_interface[24040f739c3f95dc]::util::run_in_thread_pool_with_globals<rustc_interface[24040f739c3f95dc]::interface::run_compiler<core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>, rustc_driver[f331bf04a31a4474]::run_compiler::{closure#1}>::{closure#0}, core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>>::{closure#0}, core[2c5081d8f0108272]::result::Result<(), rustc_errors[3e7e0c00279b1c89]::ErrorGuaranteed>>::{closure#1} as core[2c5081d8f0108272]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
36: 0x7f9c41ecc593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb87d6f0b287ef99f
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/alloc/src/boxed.rs:1938:9
37: 0x7f9c41ecc593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h57e28d10de971273
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/alloc/src/boxed.rs:1938:9
38: 0x7f9c41ecc593 - std::sys::unix::thread::Thread::new::thread_start::h4ee249ae8a0419de
at /rustc/bf15a9e5263fcea065a7ae9c179b2d24c2deb670/library/std/src/sys/unix/thread.rs:108:17
39: 0x7f9c41d9e609 - start_thread
40: 0x7f9c41cc1133 - clone
41: 0x0 - <unknown>
error: internal compiler error: unexpected panic