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

Namespacing of member in impl #72980

Closed
ldm0 opened this issue Jun 4, 2020 · 1 comment
Closed

Namespacing of member in impl #72980

ldm0 opened this issue Jun 4, 2020 · 1 comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@ldm0
Copy link
Contributor

ldm0 commented Jun 4, 2020

enum namespacing was introduced in RFC 390, which makes the following code compiles:

enum Emm {
    A,
    B,
}

fn main() {
    use Emm::*;
    let a = A;
    let b = B;
}

However:

struct Emm;
impl Emm {
    const A: usize = 0;
    const B: usize = 1;
}

fn main() {
    // Compiles
    let a = Emm::A;
    let b = Emm::B;

    // Doesn't compile
    use Emm::*;
    let a = A;
    let b = B;
}

I think it would be usefule if we have namespacing of member in impl? I met this issue on using bitflags, which depends on the feature of declaring const value in an impl block. Without namespacing of impl member we get this result:

use bitflags::bitflags;
bitflags! {
    struct Flags: u32 {
        const A = 0b00000001;
        const B = 0b00000010;
    }
}

fn main() {
    // Compiles
    let e = Flags::A | Flags::B;

   // Doesn't compile
    use Flags::*;
    let e = A | B;
}
@jonas-schievink jonas-schievink added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jun 4, 2020
@fmease
Copy link
Member

fmease commented Dec 21, 2024

Closing in favor of rust-lang/rfcs#3591.
Also CC rust-lang/rfcs#3530.

@fmease fmease closed this as completed Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants