From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- third_party/rust/indexmap/src/util.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'third_party/rust/indexmap/src/util.rs') diff --git a/third_party/rust/indexmap/src/util.rs b/third_party/rust/indexmap/src/util.rs index a24dfafde7..377ff516f0 100644 --- a/third_party/rust/indexmap/src/util.rs +++ b/third_party/rust/indexmap/src/util.rs @@ -29,3 +29,25 @@ where } start..end } + +pub(crate) fn try_simplify_range(range: R, len: usize) -> Option> +where + R: RangeBounds, +{ + let start = match range.start_bound() { + Bound::Unbounded => 0, + Bound::Included(&i) if i <= len => i, + Bound::Excluded(&i) if i < len => i + 1, + _ => return None, + }; + let end = match range.end_bound() { + Bound::Unbounded => len, + Bound::Excluded(&i) if i <= len => i, + Bound::Included(&i) if i < len => i + 1, + _ => return None, + }; + if start > end { + return None; + } + Some(start..end) +} -- cgit v1.2.3