Commit Graph

23 Commits

Author SHA1 Message Date
Ethiraric
c6cb0e99f3 [unnecessary_cast]: Avoid breaking precedence
If the whole cast expression is a unary expression (`(*x as T)`) or an
addressof expression (`(&x as T)`), then not surrounding the suggestion
into a block risks us changing the precedence of operators if the cast
expression is followed by an operation with higher precedence than the
unary operator (`(*x as T).foo()` would become `*x.foo()`, which changes
what the `*` applies on).
The same is true if the expression encompassing the cast expression is a
unary expression or an addressof expression.

The lint supports the latter case, but missed the former one. This PR
fixes that.

Fixes #11968
2024-02-27 16:27:12 +01:00
Guillaume Gomez
762448bc55 Update ui tests 2024-02-23 17:38:39 +01:00
Oli Scherer
3d88fae050 Update ui test crate 2023-08-11 14:02:28 +00:00
Centri3
dcfc6a20db check for fully qualified paths in unnecessary_cast 2023-07-19 05:24:17 -05:00
Centri3
357e80ea0d Ignore more type aliases in unnecessary_cast 2023-06-13 06:51:56 -05:00
Centri3
4c7bc1785d ignore more type aliases in unnecessary_cast
ignore more type aliases in unnecessary_cast
2023-06-11 06:59:01 -05:00
Alex Macleod
4346c992cb Ignore more pointer types in unnecessary_cast 2023-06-08 18:19:35 +00:00
Centri3
d7a98f507a also ensure generics with the same type are linted 2023-05-25 04:17:36 -05:00
Centri3
d2de5769a1 add generics in test 2023-05-25 04:05:13 -05:00
Centri3
7f7979f80b emit unnecessary_cast on raw pointers as well 2023-05-24 10:53:31 -05:00
Oli Scherer
def1705a27 Update to a compiletest-rs version that requires //@ for commands 2023-04-20 14:44:03 +00:00
Jason Newcomb
73f4546d24 Fix unnecessary_cast suggestion when taking a reference 2022-11-30 10:55:48 -05:00
Jason Newcomb
f44b7aa81e Don't lint unnecessary_cast in mixed macro context 2022-11-28 23:58:02 -05:00
kraktus
6f4546a4be [unnecessary_cast] Do not lint negative hexadecimal literals when cast as float
Floats cannot be expressed as hexadecimal literals
2022-10-08 16:15:18 +02:00
TennyZhuang
081f73954b let unnecessary_cast work for trivial non_literal expressions
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:11 +08:00
kraktus
90b446fd38 [unnecessary_cast] add parenthesis when negative number uses a method 2022-10-02 14:35:38 +02:00
Andre Bogus
90fe3bea52 remove parenthesis from unnecessary_cast suggestion 2022-08-27 12:04:19 +02:00
Samuel E. Moelius III
c91a7f0b83 Address review comments 2022-05-27 15:18:46 -04:00
Samuel E. Moelius III
911eb1f4cd Check .fixed paths' existence in run_ui 2022-05-27 15:18:46 -04:00
Jaic1
ec851b870b First submit 2022-03-28 12:09:01 +08:00
Dharma Saputra Wijaya
0d7273fef6 fix bad suggestion on numeric_literal 2022-01-26 15:02:13 +08:00
Cameron Steffen
a39a93faeb Disable unnecessary_cast for cfg-dependant types 2020-11-22 19:35:04 -06:00
Philipp Hansch
2d84d0361d
Split up cast.rs tests, run-rustfix for unnecessary_cast
This splits up the cast.rs tests and enables rustfix tests for the part
of the `unnecessary_cast` lint that emits `MachineApplicable`
suggestions.

cc #3630
2019-08-04 08:24:23 +02:00