fix: don't suggest .into_iter() for .cloned()/.copied() on owned items#151188
fix: don't suggest .into_iter() for .cloned()/.copied() on owned items#151188RafeSymonds wants to merge 2 commits intorust-lang:mainfrom
Conversation
249538f to
0affc1a
Compare
|
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` |
There was a problem hiding this comment.
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
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
Issue: #151147
Prevents the compiler from suggesting
IntoIteratorwhen.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.