Skip to content

Conversation

@sergiogiro
Copy link

@sergiogiro sergiogiro commented Nov 16, 2025

Fixes #16019 by reborrowing, instead of using by_ref, when the iterator expression is not Sized.

changelog: [`while_let_on_iterator`]: fixes broken suggestion by using reborrow instead of `by_ref` for references to traits that are not `Sized`

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 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

@github-actions
Copy link

github-actions bot commented Nov 16, 2025

No changes for f4496bf

@Jarcho
Copy link
Contributor

Jarcho commented Nov 17, 2025

The suggestion used to be to borrow/reborrow before it was changed to by_ref. The only change that needs to happen is a check if the iterator expression has a type of &mut ?Sized. The can be done by checking the type's kind for a reference and using Ty::is_sized on the referent type.

@sergiogiro
Copy link
Author

The suggestion used to be to borrow/reborrow before it was changed to by_ref. The only change that needs to happen is a check if the iterator expression has a type of &mut ?Sized. The can be done by checking the type's kind for a reference and using Ty::is_sized on the referent type.

Great, thanks, I can rework the PR to do a reborrow only when needed.

@sergiogiro sergiogiro force-pushed the sergio-clippy/avoid-by-ref-in-suggestion-for-while-replacement branch from 9638f9c to 1c8b099 Compare November 17, 2025 13:13
@sergiogiro sergiogiro force-pushed the sergio-clippy/avoid-by-ref-in-suggestion-for-while-replacement branch from 1c8b099 to f4496bf Compare November 17, 2025 13:19
@sergiogiro
Copy link
Author

Thanks for the advice. Now the PR just changes the behaviour for non-sized types, and adds a couple tests accordingly.

@sergiogiro sergiogiro changed the title Fixes #16109: Avoid by_ref in suggestions to remove while-let loops Fixes #16109: For non-sized types, use reborrow in suggestions to remove while-let loops Nov 17, 2025
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.

while_let_on_iterator suggested solution doesn't work in default implementations of traits without explicit Sized bound

3 participants