Skip to content

Conversation

EthanTheMaster
Copy link
Contributor

@EthanTheMaster EthanTheMaster commented Oct 10, 2019

This PR has an implementation for the lint suggested in issue #4078. Pushing the same item into a Vec can be done with vec![item; SIZE] or with Vec::resize(). I did try to reduce false positives by not giving lints for for loops with conditional branching, loops, or multiple pushes.

I noticed how problematic these things can be when I saw insidesrc/ptr.rs where the branching makes the loop terminate early. As a result, these kinds of loops are not considered for linting.

for (_, ref mutbl, ref argspan) in decl
    .inputs
    .iter()
    .filter_map(|ty| get_rptr_lm(ty))
    .filter(|&(lt, _, _)| lt.name == out.name)
{
    if *mutbl == MutMutable {
        return;
    }
    immutables.push(*argspan);
}

Similarly, src/booleans.rs has multiple pushes which may occur in an iteration depending on some condition.

for simple in Bool::Not(Box::new(expr)).simplify() {
    match simple {
        Bool::Not(_) | Bool::True | Bool::False => {},
        _ => simplified.push(Bool::Not(Box::new(simple.clone()))),
    }
    let simple_negated = simple_negate(simple);
    if simplified.iter().any(|s| *s == simple_negated) {
        continue;
    }
    simplified.push(simple_negated);
}

changelog: New lint: push_same_item

@flip1995 flip1995 changed the title Issue 4078 New Lint: push same item to Vec (#4078) Oct 10, 2019
@flip1995 flip1995 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 10, 2019
@bors
Copy link
Contributor

bors commented Oct 14, 2019

☔ The latest upstream changes (presumably #4560) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Oct 18, 2019

☔ The latest upstream changes (presumably #4683) made this pull request unmergeable. Please resolve the merge conflicts.

@jplatte
Copy link
Contributor

jplatte commented Oct 18, 2019

@EthanTheMaster you have merge conflict markers in your latest commit (in README.md)

@bors
Copy link
Contributor

bors commented Oct 24, 2019

☔ The latest upstream changes (presumably #4650) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Nov 7, 2019

☔ The latest upstream changes (presumably #4788) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Nov 23, 2019

☔ The latest upstream changes (presumably #4839) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995 flip1995 added the A-lint Area: New lints label Nov 25, 2019
@flip1995
Copy link
Member

Thanks for contributing to Clippy! Sadly this PR was not updated in quite some time. If you waited on input from a reviewer, we're sorry that this fell under the radar. If you want to continue to work on this, just reopen the PR and/or ping a reviewer.

@flip1995 flip1995 closed this May 25, 2020
@flip1995 flip1995 added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 25, 2020
bors added a commit that referenced this pull request 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 pull request 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 pull request 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.
flip1995 added a commit to flip1995/rust-clippy that referenced this pull request Aug 10, 2020
Add the new lint `same_item_push`

changelog: Add the new lint `same_item_push`

Fixed rust-lang#4078. As I said in rust-lang#4078 (comment), I referrerd to rust-lang#4647.
@jonboh
Copy link
Contributor

jonboh commented Oct 10, 2023

@rustbot label -S-inactive-closed

@rustbot rustbot removed the S-inactive-closed Status: Closed due to inactivity label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants