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

Error choosing among several implementations of a trait's static method #3903

Closed
burg opened this issue Nov 1, 2012 · 0 comments
Closed

Comments

@burg
Copy link

burg commented Nov 1, 2012

It seems that rustc isn't able to choose among multiple impls, and insists that some arbitrary one is the "right" one. (Note that type parameters are explicit to work around #3902)

Testcase

mod base {
    trait HasNew<T> {
        static pure fn new() -> T;
    }

    pub struct Foo {
        dummy: (),
    }

    pub impl Foo : HasNew<Foo> {
        static pure fn new() -> Foo {
            Foo { dummy: () }
        }
    }

    pub struct Bar {
        dummy: (),
    }

    pub impl Bar : HasNew<Bar> {
        static pure fn new() -> Bar {
            Bar { dummy: () }
        }
    }
}

fn main() {
    let f: base::Foo = base::new::<base::Foo, base::Foo>();
    debug!("%?", f);
}

Error

[burg@host-5-178 Desktop]# rustc test.rs
test.rs:28:23: 28:56 error: mismatched types: expected `@base::HasNew<base::Bar>` but found `@base::HasNew<base::Foo>` (expected class base::Bar but found class base::Foo)
test.rs:28     let f: base::Foo = base::new::<base::Foo, base::Foo>();
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:28:23: 28:56 error: mismatched types: expected `base::Foo` but found `base::Bar` (expected class base::Foo but found class base::Bar)
test.rs:28     let f: base::Foo = base::new::<base::Foo, base::Foo>();
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:28:23: 28:56 error: mismatched types: expected `@base::HasNew<base::Bar>` but found `@base::HasNew<base::Foo>` (expected class base::Bar but found class base::Foo)
test.rs:28     let f: base::Foo = base::new::<base::Foo, base::Foo>();
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:28:23: 28:56 error: mismatched types: expected `base::Foo` but found `base::Bar` (expected class base::Foo but found class base::Bar)
test.rs:28     let f: base::Foo = base::new::<base::Foo, base::Foo>();
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RalfJung pushed a commit to RalfJung/rust that referenced this issue Sep 22, 2024
try to give the CI job permission to create PRs

See the discussion [here](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/did.20github.20token.20permissions.20change.3F).

`@rust-lang/infra` just a heads-up that we are doing this -- I have no idea if this could cause any issues elsewhere, or if it is important that we limit the permissions here somehow, or so.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants