Skip to content

The variant of an enumeration has the same name as the function implemented for it, but this does not conflict and cannot call this function #113503

Closed
@A4-Tacks

Description

@A4-Tacks

The variant of an enumeration has the same name as the function implemented for it, but this does not conflict and cannot call this function

Example

fn main() {
    let _x = Foo::Value(0, ());
    //let _y = Foo::Value(0); // error
}
pub enum Foo {
    Value(usize, ()),
    Nil
}
impl Foo {
    /// It cannot be used, and no errors!!
    #[allow(non_snake_case)]
    pub fn Value(num: usize) -> Self {
        Self::Value(num, ())
    }
}

Info

  • cargo check no errors and warnings.
  • rustc --version: rustc 1.70.0 (90c541806 2023-05-31)
  • rustc +nightly --version: rustc 1.72.0-nightly (fe7454bf4 2023-06-19)

Expected

error[E0592]: duplicate definitions with name 'Value' or this function can be called

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions