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

Rust's coherence checking overconservative #10601

Closed
minhnhdo opened this issue Nov 22, 2013 · 6 comments
Closed

Rust's coherence checking overconservative #10601

minhnhdo opened this issue Nov 22, 2013 · 6 comments
Labels
A-type-system Area: Type system

Comments

@minhnhdo
Copy link
Contributor

Code:

use std::rand;

pub trait Nothing { }

impl<T: rand::Rand> Nothing for T { }
impl<T: rand::Rand> Nothing for ~[T] { }

Output:

error: conflicting implementations for trait `lib::Nothing`

Expected:
Compile normally, as there is no impl Rand for ~[T].

@thestinger
Copy link
Contributor

This is the intended behaviour. A crate can only define a trait if either the type it's defining it for or the trait is local to the crate. This prevents libraries from being able to create conflicting trait implementations. It wouldn't be good if Rust libraries could be incompatible with linking to each other from a basic language feature like this.

@huonw
Copy link
Member

huonw commented Nov 22, 2013

@thestinger I believe that rule means that this can be valid, because the compiler knows that someone can't define Rand for ~[] (because any (trait, type) pair visible in this crate has whether it is implemented or not also visible).

@thestinger thestinger reopened this Nov 22, 2013
@thestinger
Copy link
Contributor

Ah, sorry, I missed that the Nothing trait was local.

@nikomatsakis
Copy link
Contributor

cc me. cc #5527.

@japaric
Copy link
Member

japaric commented Nov 2, 2014

This is now working because of conditional/multi dispatch.

@nikomatsakis can we close this?

@nikomatsakis
Copy link
Contributor

Yes.

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 7, 2023
…n, r=llogiq

Add [`manual_slice_size_calculation`]

Fixes: rust-lang#10518

---

changelog: new lint [`manual_slice_size_calculation`]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

5 participants