Skip to content

Suggested fix has incorrect syntax #45037

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

Closed
sunjay opened this issue Oct 5, 2017 · 2 comments
Closed

Suggested fix has incorrect syntax #45037

sunjay opened this issue Oct 5, 2017 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@sunjay
Copy link
Member

sunjay commented Oct 5, 2017

Minimal reproduction: (Playground)

mod button {
    pub enum Button {}
}

mod button2 {
    pub struct Button();
}

use button::Button;

fn main() {
    use self::Button::*;
    let b = unimplemented!();
    match b {
        // match a different button that needs to be imported, but isn't yet
        Button(..) => unimplemented!(),
    }
}

This produces the error message:

error[E0532]: expected tuple struct/variant, found enum `Button`
  --> src/main.rs:16:9
   |
16 |         Button(..) => unimplemented!(),
   |         ^^^^^^ not a tuple struct/variant
   |
help: possible better candidate is found in another module, you can import it into scope
   |
11 | fn main() use button2::Button;
   |

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Notice that the suggested fix is:

11 | fn main() use button2::Button;

This is incorrect syntax.

More Details

If you remove the use self::Button::* line, the error is normal again:

error[E0532]: expected tuple struct/variant, found enum `Button`
  --> src/main.rs:15:9
   |
15 |         Button(..) => unimplemented!(),
   |         ^^^^^^ not a tuple struct/variant
   |
help: possible better candidate is found in another module, you can import it into scope
   |
1  | use button2::Button;
   |

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

In fact, this only occurs if you have both a struct and an enum with the same name.

Meta

$ rustc --version --verbose
rustc 1.20.0 (f3d6973f4 2017-08-27)
binary: rustc
commit-hash: f3d6973f41a7d1fb83029c9c0ceaf0f5d4fd7208
commit-date: 2017-08-27
host: x86_64-unknown-linux-gnu
release: 1.20.0
LLVM version: 4.0
@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 5, 2017
@kennytm
Copy link
Member

kennytm commented Oct 5, 2017

Duplicate of #42548. Already fixed by #43929, and no repro on 1.21 (beta).

@sunjay
Copy link
Member Author

sunjay commented Oct 5, 2017

Cool thanks!

@sunjay sunjay closed this as completed Oct 5, 2017
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