Skip to content

"Unsupported associated type binding" when declaring local variable with associated type in default method #19850

Closed
@kennytm

Description

@kennytm

Test case:

#![feature(associated_types)]

trait Int {
    fn one() -> Self;
    fn leading_zeros(self) -> uint;
}

trait Foo {
    type T : Int;

    fn test(&self) -> uint {
        let r: <Self as Foo>::T = Int::one();
        r.leading_zeros()
    }
}

fn main() {
}

Currently fails with:

1.rs:12:25: 12:28 error: unsupported associated type binding
1.rs:12         let r: <Self as Foo>::T = Int::one();
                                ^~~
error: aborting due to previous error

This can be worked around by making that Int::one() expression into a method of the trait returning <Self as Foo>::T, but then that method would become public as well, which may not be desirable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions