Skip to content

illegal recursive type check is excessively strict on associated types #17744

Closed
@sp3d

Description

@sp3d

As far as I can tell, the purpose of the "illegal recursive type" error (in src/librustc/middle/typeck/astconv.rs) is to prevent types from referring to themselves in their definition, e.g. as done in src/test/compile-fail/infinite-vec-type-recursion.rs (type x = Vec<x>;).

However, the logic being used to implement this check also disallows the following usage of associated types, which is intended to provide an implementation of the trait R on Vec<T> if T itself implements R (doing so by passing through T's associated type assoc):

trait R
{
    type assoc;
}
impl<T: R> R for Vec<T>
{
    type assoc=<T as R>::assoc;
    //does work: type assoc=uint;
}

It seems like this code should be accepted (though type assoc=<Vec<T> as R>::assoc; should still fail this check).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions