Closed
Description
This could be a duplicate bug, but I don't know have the know how to tell if it is (I found issues with similar but not identical error output, and I figured it's better to report and risk a duplicate than to risk leaving it unreported.
Code
pub fn compose(
f1: impl FnOnce(f64) -> f64 + Clone,
f2: impl FnOnce(f64) -> f64 + Clone,
) -> impl FnOnce(f64) -> f64 + Clone {
move |x| f1(f2(x))
}
pub fn double(f: impl FnOnce(f64) -> f64 + Clone) -> impl FnOnce(f64) -> f64 + Clone {
compose(f.clone(), f)
}
fn repeat_helper(f: impl FnOnce(f64) -> f64 + Clone, res: impl FnOnce(f64) -> f64 + Clone, times: usize) -> impl FnOnce(f64) -> f64 + Clone {
if times == 1 {
return res;
}
repeat_helper(f.clone(), compose(f, res), times - 1)
}
pub fn repeat(f: impl FnOnce(f64) -> f64 + Clone, times: usize) -> impl FnOnce(f64) -> f64 + Clone {
repeat_helper(f.clone(), f, times)
}
(Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1bb970cfa0b428638ff8fd94551bc3a6)
Meta
rustc --version --verbose
:
Bug appears on all of 1.61.0, 1.62.0-beta.3 and 1.63.0-nightly (2022-06-02 e71440575c930dcecac2)
Error output
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
error: internal compiler error: broken MIR in DefId(0:11 ~ playground[b1a6]::repeat_helper) (Terminator { source_info: SourceInfo { span: src/lib.rs:17:5: 17:57 (#0), scope: scope[0] }, kind: _0 = repeat_helper::<impl FnOnce(f64) -> f64 + Clone, impl (FnOnce(f64)-> f64) + Clone>(move _8, move _10, move _13) -> [return: bb6, unwind: bb10] }): call dest mismatch (impl (FnOnce(f64)-> f64) + std::clone::Clone <- impl (FnOnce(f64)-> f64) + std::clone::Clone): NoSolution
--> src/lib.rs:17:55
|
17 | repeat_helper(f.clone(), compose(f, res), times - 1)
| ^
|
= note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:1564:21
Backtrace
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1369:13
stack backtrace:
0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
1: std::panic::panic_any::<rustc_errors::ExplicitBug>
2: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
3: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
4: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
5: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
6: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
7: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.