Skip to content

Namespacing of member in impl #72980

Duplicate
Duplicate
@ldm0

Description

@ldm0
Contributor

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

Activity

added
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
T-langRelevant to the language team
on Jun 4, 2020
fmease

fmease commented on Dec 21, 2024

@fmease
Member

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

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

    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

        Participants

        @jonas-schievink@fmease@ldm0

        Issue actions

          Namespacing of member in impl · Issue #72980 · rust-lang/rust