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

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 opened this issue Jul 9, 2023 · 2 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@A4-Tacks
Copy link

A4-Tacks commented Jul 9, 2023

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

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 9, 2023
@A4-Tacks A4-Tacks changed the title The variant of an enumeration has the same name as the method implemented for it, but this does not conflict and cannot call this method 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 Jul 9, 2023
@saethlin saethlin added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Jul 10, 2023
@saethlin
Copy link
Member

This is similar to #76347 which reports the same problem with associated constants.

@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 10, 2023
@petrochenkov
Copy link
Contributor

Closing as a duplicate of #48758.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants