Skip to content

Commit

Permalink
Prevent "unnecessary parentheses" warnings in generated expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jul 25, 2023
1 parent cd283d9 commit 44e6bea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cast_checks/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,19 @@ fn inferred_type(x: f64) -> i32 {
fn block_expression(x: u32) -> f64 {
x as f64 / 2.0
}

#[allow(
arithmetic_overflow,
dead_code,
clippy::cast_lossless,
clippy::neg_multiply
)]
#[cast_checks::enable]
#[deny(unused_parens, clippy::double_parens)]
fn unused_parens(use_parens: bool) -> i64 {
if use_parens {
(-1 * i32::MIN) as i64
} else {
-1 * i32::MIN as i64
}
}
1 change: 1 addition & 0 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl VisitMut for Visitor {
#[allow(unused_imports)]
use cast_checks::MaybeTryIntoFallback;

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

0 comments on commit 44e6bea

Please sign in to comment.