-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-specializationArea: Trait impl specializationArea: Trait impl specialization
Description
#![feature(specialization)]
use std::marker::PhantomData;
trait Trait {
type A;
type B;
fn foo(&self, a: Self::A, b: Self::B);
}
struct Foo<A, B> {
a: PhantomData<A>,
b: PhantomData<B>,
}
impl<A, B> Foo<A, B> {
fn new() -> Self {
Foo {
a: PhantomData,
b: PhantomData,
}
}
}
impl<A, B> Trait for Foo<A, B> {
type A = A;
type B = B;
default fn foo(&self, _: A, _: B) {
println!("default impl");
}
}
// Specialized
impl<A, B: Eq> Trait for Foo<A, B> {
fn foo(&self, _: A, _: B) {
println!("specialized");
}
}
fn main() {
let a = "a";
let b = "b";
let f = Foo::new(); // Need to specify concrete type here to compile
f.foo(a, b);
}
Expected Result
Program should compile and print out "specialized"
Actual Result
rustc 1.15.0-nightly (2217bd771 2016-11-25)
error[E0282]: unable to infer enough type information about `_`
--> <anon>:44:13
|
44 | let f = Foo::new(); // Need to specify concrete type here to compile
| ^^^^^^^^ cannot infer type for `_`
|
= note: type annotations or generic parameter binding required
error: aborting due to previous error
May be related to #36262
Metadata
Metadata
Assignees
Labels
A-specializationArea: Trait impl specializationArea: Trait impl specialization