Skip to content

We should forbid type parameters from shadowing other types #21301

Description

@erickt

This is a weird case that we should probably not allow:

mod T {
    pub type Type = i32;
}

trait Trait {
    type Type;
}

impl Trait for i32 {
    type Type = i8;
}

struct Baz<T: Trait> {
    a: T::Type,
}

fn main() {
    let x: Baz<i32> = Baz { a: 0i8 };
}

The rule appears to be that the <T: Trait> has precedence over the module, it would be easiest if we just errored out in this circumstance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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