Open
Description
I tried this code: playground.
#![recursion_limit = "1024"]
#![allow(unused)]
use std::marker::PhantomData;
struct Apple;
struct Nil;
struct Cons<Car, Cdr>(PhantomData<(Car, Cdr)>);
// ========= Concat =========
trait Concat {
type Output;
}
impl<L2> Concat for (Nil, L2) {
type Output = L2;
}
impl<Car, Cdr, L2> Concat for (Cons<Car, Cdr>, L2)
where
(Cdr, L2): Concat, // Recursive step
{
type Output = Cons<Car, <(Cdr, L2) as Concat>::Output>;
}
// ========= Flat =========
trait Flat {
type Output;
}
impl Flat for Nil {
type Output = Nil;
}
// Head is not Cons
impl<Head, Tail> Flat for Cons<Head, Tail>
where
Tail: Flat,
{
type Output = Cons<Head, <Tail as Flat>::Output>;
}
// Head is Cons
impl<HeadCar, HeadCdr, Tail> Flat for Cons<Cons<HeadCar, HeadCdr>, Tail>
where
Cons<HeadCar, HeadCdr>: Flat,
Tail: Flat,
(<Cons<HeadCar, HeadCdr> as Flat>::Output, <Tail as Flat>::Output): Concat,
{
type Output = <(<Cons<HeadCar, HeadCdr> as Flat>::Output, <Tail as Flat>::Output) as Concat>::Output;
}
type Computation = <Cons<Apple, Nil> as Flat>::Output;
fn main() {
println!(
"{}",
std::any::type_name::<Computation>()
);
}
I expected to see this happen: Compiler gives compilation error or compiles
Instead, this happened: segfault
On my machine, it segfaults on stable either, but not in playground. On playground it segfaults on beta and nightly.
rustc
on my local machine, stable. Not segfaults on playground stable
❯ rustc --version --verbose
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2
Meta
Backtrace: Too long for github. I would not cut it, because I don't know what I'm doing.