Skip to content

Well-formedness of type parameter defaults is not checked #46669

Closed
@leoyvens

Description

@leoyvens

This compiles:

struct Foo<T:Copy=String>(T);

fn main() { }

This does not:

struct Foo<T:Copy=String>(T);

fn main() {
    let a: Foo;
}

Even though it's stable, we should probably phase out writing badly formed defaults in declarations.

We also don't check that a dependent default actually implements a given trait when using associated items:

struct Bar<A, T=<A as Iterator>::Item>(A, T);

Will compile. The default being applied is conditional on A implementing Iterator. May be useful for some hacks but seems bogus.

Edit:
We don't even check totally bogus stuff such as:

struct Foo<T, U: FromIterator<T>>(T, U);
struct Bar<Z = Foo<i32, i32>>(Z);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions