Skip to content

Commit

Permalink
Auto merge of #108095 - soc:drop-contains, r=Amanieu
Browse files Browse the repository at this point in the history
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err`

This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`.

The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in #93051 obviates the need for these methods (non-stabilization tracked in #62358).

An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library:
![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
  • Loading branch information
bors committed Mar 28, 2023
2 parents 478cbb4 + 3aa9f76 commit cdbbce0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 93 deletions.
30 changes: 0 additions & 30 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,36 +1780,6 @@ impl<T> Option<T> {
mem::replace(self, Some(value))
}

/// Returns `true` if the option is a [`Some`] value containing the given value.
///
/// # Examples
///
/// ```
/// #![feature(option_result_contains)]
///
/// let x: Option<u32> = Some(2);
/// assert_eq!(x.contains(&2), true);
///
/// let x: Option<u32> = Some(3);
/// assert_eq!(x.contains(&2), false);
///
/// let x: Option<u32> = None;
/// assert_eq!(x.contains(&2), false);
/// ```
#[must_use]
#[inline]
#[unstable(feature = "option_result_contains", issue = "62358")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
pub const fn contains<U>(&self, x: &U) -> bool
where
U: ~const PartialEq<T>,
{
match self {
Some(y) => x.eq(y),
None => false,
}
}

/// Zips `self` with another `Option`.
///
/// If `self` is `Some(s)` and `other` is `Some(o)`, this method returns `Some((s, o))`.
Expand Down
62 changes: 0 additions & 62 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,68 +1531,6 @@ impl<T, E> Result<T, E> {
Err(e) => e,
}
}

/////////////////////////////////////////////////////////////////////////
// Misc or niche
/////////////////////////////////////////////////////////////////////////

/// Returns `true` if the result is an [`Ok`] value containing the given value.
///
/// # Examples
///
/// ```
/// #![feature(option_result_contains)]
///
/// let x: Result<u32, &str> = Ok(2);
/// assert_eq!(x.contains(&2), true);
///
/// let x: Result<u32, &str> = Ok(3);
/// assert_eq!(x.contains(&2), false);
///
/// let x: Result<u32, &str> = Err("Some error message");
/// assert_eq!(x.contains(&2), false);
/// ```
#[must_use]
#[inline]
#[unstable(feature = "option_result_contains", issue = "62358")]
pub fn contains<U>(&self, x: &U) -> bool
where
U: PartialEq<T>,
{
match self {
Ok(y) => x == y,
Err(_) => false,
}
}

/// Returns `true` if the result is an [`Err`] value containing the given value.
///
/// # Examples
///
/// ```
/// #![feature(result_contains_err)]
///
/// let x: Result<u32, &str> = Ok(2);
/// assert_eq!(x.contains_err(&"Some error message"), false);
///
/// let x: Result<u32, &str> = Err("Some error message");
/// assert_eq!(x.contains_err(&"Some error message"), true);
///
/// let x: Result<u32, &str> = Err("Some other error message");
/// assert_eq!(x.contains_err(&"Some error message"), false);
/// ```
#[must_use]
#[inline]
#[unstable(feature = "result_contains_err", issue = "62358")]
pub fn contains_err<F>(&self, f: &F) -> bool
where
F: PartialEq<E>,
{
match self {
Ok(_) => false,
Err(e) => f == e,
}
}
}

impl<T, E> Result<&T, E> {
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
#![feature(portable_simd)]
#![feature(ptr_metadata)]
#![feature(once_cell)]
#![feature(option_result_contains)]
#![feature(unsized_tuple_coercion)]
#![feature(const_option)]
#![feature(const_option_ext)]
Expand Down

0 comments on commit cdbbce0

Please sign in to comment.