-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(unnecessary_fold): lint on folds with Add::add/Mul::mul
#16124
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
base: master
Are you sure you want to change the base?
Conversation
| // - the final expression in the body of a function with a simple return type | ||
| if let hir::Node::Block(block) = parent | ||
| && let mut parents = cx.tcx.hir_parent_iter(block.hir_id).map(|(_, def_id)| def_id) | ||
| && let Some(hir::Node::Expr(_)) = parents.next() | ||
| && let Some(hir::Node::Item(enclosing_item)) = parents.next() | ||
| && let hir::ItemKind::Fn { sig, .. } = enclosing_item.kind | ||
| && let hir::FnRetTy::Return(fn_return_ty) = sig.decl.output | ||
| && matches!(fn_return_ty.kind, hir::TyKind::Path(..)) | ||
| { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the previous checks are a subset of what using expr_use_ctxt would get you. You want something like:
if let Some(use_cx) = expr_use_ctxt(cx, expr)
&& use_cx.is_same_ctxt
&& let Some(ty) = use_cx.use_node(cx).defined_ty(cx)
{
// check ty
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for the tip! Changed
|
Reminder, once the PR becomes ready for a review, use |
92cad4a to
22d0416
Compare
|
@rustbot ready |
Resurrects #13475
changelog: [
unnecessary_fold]: lint onfolds withAdd::add/Mul::mul