Hi David,
My current thinking on the matter is that eventually, I would like to
take advantage of the coherence rules to permit a program like
this. Coherence means that given a specific type T and trait U, we can
always tell whether T implements U. This implies that we could do the
check as you described it.
However, implementing this is a bit far off. I think it is best done
as part of a general rewrite of the trait and method resolution
code. I have started that, but put it on hold to deal with #6801
(borrowck treatment of closures) and then the treatment of moves and
zeroing (#5016).
Also, I am not sure how much of this has been discussed and agreed
to. One of my longstanding "to do" items is to write up my thinking on
trait resolution as a blog post and then discuss at a meeting. You are
giving me some motivation to do that, since I'd love to be able to
point you to a fully explained blog post :)
Niko
On Thu, Sep 05, 2013 at 09:29:59AM -0700, David Renshaw wrote:
> Hi,
>
> When I try to compile the below program, why do I get a "conflicting
> implementations" error? I do not define any implementations of Bar, so
> the parameterized impl of Foo should never get instantiated, right?
>
> -------------------
>
> trait Foo {
> fn foo() -> Self;
> }
>
> trait Bar : std::num::Zero { }
>
> impl <T : Bar> Foo for T {
> fn foo() -> T {
> std::num::Zero::zero()
> }
> }
>
> impl Foo for u16 {
> fn foo () -> u16 {
> 100
> }
> }
>
> fn main() {
>
> // should be 100
> let x : u16 = Foo::foo();
> printfln!("%s", x);
>
> }
>
> // error: conflicting implementations for trait `Foo`
>
> ------------------
>
>
> When I asked about this on IRC, cmr indicated that this is probably
> the intended behavior of rustc, but that most people want to change
> it. Is that true, and when can we expect a fix?
>
>
> Thanks,
> David
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev