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

let (_ = 3; causes suggestion to remove a paren that is only hypothetical #103497

Closed
jruderman opened this issue Oct 24, 2022 · 2 comments
Closed
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

@jruderman
Copy link
Contributor

Given the following code (playground):

fn main() {
    let (_ = 3;
}

The current output is:

error: expected one of `)`, `,`, or `|`, found `=`
 --> es4.rs:2:9
  |
2 |     let (_ = 3;
  |         ^ -^
  |         | |
  |         | help: `)` may belong here
  |         unclosed delimiter

error: expected expression, found `)`
 --> es4.rs:3:1
  |
3 | }
  | ^ expected expression

warning: unnecessary parentheses around pattern
 --> es4.rs:2:9
  |
2 |     let (_ = 3;
  |         ^ ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 -     let (_ = 3;
2 +     let _ = 3;
  |

The final warning, "unnecessary parentheses around pattern", is sus:

  • The compiler shouldn't be so sure that the parens are "unnecessary" when the compiler had to guess where the end-paren was
  • In the suggestion, the second span is empty (the location at which a hypothetical end-paren might be missing) and its suggested replacement is also empty (the lack of a paren).
    • This is verifiable with --error-format=json.
    • The second yellow caret-arrow, appearing to point to the space after the underscore, is a visual sign that something is not quite right.
    • In rustc builds with debug_assert enables, this trips a recently-added assertion.
thread 'rustc' panicked at 'Span must not be empty and have no suggestion', compiler/rustc_errors/src/diagnostic.rs:570:9

Found by fuzzing with a modified fuzz-rustc, combined with this very reasonable new assertion in rustc (added by @kper in #102922).

@jruderman jruderman 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 Oct 24, 2022
@On0n0k1
Copy link

On0n0k1 commented Oct 25, 2022

In the second suggestion. You mentioned that the suggested location for ')' was after the underscore '_'.

Maybe, instead, this is because the location is behind the '=' operator. If the operator was '==', the checker could have kept searching. But a parentheses can't exist surrounding a '=' operation. So the guess was correct.

@jruderman
Copy link
Contributor Author

Obsoleted by #108297. The compiler now exits early if there are unclosed delimiters.

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

No branches or pull requests

2 participants