Skip to content

Namespacing of member in impl #72980

Closed as duplicate
Closed as duplicate
@ldm0

Description

@ldm0

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions