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

Can't provide non-overlapping trait impls based on assoc type trait bound #23341

Closed
cristicbz opened this issue Mar 13, 2015 · 3 comments
Closed
Labels
A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug.

Comments

@cristicbz
Copy link
Contributor

use std::iter::IntoIterator;

trait Foo {
    fn foo(&self);
}

trait Bar {
    fn bar(&self);
}

impl<I> Foo for I
        where I: IntoIterator,
              I::Item: Bar {
    fn foo(&self) {
    }
}

impl Foo for Vec<u8> {
    fn foo(&self) {
    }
}

fn main() {}

fails with

<anon>:11:1: 16:2 error: conflicting implementations for trait `Foo` [E0119]
<anon>:11 impl<I> Foo for I
<anon>:12         where I: IntoIterator,
<anon>:13               I::Item: Bar {
<anon>:14     fn foo(&self) {
<anon>:15     }
<anon>:16 }
<anon>:18:1: 21:2 note: note conflicting implementation here
<anon>:18 impl Foo for Vec<u8> {
<anon>:19     fn foo(&self) {
<anon>:20     }
<anon>:21 }

See playpen.

Since u8 does not implement Bar, the impl-s are actually non-overlapping.

Possibly related to #20400.

@kdeeee
Copy link

kdeeee commented Sep 30, 2016

still occur this error inrustc 1.11.0 (9b21dcd6a 2016-08-15)
error message is conflicting implementations of trait 'Foo' for type 'std::vec::Vec<u8>'

@sanxiyn sanxiyn changed the title Can't provide non-overlpping trait impls based on assoc type trait bound Can't provide non-overlapping trait impls based on assoc type trait bound Sep 30, 2016
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@dhardy
Copy link
Contributor

dhardy commented Aug 1, 2017

@dtolnay
Copy link
Member

dtolnay commented Aug 13, 2018

Let's continue to track this under #20400 -- the resolution will surely be the same and it's better to keep the relevant discussion in one place.

@dtolnay dtolnay closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

6 participants