Skip to content
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

Suggest resize rather when pushing same item to vec #4078

Closed
pickfire opened this issue May 10, 2019 · 3 comments · Fixed by #5825
Closed

Suggest resize rather when pushing same item to vec #4078

pickfire opened this issue May 10, 2019 · 3 comments · Fixed by #5825
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group

Comments

@pickfire
Copy link
Contributor

pickfire commented May 10, 2019

Example in https://github.com/Gymmasssorla/finshir/blob/eae5d0c6761f5558c8ed33ef098d8bd13a07e64f/src/testing/helpers.rs#L55-L61

When pushing the same item to vec.

fn gen_portions() -> Vec<Vec<u8>> {
    let mut spaces = Vec::with_capacity(EMPTY_SPACES_COUNT);
    for _ in 0..EMPTY_SPACES_COUNT {
        spaces.push(vec![b' ']);
    }
    spaces
}

Could be.

fn gen_portions() -> Vec<Vec<u8>> {
    let mut spaces = Vec::with_capacity(EMPTY_SPACES_COUNT);
    spaces.resize(EMPTY_SPACES_COUNT, vec![b' ']);
    spaces
}

Maybe we could even use vec![b''].repeat(EMPTY_SPACES_COUNT) after stabilization ofrepeat_generic_size? rust-lang/rust#48784

@flip1995 flip1995 added L-complexity Lint: Belongs in the complexity lint group good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels May 13, 2019
EthanTheMaster added a commit to EthanTheMaster/rust-clippy that referenced this issue Oct 10, 2019
@giraffate
Copy link
Contributor

Was this attached PR #4647 closed just because the conflict was not resolved? If so, and if no one is interested, can I take over?

@pickfire
Copy link
Contributor Author

pickfire commented Jul 14, 2020

@giraffate I believe no one is working on this, sure please go ahead. The PR also provide a good suggestion with vec![item; SIZE] which wasn't discussed here.

@flip1995
Copy link
Member

@giraffate All issued marked with S-inactive-closed are "free for all" and can be picked up and completed anytime.

bors added a commit that referenced this issue Aug 7, 2020
Add the new lint `same_item_push`

changelog: Add the new lint `same_item_push`

Fixed #4078. As I said in #4078 (comment), I referrerd to #4647.
bors added a commit that referenced this issue Aug 7, 2020
Add the new lint `same_item_push`

changelog: Add the new lint `same_item_push`

Fixed #4078. As I said in #4078 (comment), I referrerd to #4647.
bors added a commit that referenced this issue Aug 10, 2020
Add the new lint `same_item_push`

changelog: Add the new lint `same_item_push`

Fixed #4078. As I said in #4078 (comment), I referrerd to #4647.
@bors bors closed this as completed in 9da5b6d Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants