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

Creating data-less enum variant with data yields a confusing error message #28533

Closed
nagisa opened this issue Sep 20, 2015 · 1 comment
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@nagisa
Copy link
Member

nagisa commented Sep 20, 2015

enum Test {
    Variant,
    Variant2(&'static str)
}

fn main(){
    let y = Test::Variant2("Hello");
    let x = Test::Variant("World");
}

results in

<anon>:8:13: 8:35 error: expected function, found `Test`
<anon>:8     let x = Test::Variant("World");
                     ^~~~~~~~~~~~~~~~~~~~~~

The error should say something about variant not being able to contain any data instead.

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 28, 2015
bors added a commit that referenced this issue Nov 9, 2016
Reword error when data-less enum variant called as function

Given a file like:

``` rust
enum Test {
    Variant,
    Variant2 {a: u32},
}

fn main(){
    let x = Test::Variant("Hello");
    let y = Test::Variant2("World");
}
```

Both errors now look similar:

``` bash
error[E0423]: `Test::Variant2` is the name of a struct or struct variant, but this expression uses it like a function name
  --> file3.rs:10:13
   |
10 |     let y = Test::Variant2("Hello");
   |             ^^^^^^^^^^^^^^ struct called like a function
   |
   = help: did you mean to write: `Test::Variant2 { /* fields */ }`?

error: `Test::Variant` is the name of a data-less enum, but this expression uses it like a function name
 --> file3.rs:9:13
  |
9 |     let x = Test::Variant("World");
  |             ^^^^^^^^^^^^^^^^^^^^^^ data-less enum called like a function
  |
  = help: did you mean to write: `Test::Variant`?
note: defined here
 --> file3.rs:2:5
  |
2 |     Variant,
  |     ^^^^^^^

error: aborting due to previous error
```

Re: #28533
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

Closing, we suggest to not call it today and provide the definition site.

error: `Test::Variant` is being called, but it is not a function
 --> test.rs:8:13
  |
8 |     let x = Test::Variant("World");
  |             ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: did you mean to write `Test::Variant`?
note: defined here
 --> test.rs:2:5
  |
2 |     Variant,
  |     ^^^^^^^

error: aborting due to previous error(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

3 participants