Skip to content

Commit cdbbce0

Browse files
committed
Auto merge of rust-lang#108095 - soc:drop-contains, r=Amanieu
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 rust-lang#93051 obviates the need for these methods (non-stabilization tracked in rust-lang#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)
2 parents 478cbb4 + 3aa9f76 commit cdbbce0

File tree

3 files changed

+0
-93
lines changed

3 files changed

+0
-93
lines changed

library/core/src/option.rs

-30
Original file line numberDiff line numberDiff line change
@@ -1780,36 +1780,6 @@ impl<T> Option<T> {
17801780
mem::replace(self, Some(value))
17811781
}
17821782

1783-
/// Returns `true` if the option is a [`Some`] value containing the given value.
1784-
///
1785-
/// # Examples
1786-
///
1787-
/// ```
1788-
/// #![feature(option_result_contains)]
1789-
///
1790-
/// let x: Option<u32> = Some(2);
1791-
/// assert_eq!(x.contains(&2), true);
1792-
///
1793-
/// let x: Option<u32> = Some(3);
1794-
/// assert_eq!(x.contains(&2), false);
1795-
///
1796-
/// let x: Option<u32> = None;
1797-
/// assert_eq!(x.contains(&2), false);
1798-
/// ```
1799-
#[must_use]
1800-
#[inline]
1801-
#[unstable(feature = "option_result_contains", issue = "62358")]
1802-
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
1803-
pub const fn contains<U>(&self, x: &U) -> bool
1804-
where
1805-
U: ~const PartialEq<T>,
1806-
{
1807-
match self {
1808-
Some(y) => x.eq(y),
1809-
None => false,
1810-
}
1811-
}
1812-
18131783
/// Zips `self` with another `Option`.
18141784
///
18151785
/// If `self` is `Some(s)` and `other` is `Some(o)`, this method returns `Some((s, o))`.

library/core/src/result.rs

-62
Original file line numberDiff line numberDiff line change
@@ -1531,68 +1531,6 @@ impl<T, E> Result<T, E> {
15311531
Err(e) => e,
15321532
}
15331533
}
1534-
1535-
/////////////////////////////////////////////////////////////////////////
1536-
// Misc or niche
1537-
/////////////////////////////////////////////////////////////////////////
1538-
1539-
/// Returns `true` if the result is an [`Ok`] value containing the given value.
1540-
///
1541-
/// # Examples
1542-
///
1543-
/// ```
1544-
/// #![feature(option_result_contains)]
1545-
///
1546-
/// let x: Result<u32, &str> = Ok(2);
1547-
/// assert_eq!(x.contains(&2), true);
1548-
///
1549-
/// let x: Result<u32, &str> = Ok(3);
1550-
/// assert_eq!(x.contains(&2), false);
1551-
///
1552-
/// let x: Result<u32, &str> = Err("Some error message");
1553-
/// assert_eq!(x.contains(&2), false);
1554-
/// ```
1555-
#[must_use]
1556-
#[inline]
1557-
#[unstable(feature = "option_result_contains", issue = "62358")]
1558-
pub fn contains<U>(&self, x: &U) -> bool
1559-
where
1560-
U: PartialEq<T>,
1561-
{
1562-
match self {
1563-
Ok(y) => x == y,
1564-
Err(_) => false,
1565-
}
1566-
}
1567-
1568-
/// Returns `true` if the result is an [`Err`] value containing the given value.
1569-
///
1570-
/// # Examples
1571-
///
1572-
/// ```
1573-
/// #![feature(result_contains_err)]
1574-
///
1575-
/// let x: Result<u32, &str> = Ok(2);
1576-
/// assert_eq!(x.contains_err(&"Some error message"), false);
1577-
///
1578-
/// let x: Result<u32, &str> = Err("Some error message");
1579-
/// assert_eq!(x.contains_err(&"Some error message"), true);
1580-
///
1581-
/// let x: Result<u32, &str> = Err("Some other error message");
1582-
/// assert_eq!(x.contains_err(&"Some error message"), false);
1583-
/// ```
1584-
#[must_use]
1585-
#[inline]
1586-
#[unstable(feature = "result_contains_err", issue = "62358")]
1587-
pub fn contains_err<F>(&self, f: &F) -> bool
1588-
where
1589-
F: PartialEq<E>,
1590-
{
1591-
match self {
1592-
Ok(_) => false,
1593-
Err(e) => f == e,
1594-
}
1595-
}
15961534
}
15971535

15981536
impl<T, E> Result<&T, E> {

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
#![feature(portable_simd)]
9696
#![feature(ptr_metadata)]
9797
#![feature(once_cell)]
98-
#![feature(option_result_contains)]
9998
#![feature(unsized_tuple_coercion)]
10099
#![feature(const_option)]
101100
#![feature(const_option_ext)]

0 commit comments

Comments
 (0)