Skip to content

Commit 2f83134

Browse files
committed
Change is_some_and to take by value
1 parent 744e397 commit 2f83134

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

library/core/src/option.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,22 @@ impl<T> Option<T> {
562562
/// #![feature(is_some_with)]
563563
///
564564
/// let x: Option<u32> = Some(2);
565-
/// assert_eq!(x.is_some_and(|&x| x > 1), true);
565+
/// assert_eq!(x.is_some_and(|x| x > 1), true);
566566
///
567567
/// let x: Option<u32> = Some(0);
568-
/// assert_eq!(x.is_some_and(|&x| x > 1), false);
568+
/// assert_eq!(x.is_some_and(|x| x > 1), false);
569569
///
570570
/// let x: Option<u32> = None;
571-
/// assert_eq!(x.is_some_and(|&x| x > 1), false);
571+
/// assert_eq!(x.is_some_and(|x| x > 1), false);
572572
/// ```
573573
#[must_use]
574574
#[inline]
575575
#[unstable(feature = "is_some_with", issue = "93050")]
576-
pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool {
577-
matches!(self, Some(x) if f(x))
576+
pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
577+
match self {
578+
None => false,
579+
Some(x) => f(x),
580+
}
578581
}
579582

580583
/// Returns `true` if the option is a [`None`] value.

library/core/src/result.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -551,19 +551,22 @@ impl<T, E> Result<T, E> {
551551
/// #![feature(is_some_with)]
552552
///
553553
/// let x: Result<u32, &str> = Ok(2);
554-
/// assert_eq!(x.is_ok_and(|&x| x > 1), true);
554+
/// assert_eq!(x.is_ok_and(|x| x > 1), true);
555555
///
556556
/// let x: Result<u32, &str> = Ok(0);
557-
/// assert_eq!(x.is_ok_and(|&x| x > 1), false);
557+
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
558558
///
559559
/// let x: Result<u32, &str> = Err("hey");
560-
/// assert_eq!(x.is_ok_and(|&x| x > 1), false);
560+
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
561561
/// ```
562562
#[must_use]
563563
#[inline]
564564
#[unstable(feature = "is_some_with", issue = "93050")]
565-
pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool {
566-
matches!(self, Ok(x) if f(x))
565+
pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool {
566+
match self {
567+
Err(_) => false,
568+
Ok(x) => f(x),
569+
}
567570
}
568571

569572
/// Returns `true` if the result is [`Err`].
@@ -607,8 +610,11 @@ impl<T, E> Result<T, E> {
607610
#[must_use]
608611
#[inline]
609612
#[unstable(feature = "is_some_with", issue = "93050")]
610-
pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool {
611-
matches!(self, Err(x) if f(x))
613+
pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool {
614+
match self {
615+
Ok(_) => false,
616+
Err(e) => f(e),
617+
}
612618
}
613619

614620
/////////////////////////////////////////////////////////////////////////

src/tools/miri/src/stacked_borrows/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<'tcx> Stack {
211211
}
212212

213213
// Couldn't find it in the stack; but if there is an unknown bottom it might be there.
214-
let found = self.unknown_bottom.is_some_and(|&unknown_limit| {
214+
let found = self.unknown_bottom.is_some_and(|unknown_limit| {
215215
tag.0 < unknown_limit.0 // unknown_limit is an upper bound for what can be in the unknown bottom.
216216
});
217217
if found { Ok(None) } else { Err(()) }

0 commit comments

Comments
 (0)