Closed
Description
While coding for a kata challenge (this one to be exact), the compiler hung when I tried to compile the code below, probably getting stuck trying to determine the return type.
It's late so I'll look into making the code more concrete tomorrow (if this doesn't turn out to be known)
Code
Original code
pub type ISO<A: 'static, B: 'static> = (Box<dyn Fn(A) -> B>, Box<dyn Fn(B) -> A>);
pub fn iso<A: 'static, B: 'static, F1, F2>(a: F1, b: F2) -> ISO<A, B>
where
F1: 'static + Fn(A) -> B,
F2: 'static + Fn(B) -> A,
{
(Box::new(a), Box::new(b))
}
pub fn iso_un_option<A: 'static, B: 'static>(i: ISO<Option<A>, Option<B>>) -> ISO<A, B> {
let (ab, ba) = (i.0, i.1);
let left = move |o_a| match o_a {
None => panic!("absured"),
Some(a) => a,
};
let right = move |o_b| match o_b {
None => panic!("absurd"),
Some(b) => b,
};
// todo!() if the below is replaced with this there is no problem
iso(left, right)
}
fn main() {
println!("I'm working!");
}
EDIT: The smallest I could get it. The compiler won't hang if I
- Inline the iso function
- Call unwrap instead of matching in left or right
- Remove either of the two arguments left/right
MCVE:
pub fn iso<A, B, F1, F2>(a: F1, b: F2) -> (Box<dyn Fn(A) -> B>, Box<dyn Fn(B) -> A>)
where
F1: 'static + Fn(A) -> B,
F2: 'static + Fn(B) -> A,
{
(Box::new(a), Box::new(b))
}
pub fn iso_un_option<A, B>() -> (Box<dyn Fn(A) -> B>, Box<dyn Fn(B) -> A>) {
let left: fn(Option<_>) -> _ = move |o_a| match o_a {
None => panic!("absurd"),
Some(a) => a,
};
let right : fn(Option<_>) -> _= move |o_b| match o_b {
None => panic!("absurd"),
Some(b) => b,
};
iso(left, right)
}
fn main() {
println!("I'm working!");
}
Meta
rustc --version --verbose
:
rustc 1.45.2 (d3fb005a3 2020-07-31)
binary: rustc
commit-hash: d3fb005a39e62501b8b0b356166e515ae24e2e54
commit-date: 2020-07-31
host: x86_64-pc-windows-msvc
release: 1.45.2
LLVM version: 10.0
Same for nightly:
rustc 1.47.0-nightly (663d2f5cd 2020-08-22)
binary: rustc
commit-hash: 663d2f5cd3163f17eddb74ee1e028d542255f21a
commit-date: 2020-08-22
host: x86_64-pc-windows-msvc
release: 1.47.0-nightly
LLVM version: 10.0
Error output
Hung compiler, so no output or backtrace