Skip to content

Conversation

@ada4a
Copy link
Contributor

@ada4a ada4a commented Nov 21, 2025

Resurrects #13475

changelog: [unnecessary_fold]: lint on folds with Add::add/Mul::mul

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Comment on lines +45 to +55
// - 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;
}
Copy link
Contributor

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
}

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Nov 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 26, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants