Skip to content

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

Closed
@booleancoercion

Description

@booleancoercion

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions