Skip to content

Suggestion to "surround the struct literal in parentheses" sometimes places the opening parenthesis after the module name #112278

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
bernardosulzbach opened this issue Jun 4, 2023 · 0 comments · Fixed by #112475
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bernardosulzbach
Copy link
Contributor

Code

mod module {
    #[derive(Eq, PartialEq)]
    pub struct Type {
        pub x: u8,
        pub y: u8,
    }

    pub const C: u8 = 32u8;
}

fn test(x: module::Type) -> i32 {
    if x == module::Type { x: module::C, y: 1 } {
        1
    } else {
        0
    }
}

Current output

error: invalid struct literal
  --> <source>:12:21
   |
12 |     if x == module::Type { x: module::C, y: 1 } {
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: you might need to surround the struct literal in parentheses
   |
12 |     if x == module::(Type { x: module::C, y: 1 }) {
   |                     +                           +

Desired output

error: invalid struct literal
  --> <source>:12:21
   |
12 |     if x == module::Type { x: module::C, y: 1 } {
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: you might need to surround the struct literal in parentheses
   |
12 |     if x == (module::Type { x: module::C, y: 1 }) {
   |             +                                   +

Rationale and extra context

No response

Other cases

No response

Anything else?

This defect is reproducible with (at least) 1.68, 1.69, beta, and nightly.

Furthermore, I think it would be good to reword the message to suggest surrounding with parentheses.

@bernardosulzbach bernardosulzbach added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 4, 2023
@chenyukang chenyukang self-assigned this Jun 6, 2023
@bors bors closed this as completed in e19a509 Jun 11, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants