Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialization does not work with inference of multiple parameterized types #38167

Closed
ipetkov opened this issue Dec 4, 2016 · 2 comments
Closed
Labels
A-specialization Area: Trait impl specialization

Comments

@ipetkov
Copy link
Contributor

ipetkov commented Dec 4, 2016

#![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

@bluss
Copy link
Member

bluss commented Dec 5, 2016

What I thought was interesting here was that the program compiles without the specialization impl (line 34), and when it is added, there is a type inference error.

@apasel422 apasel422 added the A-specialization Area: Trait impl specialization label Dec 28, 2016
@Mark-Simulacrum
Copy link
Member

I'm going to close in favor of #36262, since it seems to be the same general issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization
Projects
None yet
Development

No branches or pull requests

4 participants