fix: don't suggest .into_iter() for .cloned()/.copied() on non-reference Option#157413
Open
Albab-Hasan wants to merge 1 commit into
Open
fix: don't suggest .into_iter() for .cloned()/.copied() on non-reference Option#157413Albab-Hasan wants to merge 1 commit into
Albab-Hasan wants to merge 1 commit into
Conversation
Collaborator
|
r? @folkertdev rustbot has assigned @folkertdev. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5160827 to
b394147
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
b394147 to
a49c252
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…nce Option calling `.cloned()` or `.copied()` on `Option<T>` where `T` is an owned type emitted "`Option<T>` is not an iterator" with a suggestion to prepend `.into_iter()`. the suggested code still did not compile: `Option<T>::into_iter()` yields `T` by value not `&T`, so `.cloned()`/`.copied()` failed again for the same reason. `Option<T>` implements `IntoIterator`, which is why the `impl_into_iterator_should_be_iterator` branch fires. added a guard before it: when the method is `cloned`/`copied`, the receiver is `Option<T>`, and `T` is a concrete non-reference type, emit a targeted label pointing at the correct form (`Option<&T>`) and suggest removing the call instead. closes rust-lang#151147
a49c252 to
914cc9c
Compare
Collaborator
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
calling
.cloned()or.copied()onOption<T>whereTis an owned type emitted "Option<T>is not an iterator" with a suggestion to prepend.into_iter(). the suggested code still did not compile:Option<T>::into_iter()yieldsTby value not&Tso.cloned()/.copied()failed again for the same reason.Option<T>implementsIntoIteratorwhich is why theimpl_into_iterator_should_be_iteratorbranch fires. added a guard before it: when the method iscloned/copied, the receiver isOption<T>andTis a concrete non-reference type. emit a targeted label pointing at the correct form (Option<&T>) and suggest removing the call instead.closes #151147