-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standard library documentation for alternatives to [T]::contains suggests Borrow is needed when it is not #84877
Labels
C-bug
Category: This is a bug.
Comments
CC: @RalfJung , since they're the author of the comment. |
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this issue
May 4, 2021
…riplett Clarify documentation for `[T]::contains`. Fixes rust-lang#84877. Change the documentation to correctly characterize when the suggested alternative to `contains` applies, and correctly explain why it works.
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this issue
May 4, 2021
…riplett Clarify documentation for `[T]::contains`. Fixes rust-lang#84877. Change the documentation to correctly characterize when the suggested alternative to `contains` applies, and correctly explain why it works.
Introduced in #62656, also Cc #62367 which is still open. Looks like I simply misread this comment. |
RalfJung
added a commit
to RalfJung/rust
that referenced
this issue
May 5, 2021
…riplett Clarify documentation for `[T]::contains` Change the documentation to correctly characterize when the suggested alternative to `contains` applies, and correctly explain why it works. Fixes rust-lang#84877
RalfJung
added a commit
to RalfJung/rust
that referenced
this issue
May 5, 2021
…riplett Clarify documentation for `[T]::contains` Change the documentation to correctly characterize when the suggested alternative to `contains` applies, and correctly explain why it works. Fixes rust-lang#84877
RalfJung
added a commit
to RalfJung/rust
that referenced
this issue
May 5, 2021
…riplett Clarify documentation for `[T]::contains` Change the documentation to correctly characterize when the suggested alternative to `contains` applies, and correctly explain why it works. Fixes rust-lang#84877
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The documentation for
[T]::contains where T: PartialEq<T>
suggests that, if this method is not applicable because the type you need to compare with is not exactlyT
, you should use.iter().any()
. This is good advice, but it goes on to suggest that somehow aBorrow
implementation is a necessary part of the solution, when it is not.The documentation should suggest the use of
iter().any
without mentioningBorrow
.Specifically, the documentation says:
This code works because
String
has an explicit implementation ofPartialEq<str>
(note, no&
), not because it implementsBorrow<str>
. As far as I know,Borrow
is never invoked implicitly (it's not a lang item), and it doesn't help one use==
in this way. For example:This fails:
The text was updated successfully, but these errors were encountered: