Skip to content

With a generic struct, Self(x) works where x is of the wrong type argument #61882

Closed
@Centril

Description

@Centril

In particular, we can write:

struct A<T>(T);

impl A<bool> {
    const B: A<u8> = Self(0); // OK but shouldn't be?

    const C: A<u8> = Self { 0: 0 }; // Correctly rejected.
}

This can lead to the following interesting situation:

struct A<T>(T);

impl A<bool> {
    const B: Self = Self(0); // Rejected, so `Self(..)` is not of type `Self`?
}

cc @petrochenkov, @varkor, @eddyb, and @alexreg

This does seem like a bug to me... In particular, type_alias_enum_variants does not allow Self::Some(transform(x)) where Self == Option<T> but where Option<U> is expected.

cc @rust-lang/lang

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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