about summary refs log tree commit diff
path: root/tests/rustdoc-js-std/parser-errors.js
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2024-11-09 05:03:10 +0000
committerGitHub <noreply@github.com>2024-11-09 05:03:10 +0000
commit8cfb95959b740405b2b85e28d86091b5424de870 (patch)
tree6295949c2a455a318c2d41783b28b8bc4ce29c3d /tests/rustdoc-js-std/parser-errors.js
parentf712eb5cdccd121d0569af12f20e6a0fabe4364d (diff)
parentef0f1cad593c24bc80f0b5d2255fafc561a47030 (diff)
downloadrust-8cfb95959b740405b2b85e28d86091b5424de870.tar.gz
rust-8cfb95959b740405b2b85e28d86091b5424de870.zip
fix: `identity_op` suggestions use correct parenthesis (#13647)
The `identity_op` lint was suggesting code fixes that resulted in
incorrect or broken code, due to missing parenthesis in the fix that
changed the semantics of the code.

For a binary expression, `left op right`, if the `left` was redundant,
it would check if the right side needed parenthesis, but if the `right`
was redundant, it would just assume that the left side did not need
parenthesis.

This can result in rustfix generating broken code and failing, or
generating code that has different behavior than before the fix. e.g.
`-(x + y + 0)` would turn into `-x + y`, changing the behavior, and
`1u64 + (x + y + 0i32) as u64` where `x: i32` and `y: i32` would turn
into `1u64 + x + y as u64`, creating an error where `x` cannot be added
to the other values, as it was never cast to `u64`.

This commit fixes both of these problems by always checking the
non-redundant child of a binary expression for needed parenthesis.

fixes #13470

changelog: [`identity_op`]: Fix suggested code that is broken or has
changed behavior
Diffstat (limited to 'tests/rustdoc-js-std/parser-errors.js')
0 files changed, 0 insertions, 0 deletions