Closed
Description
Rustc runs out of stack on this program:
use std::io;
trait B {
fn f(&self);
}
trait T : B {
}
struct A;
impl<U: T> B for U {
fn f(&self) { io::println("Hey, I'm a T!"); }
}
impl T for A {
}
fn main() {
let a = A;
let br = &a as &B;
// let tr = &a as &T;
// let br = tr as &B;
br.f();
}
The inheritance of trait T from B seemingly triggers the recursion: without it, the program compiles and runs fine.
P.S. The commented-out lines illustrate what I was actually trying to achieve: upcasting a trait pointer to the base trait. That didn't work for other reasons.