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

@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.

@ada4a
Copy link
Contributor Author

ada4a commented Nov 27, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Nov 27, 2025
gauravagerwala added a commit to gauravagerwala/rust-clippy that referenced this pull request Dec 7, 2025

// - the final expression in the body of a function with a simple return type
(ExprUseNode::Return(_), DefinedTy::Mir { ty: fn_return_ty, .. })
if fn_return_ty.skip_binder().is_simple_text() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this supposed to be checking for? The return type of a function must be a fully defined type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this supposed to be checking for?

Opaque types (like impl Add/Mul, see {add,mul}_turbofish_necessary), and generic types with trait bounds (something like fn sum<T: Add>(ts: &[T]) -> T), it seems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change it to checking for opaque types then. Ty::walk will get you all the types you need to check.

The type of generic parameters can't be changed by inference so you can ignore those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of generic parameters can't be changed by inference

I think they can, if you replace fn foo() -> impl Add with fn foo<T: Add>() -> T

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those aren't the same thing. In fn foo<T>() -> T has the return type determined by the caller; inside the body it must be the abstract type T. With -> impl Trait the return type is determined by the callee with the actual type inferred from whatever the body returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty::walk will get you all the types you need to check

Do you think descending into the generics is necessary, given that .sum()/.product() usually return primitive types? Though I guess nothing would stop an external implementation of Add/Mul from doing something like that...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sum and Product are implemented for Option and Result, so yes.

@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ada4a ada4a force-pushed the unnecessary_fold branch 2 times, most recently from bfdd5b5 to ce5a4a1 Compare December 11, 2025 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants