From 2f83134e375a98b14ecb2b10dbea0c8b2c43f5ed Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 21 Jun 2022 14:27:53 -0500 Subject: [PATCH 1/2] Change is_some_and to take by value --- library/core/src/option.rs | 13 ++++++++----- library/core/src/result.rs | 20 +++++++++++++------- src/tools/miri/src/stacked_borrows/stack.rs | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 4a93df4591b7a..0623d30400448 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -562,19 +562,22 @@ impl Option { /// #![feature(is_some_with)] /// /// let x: Option = 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 = 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 = None; - /// assert_eq!(x.is_some_and(|&x| x > 1), false); + /// assert_eq!(x.is_some_and(|x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool { - matches!(self, Some(x) if f(x)) + pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool { + match self { + None => false, + Some(x) => f(x), + } } /// Returns `true` if the option is a [`None`] value. diff --git a/library/core/src/result.rs b/library/core/src/result.rs index dc90e90402c8e..7c740bbd01f63 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -551,19 +551,22 @@ impl Result { /// #![feature(is_some_with)] /// /// let x: Result = 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 = 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 = Err("hey"); - /// assert_eq!(x.is_ok_and(|&x| x > 1), false); + /// assert_eq!(x.is_ok_and(|x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool { - matches!(self, Ok(x) if f(x)) + pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool { + match self { + Err(_) => false, + Ok(x) => f(x), + } } /// Returns `true` if the result is [`Err`]. @@ -607,8 +610,11 @@ impl Result { #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool { - matches!(self, Err(x) if f(x)) + pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool { + match self { + Ok(_) => false, + Err(e) => f(e), + } } ///////////////////////////////////////////////////////////////////////// diff --git a/src/tools/miri/src/stacked_borrows/stack.rs b/src/tools/miri/src/stacked_borrows/stack.rs index 494ea08b56e48..97632af785db5 100644 --- a/src/tools/miri/src/stacked_borrows/stack.rs +++ b/src/tools/miri/src/stacked_borrows/stack.rs @@ -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. - 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. }); if found { Ok(None) } else { Err(()) } From 4f12de0660bb26eefac258b03ffb6c43d2debda7 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 23 Jun 2022 13:17:42 -0500 Subject: [PATCH 2/2] Change feature name to is_some_and --- compiler/rustc_builtin_macros/src/lib.rs | 2 +- compiler/rustc_const_eval/src/lib.rs | 2 +- compiler/rustc_hir_analysis/src/lib.rs | 2 +- library/core/src/option.rs | 4 ++-- library/core/src/result.rs | 8 ++++---- library/std/src/lib.rs | 2 +- src/tools/miri/src/lib.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index f058503064bf1..c7ea7de8f4ead 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -7,7 +7,7 @@ #![feature(box_patterns)] #![feature(decl_macro)] #![feature(if_let_guard)] -#![feature(is_some_with)] +#![feature(is_some_and)] #![feature(is_sorted)] #![feature(let_chains)] #![feature(proc_macro_internals)] diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 7c4c7db1035b4..ebdaf61e43905 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -20,7 +20,7 @@ Rust MIR: a lowered representation of Rust. #![feature(trusted_step)] #![feature(try_blocks)] #![feature(yeet_expr)] -#![feature(is_some_with)] +#![feature(is_some_and)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 1859473166a78..d31b9b7ae46b4 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -70,7 +70,7 @@ This API is completely unstable and subject to change. #![feature(once_cell)] #![feature(slice_partition_dedup)] #![feature(try_blocks)] -#![feature(is_some_with)] +#![feature(is_some_and)] #![feature(type_alias_impl_trait)] #![recursion_limit = "256"] diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 0623d30400448..4b57371096e9a 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -559,7 +559,7 @@ impl Option { /// # Examples /// /// ``` - /// #![feature(is_some_with)] + /// #![feature(is_some_and)] /// /// let x: Option = Some(2); /// assert_eq!(x.is_some_and(|x| x > 1), true); @@ -572,7 +572,7 @@ impl Option { /// ``` #[must_use] #[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 { match self { None => false, diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 7c740bbd01f63..1c6d4cc5279d1 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -548,7 +548,7 @@ impl Result { /// # Examples /// /// ``` - /// #![feature(is_some_with)] + /// #![feature(is_some_and)] /// /// let x: Result = Ok(2); /// assert_eq!(x.is_ok_and(|x| x > 1), true); @@ -561,7 +561,7 @@ impl Result { /// ``` #[must_use] #[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 { match self { Err(_) => false, @@ -595,7 +595,7 @@ impl Result { /// # Examples /// /// ``` - /// #![feature(is_some_with)] + /// #![feature(is_some_and)] /// use std::io::{Error, ErrorKind}; /// /// let x: Result = Err(Error::new(ErrorKind::NotFound, "!")); @@ -609,7 +609,7 @@ impl Result { /// ``` #[must_use] #[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 { match self { Ok(_) => false, diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 64b62fd3bba4f..acc9f2ceee39b 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -291,7 +291,7 @@ #![feature(hasher_prefixfree_extras)] #![feature(hashmap_internals)] #![feature(int_error_internals)] -#![feature(is_some_with)] +#![feature(is_some_and)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_write_slice)] #![feature(nonnull_slice_from_raw_parts)] diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index cda27beab300f..d07610b19d754 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -7,7 +7,7 @@ #![feature(int_log)] #![feature(variant_count)] #![feature(yeet_expr)] -#![feature(is_some_with)] +#![feature(is_some_and)] #![feature(nonzero_ops)] #![feature(local_key_cell_methods)] #![cfg_attr(bootstrap, feature(let_else))]