Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImpl search fails in case of generalized trait inheritance #10950
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
file under #5527 -- it is a good point. |
This comment has been minimized.
This comment has been minimized.
|
The error for this sample is now
|
This comment has been minimized.
This comment has been minimized.
|
Triage: same error, but with extra message:
Also, you need the old impl check here:
|
steveklabnik
added
A-typesystem
A-traits
labels
Jan 23, 2015
This comment has been minimized.
This comment has been minimized.
|
Even without the old impl check, this example no longer makes sense, because it uses the old unary tuple dereferencing syntax. Today, the compiler is correct that type trait Foo {
fn foo(&self, x: &Self);
}
trait Bar {
type A: Foo;
fn bar(&self) -> Self::A;
}
struct Wrap<T>(T);
impl<B: Bar> Wrap<B> {
fn test(&self, x: &B::A) {
self.0.bar().foo(x);
}
}
fn main() {}compiles successfully. I think this issue can be closed. |
This comment has been minimized.
This comment has been minimized.
talchas
commented
Aug 31, 2015
|
Well this still fails, and seems like morally still at least somewhat similar. trait Foo { fn foo(&self, x: &Self); }
trait Bar<A: Foo> { fn bar(&self) -> A; }
struct Wrap<T>(T);
fn test<A, B: Bar<A>>(wrap: Wrap<B>, x: &A) {
wrap.0.bar().foo(x);
}
fn main() {} |
This comment has been minimized.
This comment has been minimized.
|
This is intentional - non-supertrait bounds are not elaborated. |
jld
referenced this issue
Dec 21, 2015
Open
RFC 1214 problems with bounds on associated type of type parameter #30311
brson
added
the
T-lang
label
Mar 23, 2017
This comment has been minimized.
This comment has been minimized.
|
Closing as a duplicate of #20671, which has a better explanation. |
rntz commentedDec 13, 2013
The following program fails to compile:
With the following error:
Given that
B: Bar<A>, we knowA: Foobecause of the definition of the trait Bar. This can be seen as a generalized case of trait inheritance (trait B inheriting from A lets us know that ifX:B, thenX:A, becauseX:BrequiresX:A; similarly,B:Bar<A>requiresA:Foo, so we knowA:Foo). Indeed, in Haskell there is no distinction between the two forms of inheritance:{-# LANGUAGE MultiParamTypeClasses #-} class Foo b where foo :: b -> b -> () class Foo b => Bar a b where bar :: a -> b test :: Bar a b => a -> b -> () test x y = foo (bar x) yThe order of arguments to Bar could be switched and the program above would still be valid.