Closed
Description
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.
- This is verifiable with
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).