Skip to content

unused_parens help text as of 1.92 suggests replacing paren with space, looks weird #158583

Description

@carols10cents

Code

fn main() {
    let x = (let y = 6);
}

Current output

warning: unnecessary parentheses around assigned value
 --> src/main.rs:2:13
  |
2 |     let x = (let y = 6);
  |             ^         ^
  |
  = note: `#[warn(unused_parens)]` (part of `#[warn(unused)]`) on by default
help: remove these parentheses
  |
2 -     let x = (let y = 6);
2 +     let x = let y = 6 ;
  |

Desired output

warning: unnecessary parentheses around assigned value
 --> src/main.rs:2:13
  |
2 |     let x = (let y = 6);
  |             ^         ^
  |
  = note: `#[warn(unused_parens)]` (part of `#[warn(unused)]`) on by default
help: remove these parentheses
  |
2 -     let x = (let y = 6);
2 +     let x = let y = 6;
  |

Rationale and extra context

This is like the teeniest tiniest bug, but it's a relatively recent regression and looks weird, so here I am!

TRPL shows error messages to illustrate various concepts. When I update the version of Rust that the book is using, I regenerate and check in all the error messages for the listings.

When I upgraded the book from 1.91.1 to 1.92.0, this warning's help suggestion changed from suggesting that removing the parentheses should produce:

let x = let y = 6;

to suggesting that it should produce:

let x = let y = 6 ;

Note that the right parenthesis was replaced by a space, rather than being removed.

Please ignore that there is also an error in addition to this warning and that neither the original code nor the suggestion are valid Rust. I don't think that's relevant, it's just how I found the issue.

The issue can also be reproduced with this valid Rust:

fn main() {
    let x = (3 + 6);
}

which also shows the space between the 6 and semicolon that I don't think should be there:

  = note: `#[warn(unused_parens)]` (part of `#[warn(unused)]`) on by default
help: remove these parentheses
  |
2 -     let x = (3 + 6);
2 +     let x = 3 + 6 ;
  |

Rust Version

$ rustc --version --verbose
rustc 1.96.0 (ac68faa20 2026-05-25)
binary: rustc
commit-hash: ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96
commit-date: 2026-05-25
host: aarch64-apple-darwin
release: 1.96.0
LLVM version: 22.1.2

Anything else?

This first started appearing in stable 1.92.0, continues to reproduce through stable 1.96.0, and also reproduces with 1.98.0-nightly (2026-06-28 df6ee90).

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions