Skip to content

Commit 44e6bea

Browse files
committed
Prevent "unnecessary parentheses" warnings in generated expressions
1 parent cd283d9 commit 44e6bea

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cast_checks/tests/basic.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,19 @@ fn inferred_type(x: f64) -> i32 {
7474
fn block_expression(x: u32) -> f64 {
7575
x as f64 / 2.0
7676
}
77+
78+
#[allow(
79+
arithmetic_overflow,
80+
dead_code,
81+
clippy::cast_lossless,
82+
clippy::neg_multiply
83+
)]
84+
#[cast_checks::enable]
85+
#[deny(unused_parens, clippy::double_parens)]
86+
fn unused_parens(use_parens: bool) -> i64 {
87+
if use_parens {
88+
(-1 * i32::MIN) as i64
89+
} else {
90+
-1 * i32::MIN as i64
91+
}
92+
}

macro/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl VisitMut for Visitor {
9090
#[allow(unused_imports)]
9191
use cast_checks::MaybeTryIntoFallback;
9292

93+
#[allow(unused_parens, clippy::double_parens)]
9394
if let Some(result) = cast_checks::MaybeTryInto::<_, #ty >::new( #operand ).maybe_try_into() {
9495
result.expect( #msg )
9596
} else {

0 commit comments

Comments
 (0)