Skip to content

Error message mentions type errors and non-existent type parameter on trait with an associated type #17696

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

Closed
ftxqxd opened this issue Oct 1, 2014 · 1 comment
Labels
A-type-system Area: Type system

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Oct 1, 2014

#![feature(associated_types)]

trait Foo {
    type T;
    fn foo(&self) -> <Self as Foo>::T;
}

struct Bar;

impl Foo for Bar {
    type T = int;
    fn foo(&self) -> int { 1 }
}

fn main() {
    let x = box Bar as Box<Foo>;
    x.foo();
}

This fails to compile with:

assoc_typ_dyn.rs:16:28: 16:31 error: unsupported associated type binding
assoc_typ_dyn.rs:16     let x = box Bar as Box<Foo>;
                                               ^~~
assoc_typ_dyn.rs:16:13: 16:32 error: type mismatch: the type `Bar` implements the trait `Foo<int>`, but the trait `Foo<[type error]>` is required (expected type error, found int)
assoc_typ_dyn.rs:16     let x = box Bar as Box<Foo>;
                                ^~~~~~~~~~~~~~~~~~~
assoc_typ_dyn.rs:16:13: 16:32 note: the trait `Foo` must be implemented for the cast to the object type `Foo<[type error]>`
assoc_typ_dyn.rs:16     let x = box Bar as Box<Foo>;
                                ^~~~~~~~~~~~~~~~~~~

Not only does this mention type errors when it probably shouldn’t, but it also seems to be mistaking the associated type for a type parameter. Changing the cast to as Box<Foo<int>> as it seems to suggest doesn’t work, and the syntax from the RFC (Box<Foo<T = int>>) doesn’t seem to be implemented yet.

@ftxqxd
Copy link
Contributor Author

ftxqxd commented May 15, 2015

The error message for this makes sense now, and the Box<Foo<T = i32>> syntax works now. I think this can be closed.

@ftxqxd ftxqxd closed this as completed May 15, 2015
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

2 participants