Skip to content

Conversation

@keirsalterego
Copy link

@keirsalterego keirsalterego commented Dec 14, 2025

Description

I updated the useless_conversion lint to stop applying adjustment prefixes once it reaches the final target type.

Previously, the lint would continue applying adjustments even after the type requirements were met, which often resulted in over-borrowed suggestions like &**y. By breaking the loop early once the target type is reached, we now emit the minimal, idiomatic suggestion (e.g., *y).

fixes #14847

Test Plan

I added a targeted UI regression test: tests/ui/useless_conversion.rs.
This covers .into_iter() usage on nested slice references (&&[T]) and verifies that Clippy now suggests *items instead of the previous incorrect suggestion.

Checklist

  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Run cargo dev fmt

changelog: [useless_conversion]: refine .into_iter() suggestions to stop at the final target type (fixing over-borrowed suggestions like &**y)

Copilot AI review requested due to automatic review settings December 14, 2025 10:22
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 14, 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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refines the useless_conversion lint to fix over-borrowed suggestions when dealing with .into_iter() calls on nested references. The core change modifies the adjustments function to include early-break logic that stops processing adjustments once the target type is reached.

  • Adds early break logic in the adjustments function to stop at the target type
  • Introduces a regression test for .into_iter() on nested slice references (&&[T])

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
clippy_lints/src/useless_conversion.rs Modified adjustments function to break early when reaching the target type, preventing over-application of adjustment prefixes
tests/ui/useless_conversion_into_iter_adjustments.rs Added regression test for issue #14847 testing .into_iter() on &&[i32]
tests/ui/useless_conversion_into_iter_adjustments.stderr Expected test output showing the corrected suggestion (*items instead of over-borrowed alternatives)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

View changes since this review

@rustbot

This comment has been minimized.

Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

The added tests should be added to test/ui/useless_conversion.rs, not in there own file. Can you please also squash this into a single commit.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Dec 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 15, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@keirsalterego keirsalterego force-pushed the fix-useless-conversion-14847 branch 2 times, most recently from 2648e37 to 1607099 Compare December 17, 2025 13:35
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Dec 17, 2025
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

Missed something on the last review.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Dec 18, 2025
@keirsalterego keirsalterego force-pushed the fix-useless-conversion-14847 branch 3 times, most recently from b91ac03 to 2d7954c Compare December 18, 2025 09:27
@keirsalterego keirsalterego force-pushed the fix-useless-conversion-14847 branch from 2d7954c to 854660d Compare December 18, 2025 10:16
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Dec 18, 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.

Suggestion for useless_conversion with .into_iter() could be better

3 participants