summaryrefslogtreecommitdiffstats
path: root/library/core/src/ops
diff options
context:
space:
mode:
Diffstat (limited to 'library/core/src/ops')
-rw-r--r--library/core/src/ops/index_range.rs15
-rw-r--r--library/core/src/ops/try_trait.rs9
2 files changed, 8 insertions, 16 deletions
diff --git a/library/core/src/ops/index_range.rs b/library/core/src/ops/index_range.rs
index 3e06776d2..265022a39 100644
--- a/library/core/src/ops/index_range.rs
+++ b/library/core/src/ops/index_range.rs
@@ -1,5 +1,6 @@
use crate::intrinsics::{assert_unsafe_precondition, unchecked_add, unchecked_sub};
use crate::iter::{FusedIterator, TrustedLen};
+use crate::num::NonZeroUsize;
/// Like a `Range<usize>`, but with a safety invariant that `start <= end`.
///
@@ -132,10 +133,9 @@ impl Iterator for IndexRange {
}
#[inline]
- fn advance_by(&mut self, n: usize) -> Result<(), usize> {
- let original_len = self.len();
- self.take_prefix(n);
- if n > original_len { Err(original_len) } else { Ok(()) }
+ fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
+ let taken = self.take_prefix(n);
+ NonZeroUsize::new(n - taken.len()).map_or(Ok(()), Err)
}
}
@@ -151,10 +151,9 @@ impl DoubleEndedIterator for IndexRange {
}
#[inline]
- fn advance_back_by(&mut self, n: usize) -> Result<(), usize> {
- let original_len = self.len();
- self.take_suffix(n);
- if n > original_len { Err(original_len) } else { Ok(()) }
+ fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
+ let taken = self.take_suffix(n);
+ NonZeroUsize::new(n - taken.len()).map_or(Ok(()), Err)
}
}
diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs
index 86aa1e4fd..c254803fb 100644
--- a/library/core/src/ops/try_trait.rs
+++ b/library/core/src/ops/try_trait.rs
@@ -392,14 +392,7 @@ impl<T> NeverShortCircuit<T> {
pub fn wrap_mut_2<A, B>(
mut f: impl ~const FnMut(A, B) -> T,
) -> impl ~const FnMut(A, B) -> Self {
- cfg_if! {
- if #[cfg(bootstrap)] {
- #[allow(unused_parens)]
- (const move |a, b| NeverShortCircuit(f(a, b)))
- } else {
- const move |a, b| NeverShortCircuit(f(a, b))
- }
- }
+ const move |a, b| NeverShortCircuit(f(a, b))
}
}