Skip to content

Commit

Permalink
Rollup merge of rust-lang#84878 - jimblandy:contains-doc-fix, r=josht…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
RalfJung authored May 5, 2021
2 parents bbfa06a + d53469c commit 80d2c9a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,8 +1948,9 @@ impl<T> [T] {
/// assert!(!v.contains(&50));
/// ```
///
/// If you do not have an `&T`, but just an `&U` such that `T: Borrow<U>`
/// (e.g. `String: Borrow<str>`), you can use `iter().any`:
/// If you do not have a `&T`, but some other value that you can compare
/// with one (for example, `String` implements `PartialEq<str>`), you can
/// use `iter().any`:
///
/// ```
/// let v = [String::from("hello"), String::from("world")]; // slice of `String`
Expand Down

0 comments on commit 80d2c9a

Please sign in to comment.