Skip to content

fix: don't suggest .into_iter() for .cloned()/.copied() on owned items - #151188

Open
RafeSymonds wants to merge 2 commits into
rust-lang:mainfrom
RafeSymonds:fix-option-cloned-diagnostic
Open

fix: don't suggest .into_iter() for .cloned()/.copied() on owned items#151188
RafeSymonds wants to merge 2 commits into
rust-lang:mainfrom
RafeSymonds:fix-option-cloned-diagnostic

Conversation

@RafeSymonds

@RafeSymonds RafeSymonds commented Jan 16, 2026

Copy link
Copy Markdown

Issue: #151147
Prevents the compiler from suggesting IntoIterator when .cloned() or .copied() is called on a collection that doesn't contain references. This avoids misleading suggestions where the fix would still result in a type error.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 16, 2026
@rustbot

rustbot commented Jan 16, 2026

Copy link
Copy Markdown
Collaborator

r? @lcnr

rustbot has assigned @lcnr.
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

Comment thread compiler/rustc_hir_typeck/src/method/suggest.rs Outdated
@RafeSymonds
RafeSymonds force-pushed the fix-option-cloned-diagnostic branch from 249538f to 0affc1a Compare January 16, 2026 23:30
@rustbot

rustbot commented Jan 16, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is neededβ€”this note is just to help reviewers.

--> $DIR/into-iter-on-cloned.rs:8:20
|
LL | let _: i32 = x.copied().unwrap();
| ^^^^^^ help: delete the call to `copied`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I disagree with this help message. We should not suggest to remove cloned here. Maybe the user wanted to clone the option to avoid incorrectly moving it.

I do agree that we should improve impl_into_iterator_should_be_iterator to not suggest into_iterator if the following method is actually still incorrect. In a sense, we should strengthen impl_into_iterator_should_be_iterator to check all unsatisfied predicates, instead of always returning yes for a single self: Iterator one

@reddevilmidzy

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2026
@rustbot

rustbot commented Jan 20, 2026

Copy link
Copy Markdown
Collaborator

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

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

β˜” The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants