Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We should forbid type parameters from shadowing other types #21301

Closed
erickt opened this issue Jan 17, 2015 · 5 comments
Closed

We should forbid type parameters from shadowing other types #21301

erickt opened this issue Jan 17, 2015 · 5 comments
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@erickt
Copy link
Contributor

erickt commented Jan 17, 2015

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.

@kmcallister kmcallister added the A-associated-items Area: Associated items (types, constants & functions) label Jan 17, 2015
@kmcallister
Copy link
Contributor

Nominating for reasons of backwards-incompatibility.

@kmcallister
Copy link
Contributor

(Though adding a lint would be back-compat, aiui)

@nikomatsakis
Copy link
Contributor

I for one am not convinced we should disallow this. We disallow type parameters from shadowing one another specifically because it came up very frequently. This seems less likely to arise frequently (it relies on not following our suggested naming conventions for type parameters and modules, for one thing).

@nikomatsakis
Copy link
Contributor

(Even if it did come up frequently, I'd probably rather just work on the error messages that result.)

@rust-highfive
Copy link
Collaborator

This issue has been moved to the RFCs repo: rust-lang/rfcs#707

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions)
Projects
None yet
Development

No branches or pull requests

5 participants