Closed
Description
This code:
#![feature(associated_types)]
trait Factory {
type Product;
fn create(&self) -> <Self as Factory>::Product;
}
impl Factory for f64 {
type Product = f64;
fn create(&self) -> f64 { *self * *self }
}
impl<A: Factory, B: Factory> Factory for (A, B) {
type Product = (<A as Factory>::Product, <B as Factory>::Product); // line 14
fn create(&self) -> (<A as Factory>::Product, <B as Factory>::Product) {
let (ref a, ref b) = *self;
(a.create(), b.create())
}
}
fn main() {
println!("{}", (4.0f64, 5.0f64).create());
// ^ should print (16, 25)
}
Failed to compile with error:
1.rs:14:20: 14:70 error: illegal recursive type; insert an enum or struct in the cycle, if this is desired
1.rs:14 type Product = (<A as Factory>::Product, <B as Factory>::Product);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think this should be allowed.