rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

lint on unnecessary collections

Open bend-n opened this issue 2 months ago • 8 comments

lints on

fn squares() -> Vec<(u8, u8)> {
 (0..8u8)
   .flat_map(|x| (0..8).map(move |y| (x, y)))
   .collect::<Vec<_>>()
}

changelog: [unnecessary_collect]: create lint

see also #clippy > linting on vector returns where return is collected

name can be bikeshed

bend-n avatar Oct 07 '25 12:10 bend-n

r? @llogiq

rustbot has assigned @llogiq. 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 avatar Oct 07 '25 12:10 rustbot

Lintcheck changes for 7e91e188c5209d26fa135c1cf525b34452c116a6

Lint Added Removed Changed
clippy::unnecessary_collect 36 0 0

This comment will be updated if you push new changes

github-actions[bot] avatar Oct 07 '25 12:10 github-actions[bot]

Some changes occurred in clippy_lints/src/doc

cc @notriddle

rustbot avatar Oct 07 '25 13:10 rustbot

:umbrella: The latest upstream changes (possibly 0a2eeceefcd99185643f7659ce25b6376749c271) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Oct 07 '25 16:10 rustbot

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.

rustbot avatar Nov 07 '25 17:11 rustbot

:umbrella: The latest upstream changes (possibly c48592eb49d984aee2f813336e2363798e004119) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Nov 14 '25 14:11 rustbot

I personally think that the lint as is probably fits a restriction lint best (and should be documented to only show possible optimization opportunities), however, with an additional check if the result of that method ever is manipulated other than iterating it, and only linting if that's not the case would make the lint vastly more useful.

However, I don't think this PR needs to do the extension.

llogiq avatar Nov 14 '25 17:11 llogiq

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.

rustbot avatar Nov 15 '25 11:11 rustbot