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

detect unnecessary curly braces #9974

Open
mimoo opened this issue Nov 28, 2022 · 1 comment
Open

detect unnecessary curly braces #9974

mimoo opened this issue Nov 28, 2022 · 1 comment
Labels
A-lint Area: New lints

Comments

@mimoo
Copy link

mimoo commented Nov 28, 2022

What it does

In the following example, there's a single expression inside curly braces. I think clippy should detect that because it is probably not intended. (We have some of these in our codebase due to refactor.)

Lint Name

unecessary_curly_braces

Category

style

Advantage

  • Remove lines of code
  • Removes indentation
  • (Improves readability)

Drawbacks

No response

Example

let a = {
  if cond {
    None
  } else {
    Some(5)
  }
};

Better:

let a = if cond {
  None
} else {
  Some(5)
};
@mimoo mimoo added the A-lint Area: New lints label Nov 28, 2022
@kraktus
Copy link
Contributor

kraktus commented Nov 29, 2022

Hey, thanks for reporting. There’s already a lint at the rustc level: unused_braces. Unfortunately it only triggers on one-line braces, but there’s a PR to expand it, although it’s been stalled on review: rust-lang/rust#102432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants