-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
The next comment has a minimal example(the one in this comment is a bit complex).
Old example
This code:
trait Hello<Name> {
fn hello(&self, _: Name){}
}
struct A;
struct B;
struct C;
impl<T0, T1> Hello<A> for (T0, T1) {}
impl<T0, T1> Hello<B> for (T0, T1) {}
impl<T0, T1> Hello<C> for (T0, T1) {}
trait Tuple2:Hello<A> + Hello<B> + Hello<C>{}
impl<This> Tuple2 for This
where
This:Hello<A> + Hello<B> + Hello<C>
{}
fn returns_impl() -> impl Tuple2 {
(0, 10)
}
fn main() {
{
let tup = returns_impl();
tup.hello(A); // This is the first one that errors
tup.hello(B); // This is the second one that errors
tup.hello(C);
Hello::<A>::hello(&tup,A);
Hello::<B>::hello(&tup,B);
Hello::<C>::hello(&tup,C);
}
{// It all works fine with dynamic dispatch
let tup:&dyn Tuple2= &returns_impl();
tup.hello(A);
tup.hello(B);
tup.hello(C);
Hello::<A>::hello(tup,A);
Hello::<B>::hello(tup,B);
Hello::<C>::hello(tup,C);
}
}
Causes this error:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:29:19
|
29 | tup.hello(A); // This is the first one that errors
| ^ expected struct `C`, found struct `A`
|
= note: expected type `C`
found type `A`
error[E0308]: mismatched types
--> src/main.rs:30:19
|
30 | tup.hello(B); // This is the second one that errors
| ^ expected struct `C`, found struct `B`
|
= note: expected type `C`
found type `B`
error: aborting due to 2 previous errors
On both the stable (1.38) and nightly (1.40.0 2019-11-02) versions in the playground.
I expected this code to compile without errors.
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team