-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 influnces inference #36262
Comments
Another example: #![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);
} |
I don't have an sscce, but I produced this small patch for the current master branch of rust, which breaks type inference regarding specialization of iterators. |
I have a patch specializing Edit: I've misinterpreted the issue. Explanation at the end // general block
impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] {
type Output = Vec<T>;
default fn concat(&self) -> Vec<T> { ... }
/* other methods */
}
// specializing block
impl<T: Copy, V: Borrow<[T]>> SliceConcatExt<T> for [V] {
/* empty */
} The call where inference breaks is src/librustc_typeck/collect.rs Line 1299 The error is:
Edit: |
STR
Expected Result
Adding a specialized impl will not affect type inference.
Actual Result
After adding the specialized impl, inference is guided to take it:
cc @aturon @nikomatsakis
The text was updated successfully, but these errors were encountered: