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

Improper parenthesis addition when using clippy_lints::utils::Sugg::maybe_par #6767

Closed
booleancoercion opened this issue Feb 19, 2021 · 0 comments · Fixed by #7013
Closed
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@booleancoercion
Copy link
Contributor

booleancoercion commented Feb 19, 2021

While working on #6717, I noticed that sometimes an expression like (1+2) would be (falsely?) converted to a Sugg::BinOp, which coupled with the maybe_par method would produce the suggestion ((1+2)).

I'm not sure where the issue is: should the expression have been converted into a NonParen in the first place, or does maybe_par need to have an additional check when working with BinOp? If it's the latter, care must be taken because a simple check that the boundaries are () is wrong: for example, (1+2) + (3+4).

Also related - shouldn't the MaybeParen branch always return a NonParen?

It should be noted that this bug affects the following lints:

  • floating_point_log
  • from_str_radix_10 (WIP)
  • manual_memcpy
@booleancoercion booleancoercion added the C-bug Category: Clippy is not doing the correct thing label Feb 19, 2021
@camsteffen camsteffen added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-suggestion Lint: Improving, adding or fixing lint suggestions labels Feb 22, 2021
bors added a commit that referenced this issue Apr 1, 2021
clippy_utils: fix needless parenthesis output from sugg::Sugg::maybe_par

changelog: clippy_utils: fix needless parenthesis output from `sugg::Sugg::maybe_par`

fixes: #6767
@bors bors closed this as completed in 72eb60a Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants