-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Bug in checker for duplicate constraints #18693
Comments
cc @nikomatsakis @pcwalton @pnkfelix |
This is also very limiting for generic maths. For example, something like the following is impossible: fn two_mult<Scalar, Vector, Matrix>(s: Scalar, v: Vector, m: Matrix) -> (Matrix, Vector)
where Matrix: Mul<Scalar, Matrix> + Mul<Vector, Vector> {
(m * s, m * v)
} because |
These are the current rules. I do think we ought to lift the restriction at some point, but there are subtleties to consider around object types. I've been meaning to write up an RFC exploring the details. Still, seems like a non-1.0 blocker to me. |
As far as I can tell, it blocks the planned redesign of piston-event and Conrod. There is a workaround, but with bad ergonomics as consequence. Definitely high priority for Piston. @nikomatsakis I'll write up the RFC, if that is what it takes to speed this up. |
We'd like this in Iron too, as it plays nicely with |
@nikomatsakis So far I have come up with a rule: For each method in the trait, the concrete types that appears in the method signature must differ at least one place. For example: pub trait Foo<T> {
fn foo(&self); // no places to differ, trait can not have duplicates
}
// must differ in concrete type both by T and U
pub trait Bar<T, U> {
fn bar1<T>(&mut self, t: &T); // must differ in concrete type by T
fn bar2<U>(&mut self, u: &U); // must differ in concrete type by U
}
// must differ in concrete type by T or U
pub trait Baz<T, U> {
fn baz<T, U>(&self, t: &T, u: &U);
} This is a super set of the current constraint in the compiler. |
@bvssvni sorry, I'm not clear on what this proposed rule is trying to achieve? |
@nikomatsakis I should have explained this better. Assume you have a signature For example, in Depending on which constraint we choose, we will end up with different behavior depending whether it is stricter or looser than this rule. For example, we could require all parameters to be concrete types, in which case it is a stricter rule. With a looser rule, we could only compare the arguments, which might mean some methods can not be resolved, even with type annotation. pub trait Get<T> {
fn get(&self) -> Foo;
}
fn bar<T: Get<One> + Get<Two>>(bar: &T) {
// there is no way to determine the trait from the method,
// because both returns type `Foo`.
let x = bar.get();
...
} My point is, the rule defines precisely how to determine whether two trait constraints are duplicates or not. |
The recent updates to piston-current makes the workaround decent enough to not block the planned redesign. We can wait after Rust 1.0. I will collect information about this in issues under the piston repo, but will probably not write an RFC, since I don't know enough about the compiler. I learned enough to see this requires non-trivial changes. Closing this since it is not a bug and would better be discussed elsewhere. |
fix: Fix proc-macro dylib names on windows
play.rust-lang.org: http://is.gd/AnPaWL
When the same trait is used more than one time but for different concrete types, it triggers the error for duplicate constraints without being sound.
The text was updated successfully, but these errors were encountered: