Skip to content

fix incorrect suggestions related to parentheses in needless_return #14094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3552,7 +3552,7 @@ pub fn is_block_like(expr: &Expr<'_>) -> bool {
pub fn binary_expr_needs_parentheses(expr: &Expr<'_>) -> bool {
fn contains_block(expr: &Expr<'_>, is_operand: bool) -> bool {
match expr.kind {
ExprKind::Binary(_, lhs, _) => contains_block(lhs, true),
ExprKind::Binary(_, lhs, _) | ExprKind::Cast(lhs, _) => contains_block(lhs, true),
_ if is_block_like(expr) => is_operand,
_ => false,
}
Expand Down
12 changes: 11 additions & 1 deletion tests/ui/needless_return.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
clippy::single_match,
clippy::needless_bool,
clippy::equatable_if_let,
clippy::needless_else
clippy::needless_else,
clippy::missing_safety_doc
)]
#![warn(clippy::needless_return)]

Expand Down Expand Up @@ -442,3 +443,12 @@ fn b(x: Option<u8>) -> Option<u8> {
},
}
}

unsafe fn todo() -> *const u8 {
todo!()
}

pub unsafe fn issue_12157() -> *const i32 {
(unsafe { todo() } as *const i32)
//~^ needless_return
}
12 changes: 11 additions & 1 deletion tests/ui/needless_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
clippy::single_match,
clippy::needless_bool,
clippy::equatable_if_let,
clippy::needless_else
clippy::needless_else,
clippy::missing_safety_doc
)]
#![warn(clippy::needless_return)]

Expand Down Expand Up @@ -451,3 +452,12 @@ fn b(x: Option<u8>) -> Option<u8> {
},
}
}

unsafe fn todo() -> *const u8 {
todo!()
}

pub unsafe fn issue_12157() -> *const i32 {
return unsafe { todo() } as *const i32;
//~^ needless_return
}
Loading