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

Discourage impl of trait not in your crate for type not in your crate #138

Open
dtolnay opened this Issue Nov 1, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@dtolnay
Copy link
Member

dtolnay commented Nov 1, 2017

Such impls can lead to surprising and hard to debug inference failures in totally unrelated code. For example:

fn main() {
    let bools = vec![true, false];
    let stuff = Vec::new();
    assert_ne!(bools, stuff);
}

But adding this impl makes the inference break. The impl is PartialEq (not in our crate) for bool (not in our crate).

struct S;
impl PartialEq<S> for bool {
    fn eq(&self, other: &S) -> bool {
        unimplemented!()
    }
}

Real instance of this causing trouble: diesel-rs/diesel@1f3d7b1

@Ixrec

This comment has been minimized.

Copy link

Ixrec commented Jun 24, 2018

This seems like it's harmful primarily when the trait and type are both from std. Maybe we could add a clippy lint against the general pattern of impl<...> [std trait]<...> for [std type]<...>?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.