Skip to content

Commit 1cd7022

Browse files
committed
fix incorrect suggestions related to parentheses in needless_return
1 parent a8b1782 commit 1cd7022

File tree

4 files changed

+90
-58
lines changed

4 files changed

+90
-58
lines changed

clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3552,7 +3552,7 @@ pub fn is_block_like(expr: &Expr<'_>) -> bool {
35523552
pub fn binary_expr_needs_parentheses(expr: &Expr<'_>) -> bool {
35533553
fn contains_block(expr: &Expr<'_>, is_operand: bool) -> bool {
35543554
match expr.kind {
3555-
ExprKind::Binary(_, lhs, _) => contains_block(lhs, true),
3555+
ExprKind::Binary(_, lhs, _) | ExprKind::Cast(lhs, _) => contains_block(lhs, true),
35563556
_ if is_block_like(expr) => is_operand,
35573557
_ => false,
35583558
}

tests/ui/needless_return.fixed

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
clippy::single_match,
77
clippy::needless_bool,
88
clippy::equatable_if_let,
9-
clippy::needless_else
9+
clippy::needless_else,
10+
clippy::missing_safety_doc
1011
)]
1112
#![warn(clippy::needless_return)]
1213

@@ -442,3 +443,12 @@ fn b(x: Option<u8>) -> Option<u8> {
442443
},
443444
}
444445
}
446+
447+
unsafe fn todo() -> *const u8 {
448+
todo!()
449+
}
450+
451+
pub unsafe fn issue_12157() -> *const i32 {
452+
(unsafe { todo() } as *const i32)
453+
//~^ needless_return
454+
}

tests/ui/needless_return.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
clippy::single_match,
77
clippy::needless_bool,
88
clippy::equatable_if_let,
9-
clippy::needless_else
9+
clippy::needless_else,
10+
clippy::missing_safety_doc
1011
)]
1112
#![warn(clippy::needless_return)]
1213

@@ -451,3 +452,12 @@ fn b(x: Option<u8>) -> Option<u8> {
451452
},
452453
}
453454
}
455+
456+
unsafe fn todo() -> *const u8 {
457+
todo!()
458+
}
459+
460+
pub unsafe fn issue_12157() -> *const i32 {
461+
return unsafe { todo() } as *const i32;
462+
//~^ needless_return
463+
}

0 commit comments

Comments
 (0)