Skip to content

manual_slice_fill: do not initialize from the iterator#14191

Merged
dswij merged 2 commits intorust-lang:masterfrom
samueltardieu:push-nwommozmsnos
Feb 22, 2025
Merged

manual_slice_fill: do not initialize from the iterator#14191
dswij merged 2 commits intorust-lang:masterfrom
samueltardieu:push-nwommozmsnos

Conversation

@samueltardieu
Copy link
Copy Markdown
Member

@samueltardieu samueltardieu commented Feb 10, 2025

let mut tmp = vec![1, 2, 3];
for b in &mut tmp {
    *b = !*b;
}

must not suggest the invalid tmp.fill(!*b).

In addition, there is another commit which cleans up two function calls with no effect.

Fix #14189

changelog: [manual_slice_fill]: ensure that the initialization expression doesn't reference the iterator

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 10, 2025

r? @Manishearth

rustbot has assigned @Manishearth.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 10, 2025
@samueltardieu
Copy link
Copy Markdown
Member Author

r? clippy

@samueltardieu
Copy link
Copy Markdown
Member Author

samueltardieu commented Feb 10, 2025

(ping @lapla-cogito who is the author of this new lint)

@Manishearth
Copy link
Copy Markdown
Member

r? clippy

Still traveling

@rustbot rustbot assigned dswij and unassigned Centri3 Feb 10, 2025
@samueltardieu
Copy link
Copy Markdown
Member Author

Rebased

In both instances, `!assign_val.span.from_expansion()` – which is more
restrictive than `span_is_local(assign_val.span)` – has been required
already.
```rust
let mut tmp = vec![1, 2, 3];
for b in &mut tmp {
    *b = !*b;
}
```

must not suggest the invalid `tmp.fill(!*b)`.
Copy link
Copy Markdown
Member

@dswij dswij left a comment

Choose a reason for hiding this comment

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

Thanks!

@dswij dswij added this pull request to the merge queue Feb 22, 2025
Merged via the queue into rust-lang:master with commit d92da0f Feb 22, 2025
@samueltardieu samueltardieu deleted the push-nwommozmsnos branch February 23, 2025 10:05
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.

manual_slice_fill shouldn't apply when the fill is variable

6 participants