about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/errors.rs
diff options
context:
space:
mode:
authorTheSlapstickDictator <6685366+TheSlapstickDictator@users.noreply.github.com>2024-11-02 19:47:11 -0700
committerTheSlapstickDictator <6685366+TheSlapstickDictator@users.noreply.github.com>2024-11-02 19:47:11 -0700
commita0b7681a6f5e0522a4e8255961523370256bfd7d (patch)
tree4ce48aae5f3790cde5ca7418690553abebcc879a /compiler/rustc_codegen_llvm/src/errors.rs
parent52b8324503d670646bc54a976bbc6baa9ddde08e (diff)
downloadrust-a0b7681a6f5e0522a4e8255961523370256bfd7d.tar.gz
rust-a0b7681a6f5e0522a4e8255961523370256bfd7d.zip
fix: `identity_op` suggestions use correct parenthesis
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 either rustfix generating broken code and failing,
or 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 broken code where `x` cannot
be added to the other values, as it was never cast to `u64`.

This commit fixes both of these cases by always checking the
non-redundant child of a binary expression for needed parenthesis, and
makes it so if we need parenthesis, but they already exist, we don't add
any redundant ones.

Fixes #13470
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/errors.rs')
0 files changed, 0 insertions, 0 deletions