Skip to content

Commit 91931ec

Browse files
committed
Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-se
Change `is_some_and` to take by value Consistent with other function-accepting `Option` methods. Tracking issue: #93050 r? `@m-ou-se`
2 parents 756e7be + 4f12de0 commit 91931ec

File tree

8 files changed

+33
-24
lines changed

8 files changed

+33
-24
lines changed

compiler/rustc_builtin_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![feature(box_patterns)]
88
#![feature(decl_macro)]
99
#![feature(if_let_guard)]
10-
#![feature(is_some_with)]
10+
#![feature(is_some_and)]
1111
#![feature(is_sorted)]
1212
#![feature(let_chains)]
1313
#![feature(proc_macro_internals)]

compiler/rustc_const_eval/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Rust MIR: a lowered representation of Rust.
2020
#![feature(trusted_step)]
2121
#![feature(try_blocks)]
2222
#![feature(yeet_expr)]
23-
#![feature(is_some_with)]
23+
#![feature(is_some_and)]
2424
#![recursion_limit = "256"]
2525
#![allow(rustc::potential_query_instability)]
2626

compiler/rustc_hir_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ This API is completely unstable and subject to change.
7070
#![feature(once_cell)]
7171
#![feature(slice_partition_dedup)]
7272
#![feature(try_blocks)]
73-
#![feature(is_some_with)]
73+
#![feature(is_some_and)]
7474
#![feature(type_alias_impl_trait)]
7575
#![recursion_limit = "256"]
7676

library/core/src/option.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -559,22 +559,25 @@ impl<T> Option<T> {
559559
/// # Examples
560560
///
561561
/// ```
562-
/// #![feature(is_some_with)]
562+
/// #![feature(is_some_and)]
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]
575-
#[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))
575+
#[unstable(feature = "is_some_and", issue = "93050")]
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

+17-11
Original file line numberDiff line numberDiff line change
@@ -548,22 +548,25 @@ impl<T, E> Result<T, E> {
548548
/// # Examples
549549
///
550550
/// ```
551-
/// #![feature(is_some_with)]
551+
/// #![feature(is_some_and)]
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]
564-
#[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))
564+
#[unstable(feature = "is_some_and", issue = "93050")]
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`].
@@ -592,7 +595,7 @@ impl<T, E> Result<T, E> {
592595
/// # Examples
593596
///
594597
/// ```
595-
/// #![feature(is_some_with)]
598+
/// #![feature(is_some_and)]
596599
/// use std::io::{Error, ErrorKind};
597600
///
598601
/// let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!"));
@@ -606,9 +609,12 @@ impl<T, E> Result<T, E> {
606609
/// ```
607610
#[must_use]
608611
#[inline]
609-
#[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))
612+
#[unstable(feature = "is_some_and", issue = "93050")]
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
/////////////////////////////////////////////////////////////////////////

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
#![feature(hasher_prefixfree_extras)]
293293
#![feature(hashmap_internals)]
294294
#![feature(int_error_internals)]
295-
#![feature(is_some_with)]
295+
#![feature(is_some_and)]
296296
#![feature(maybe_uninit_slice)]
297297
#![feature(maybe_uninit_write_slice)]
298298
#![feature(nonnull_slice_from_raw_parts)]

src/tools/miri/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![feature(int_log)]
88
#![feature(variant_count)]
99
#![feature(yeet_expr)]
10-
#![feature(is_some_with)]
10+
#![feature(is_some_and)]
1111
#![feature(nonzero_ops)]
1212
#![feature(local_key_cell_methods)]
1313
#![cfg_attr(bootstrap, feature(let_else))]

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)