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`
This commit is contained in:
commit
91931ec2fc
8 changed files with 33 additions and 24 deletions
|
@ -7,7 +7,7 @@
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
#![feature(is_some_with)]
|
#![feature(is_some_and)]
|
||||||
#![feature(is_sorted)]
|
#![feature(is_sorted)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(proc_macro_internals)]
|
#![feature(proc_macro_internals)]
|
||||||
|
|
|
@ -20,7 +20,7 @@ Rust MIR: a lowered representation of Rust.
|
||||||
#![feature(trusted_step)]
|
#![feature(trusted_step)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(yeet_expr)]
|
#![feature(yeet_expr)]
|
||||||
#![feature(is_some_with)]
|
#![feature(is_some_and)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ This API is completely unstable and subject to change.
|
||||||
#![feature(once_cell)]
|
#![feature(once_cell)]
|
||||||
#![feature(slice_partition_dedup)]
|
#![feature(slice_partition_dedup)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(is_some_with)]
|
#![feature(is_some_and)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
|
|
|
@ -559,22 +559,25 @@ impl<T> Option<T> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(is_some_with)]
|
/// #![feature(is_some_and)]
|
||||||
///
|
///
|
||||||
/// let x: Option<u32> = Some(2);
|
/// let x: Option<u32> = Some(2);
|
||||||
/// assert_eq!(x.is_some_and(|&x| x > 1), true);
|
/// assert_eq!(x.is_some_and(|x| x > 1), true);
|
||||||
///
|
///
|
||||||
/// let x: Option<u32> = Some(0);
|
/// let x: Option<u32> = Some(0);
|
||||||
/// assert_eq!(x.is_some_and(|&x| x > 1), false);
|
/// assert_eq!(x.is_some_and(|x| x > 1), false);
|
||||||
///
|
///
|
||||||
/// let x: Option<u32> = None;
|
/// let x: Option<u32> = None;
|
||||||
/// assert_eq!(x.is_some_and(|&x| x > 1), false);
|
/// assert_eq!(x.is_some_and(|x| x > 1), false);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "is_some_with", issue = "93050")]
|
#[unstable(feature = "is_some_and", issue = "93050")]
|
||||||
pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool {
|
pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
|
||||||
matches!(self, Some(x) if f(x))
|
match self {
|
||||||
|
None => false,
|
||||||
|
Some(x) => f(x),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the option is a [`None`] value.
|
/// Returns `true` if the option is a [`None`] value.
|
||||||
|
|
|
@ -548,22 +548,25 @@ impl<T, E> Result<T, E> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(is_some_with)]
|
/// #![feature(is_some_and)]
|
||||||
///
|
///
|
||||||
/// let x: Result<u32, &str> = Ok(2);
|
/// let x: Result<u32, &str> = Ok(2);
|
||||||
/// assert_eq!(x.is_ok_and(|&x| x > 1), true);
|
/// assert_eq!(x.is_ok_and(|x| x > 1), true);
|
||||||
///
|
///
|
||||||
/// let x: Result<u32, &str> = Ok(0);
|
/// let x: Result<u32, &str> = Ok(0);
|
||||||
/// assert_eq!(x.is_ok_and(|&x| x > 1), false);
|
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
|
||||||
///
|
///
|
||||||
/// let x: Result<u32, &str> = Err("hey");
|
/// let x: Result<u32, &str> = Err("hey");
|
||||||
/// assert_eq!(x.is_ok_and(|&x| x > 1), false);
|
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "is_some_with", issue = "93050")]
|
#[unstable(feature = "is_some_and", issue = "93050")]
|
||||||
pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool {
|
pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool {
|
||||||
matches!(self, Ok(x) if f(x))
|
match self {
|
||||||
|
Err(_) => false,
|
||||||
|
Ok(x) => f(x),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the result is [`Err`].
|
/// Returns `true` if the result is [`Err`].
|
||||||
|
@ -592,7 +595,7 @@ impl<T, E> Result<T, E> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(is_some_with)]
|
/// #![feature(is_some_and)]
|
||||||
/// use std::io::{Error, ErrorKind};
|
/// use std::io::{Error, ErrorKind};
|
||||||
///
|
///
|
||||||
/// let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!"));
|
/// let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!"));
|
||||||
|
@ -606,9 +609,12 @@ impl<T, E> Result<T, E> {
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "is_some_with", issue = "93050")]
|
#[unstable(feature = "is_some_and", issue = "93050")]
|
||||||
pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool {
|
pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool {
|
||||||
matches!(self, Err(x) if f(x))
|
match self {
|
||||||
|
Ok(_) => false,
|
||||||
|
Err(e) => f(e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -292,7 +292,7 @@
|
||||||
#![feature(hasher_prefixfree_extras)]
|
#![feature(hasher_prefixfree_extras)]
|
||||||
#![feature(hashmap_internals)]
|
#![feature(hashmap_internals)]
|
||||||
#![feature(int_error_internals)]
|
#![feature(int_error_internals)]
|
||||||
#![feature(is_some_with)]
|
#![feature(is_some_and)]
|
||||||
#![feature(maybe_uninit_slice)]
|
#![feature(maybe_uninit_slice)]
|
||||||
#![feature(maybe_uninit_write_slice)]
|
#![feature(maybe_uninit_write_slice)]
|
||||||
#![feature(nonnull_slice_from_raw_parts)]
|
#![feature(nonnull_slice_from_raw_parts)]
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#![feature(int_log)]
|
#![feature(int_log)]
|
||||||
#![feature(variant_count)]
|
#![feature(variant_count)]
|
||||||
#![feature(yeet_expr)]
|
#![feature(yeet_expr)]
|
||||||
#![feature(is_some_with)]
|
#![feature(is_some_and)]
|
||||||
#![feature(nonzero_ops)]
|
#![feature(nonzero_ops)]
|
||||||
#![feature(local_key_cell_methods)]
|
#![feature(local_key_cell_methods)]
|
||||||
#![cfg_attr(bootstrap, feature(let_else))]
|
#![cfg_attr(bootstrap, feature(let_else))]
|
||||||
|
|
|
@ -211,7 +211,7 @@ impl<'tcx> Stack {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't find it in the stack; but if there is an unknown bottom it might be there.
|
// Couldn't find it in the stack; but if there is an unknown bottom it might be there.
|
||||||
let found = self.unknown_bottom.is_some_and(|&unknown_limit| {
|
let found = self.unknown_bottom.is_some_and(|unknown_limit| {
|
||||||
tag.0 < unknown_limit.0 // unknown_limit is an upper bound for what can be in the unknown bottom.
|
tag.0 < unknown_limit.0 // unknown_limit is an upper bound for what can be in the unknown bottom.
|
||||||
});
|
});
|
||||||
if found { Ok(None) } else { Err(()) }
|
if found { Ok(None) } else { Err(()) }
|
||||||
|
|
Loading…
Add table
Reference in a new issue