Skip to content
Merged
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5461fd4
Gracefully handle non-WF alias in assemble_alias_bound_candidates_recur
compiler-errors Feb 10, 2024
1fa75af
Add test
c410-f3r Feb 11, 2024
89abbb0
Add ChrisDenton to review queue
ChrisDenton Feb 11, 2024
d5de9a6
check_consts: fix some duplicate errors by not calling check_static u…
RalfJung Feb 11, 2024
e13de31
make Primary/Secondary importance consistent between CellBorrow and M…
RalfJung Feb 11, 2024
792fa24
improve `btree_cursors` functions documentation
ripytide Feb 11, 2024
f415339
fix incorrect doctest
ripytide Feb 11, 2024
9789e88
Check that the ABI of the instance we are inlining is correct
compiler-errors Feb 11, 2024
f34d9da
fix intra-doc links
ripytide Feb 11, 2024
c35983a
Reorder the diagnostic API methods.
nnethercote Feb 8, 2024
b7b6ebc
Fix inconsistencies in the diagnostic API methods.
nnethercote Feb 8, 2024
2bcbc16
remove a bunch of dead parameters in fn
chenyukang Feb 11, 2024
fc7693d
Clean inlined type alias with correct param-env
compiler-errors Feb 12, 2024
30774b0
Remove final unwanted `unchecked_error_guaranteed` calls.
nnethercote Feb 9, 2024
e0a0cc2
Remove `dcx` arg from `ReportErrorExt::add_args`.
nnethercote Feb 12, 2024
d4b77f6
Tweak delayed bug mentions.
nnethercote Feb 12, 2024
1f39c8b
Change level used in `print_error_count`.
nnethercote Feb 12, 2024
95c5b06
fix ICE for deref coercions with type errors
Feb 11, 2024
57a2e91
Rollup merge of #120765 - nnethercote:reorder-diag-API, r=compiler-er…
matthiaskrgr Feb 12, 2024
f08ece3
Rollup merge of #120833 - nnethercote:more-internal-emit_diagnostics-…
matthiaskrgr Feb 12, 2024
733f93d
Rollup merge of #120899 - compiler-errors:non-wf-alias, r=lcnr
matthiaskrgr Feb 12, 2024
ebe36ac
Rollup merge of #120917 - chenyukang:yukang-dead-parameters, r=compil…
matthiaskrgr Feb 12, 2024
02c1e3e
Rollup merge of #120928 - c410-f3r:tests-tests-tests, r=davidtwco
matthiaskrgr Feb 12, 2024
3f67169
Rollup merge of #120933 - RalfJung:const-check-misc, r=oli-obk
matthiaskrgr Feb 12, 2024
8305686
Rollup merge of #120936 - ripytide:master, r=Amanieu
matthiaskrgr Feb 12, 2024
8ec144d
Rollup merge of #120944 - compiler-errors:inliner-abi, r=oli-obk
matthiaskrgr Feb 12, 2024
a0156e5
Rollup merge of #120956 - compiler-errors:clean-type-alias, r=Guillau…
matthiaskrgr Feb 12, 2024
323f66a
Rollup merge of #120962 - ChrisDenton:review, r=Nilstrieb
matthiaskrgr Feb 12, 2024
8e5f722
Rollup merge of #120972 - lukas-code:autoderef-type-error, r=compiler…
matthiaskrgr Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 128 additions & 85 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2522,10 +2522,17 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
self.len() == 0
}

/// Returns a [`Cursor`] pointing to the first gap above the given bound.
/// Returns a [`Cursor`] pointing at the gap before the smallest key
/// greater than the given bound.
///
/// Passing [`Bound::Unbounded`] will return a cursor pointing to the start
/// of the map.
/// Passing `Bound::Included(x)` will return a cursor pointing to the
/// gap before the smallest key greater than or equal to `x`.
///
/// Passing `Bound::Excluded(x)` will return a cursor pointing to the
/// gap before the smallest key greater than `x`.
///
/// Passing `Bound::Unbounded` will return a cursor pointing to the
/// gap before the smallest key in the map.
///
/// # Examples
///
Expand All @@ -2535,17 +2542,24 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// use std::collections::BTreeMap;
/// use std::ops::Bound;
///
/// let mut a = BTreeMap::new();
/// a.insert(1, "a");
/// a.insert(2, "b");
/// a.insert(3, "c");
/// a.insert(4, "d");
/// let cursor = a.lower_bound(Bound::Included(&2));
/// let map = BTreeMap::from([
/// (1, "a"),
/// (2, "b"),
/// (3, "c"),
/// (4, "d"),
/// ]);
///
/// let cursor = map.lower_bound(Bound::Included(&2));
/// assert_eq!(cursor.peek_prev(), Some((&1, &"a")));
/// assert_eq!(cursor.peek_next(), Some((&2, &"b")));
/// let cursor = a.lower_bound(Bound::Excluded(&2));
///
/// let cursor = map.lower_bound(Bound::Excluded(&2));
/// assert_eq!(cursor.peek_prev(), Some((&2, &"b")));
/// assert_eq!(cursor.peek_next(), Some((&3, &"c")));
///
/// let cursor = map.lower_bound(Bound::Unbounded);
/// assert_eq!(cursor.peek_prev(), None);
/// assert_eq!(cursor.peek_next(), Some((&1, &"a")));
/// ```
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn lower_bound<Q: ?Sized>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
Expand All @@ -2561,11 +2575,17 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
Cursor { current: Some(edge), root: self.root.as_ref() }
}

/// Returns a [`CursorMut`] pointing to the first gap above the given bound.
/// Returns a [`CursorMut`] pointing at the gap before the smallest key
/// greater than the given bound.
///
/// Passing `Bound::Included(x)` will return a cursor pointing to the
/// gap before the smallest key greater than or equal to `x`.
///
/// Passing [`Bound::Unbounded`] will return a cursor pointing to the start
/// of the map.
/// Passing `Bound::Excluded(x)` will return a cursor pointing to the
/// gap before the smallest key greater than `x`.
///
/// Passing `Bound::Unbounded` will return a cursor pointing to the
/// gap before the smallest key in the map.
///
/// # Examples
///
Expand All @@ -2575,17 +2595,24 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// use std::collections::BTreeMap;
/// use std::ops::Bound;
///
/// let mut a = BTreeMap::new();
/// a.insert(1, "a");
/// a.insert(2, "b");
/// a.insert(3, "c");
/// a.insert(4, "d");
/// let mut cursor = a.lower_bound_mut(Bound::Included(&2));
/// let mut map = BTreeMap::from([
/// (1, "a"),
/// (2, "b"),
/// (3, "c"),
/// (4, "d"),
/// ]);
///
/// let mut cursor = map.lower_bound_mut(Bound::Included(&2));
/// assert_eq!(cursor.peek_prev(), Some((&1, &mut "a")));
/// assert_eq!(cursor.peek_next(), Some((&2, &mut "b")));
/// let mut cursor = a.lower_bound_mut(Bound::Excluded(&2));
///
/// let mut cursor = map.lower_bound_mut(Bound::Excluded(&2));
/// assert_eq!(cursor.peek_prev(), Some((&2, &mut "b")));
/// assert_eq!(cursor.peek_next(), Some((&3, &mut "c")));
///
/// let mut cursor = map.lower_bound_mut(Bound::Unbounded);
/// assert_eq!(cursor.peek_prev(), None);
/// assert_eq!(cursor.peek_next(), Some((&1, &mut "a")));
/// ```
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn lower_bound_mut<Q: ?Sized>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
Expand Down Expand Up @@ -2618,10 +2645,17 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
}
}

/// Returns a [`Cursor`] pointing at the last gap below the given bound.
/// Returns a [`Cursor`] pointing at the gap after the greatest key
/// smaller than the given bound.
///
/// Passing [`Bound::Unbounded`] will return a cursor pointing to the end
/// of the map.
/// Passing `Bound::Included(x)` will return a cursor pointing to the
/// gap after the greatest key smaller than or equal to `x`.
///
/// Passing `Bound::Excluded(x)` will return a cursor pointing to the
/// gap after the greatest key smaller than `x`.
///
/// Passing `Bound::Unbounded` will return a cursor pointing to the
/// gap after the greatest key in the map.
///
/// # Examples
///
Expand All @@ -2631,17 +2665,24 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// use std::collections::BTreeMap;
/// use std::ops::Bound;
///
/// let mut a = BTreeMap::new();
/// a.insert(1, "a");
/// a.insert(2, "b");
/// a.insert(3, "c");
/// a.insert(4, "d");
/// let cursor = a.upper_bound(Bound::Included(&3));
/// let map = BTreeMap::from([
/// (1, "a"),
/// (2, "b"),
/// (3, "c"),
/// (4, "d"),
/// ]);
///
/// let cursor = map.upper_bound(Bound::Included(&3));
/// assert_eq!(cursor.peek_prev(), Some((&3, &"c")));
/// assert_eq!(cursor.peek_next(), Some((&4, &"d")));
/// let cursor = a.upper_bound(Bound::Excluded(&3));
///
/// let cursor = map.upper_bound(Bound::Excluded(&3));
/// assert_eq!(cursor.peek_prev(), Some((&2, &"b")));
/// assert_eq!(cursor.peek_next(), Some((&3, &"c")));
///
/// let cursor = map.upper_bound(Bound::Unbounded);
/// assert_eq!(cursor.peek_prev(), Some((&4, &"d")));
/// assert_eq!(cursor.peek_next(), None);
/// ```
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn upper_bound<Q: ?Sized>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
Expand All @@ -2657,10 +2698,17 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
Cursor { current: Some(edge), root: self.root.as_ref() }
}

/// Returns a [`CursorMut`] pointing at the last gap below the given bound.
/// Returns a [`CursorMut`] pointing at the gap after the greatest key
/// smaller than the given bound.
///
/// Passing [`Bound::Unbounded`] will return a cursor pointing to the end
/// of the map.
/// Passing `Bound::Included(x)` will return a cursor pointing to the
/// gap after the greatest key smaller than or equal to `x`.
///
/// Passing `Bound::Excluded(x)` will return a cursor pointing to the
/// gap after the greatest key smaller than `x`.
///
/// Passing `Bound::Unbounded` will return a cursor pointing to the
/// gap after the greatest key in the map.
///
/// # Examples
///
Expand All @@ -2670,17 +2718,24 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// use std::collections::BTreeMap;
/// use std::ops::Bound;
///
/// let mut a = BTreeMap::new();
/// a.insert(1, "a");
/// a.insert(2, "b");
/// a.insert(3, "c");
/// a.insert(4, "d");
/// let mut cursor = a.upper_bound_mut(Bound::Included(&3));
/// let mut map = BTreeMap::from([
/// (1, "a"),
/// (2, "b"),
/// (3, "c"),
/// (4, "d"),
/// ]);
///
/// let mut cursor = map.upper_bound_mut(Bound::Included(&3));
/// assert_eq!(cursor.peek_prev(), Some((&3, &mut "c")));
/// assert_eq!(cursor.peek_next(), Some((&4, &mut "d")));
/// let mut cursor = a.upper_bound_mut(Bound::Excluded(&3));
///
/// let mut cursor = map.upper_bound_mut(Bound::Excluded(&3));
/// assert_eq!(cursor.peek_prev(), Some((&2, &mut "b")));
/// assert_eq!(cursor.peek_next(), Some((&3, &mut "c")));
///
/// let mut cursor = map.upper_bound_mut(Bound::Unbounded);
/// assert_eq!(cursor.peek_prev(), Some((&4, &mut "d")));
/// assert_eq!(cursor.peek_next(), None);
/// ```
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn upper_bound_mut<Q: ?Sized>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
Expand Down Expand Up @@ -3040,8 +3095,8 @@ impl<'a, K, V, A> CursorMutKey<'a, K, V, A> {

// Now the tree editing operations
impl<'a, K: Ord, V, A: Allocator + Clone> CursorMutKey<'a, K, V, A> {
/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMutKey` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap before the
/// newly inserted element.
Expand Down Expand Up @@ -3083,8 +3138,8 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMutKey<'a, K, V, A> {
*self.length += 1;
}

/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMutKey` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap after the
/// newly inserted element.
Expand Down Expand Up @@ -3129,19 +3184,16 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMutKey<'a, K, V, A> {
*self.length += 1;
}

/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMutKey` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap before the
/// newly inserted element.
///
/// # Panics
///
/// This function panics if:
/// - the given key compares less than or equal to the current element (if
/// any).
/// - the given key compares greater than or equal to the next element (if
/// any).
/// If the inserted key is not greater than the key before the cursor
/// (if any), or if it not less than the key after the cursor (if any),
/// then an [`UnorderedKeyError`] is returned since this would
/// invalidate the [`Ord`] invariant between the keys of the map.
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn insert_after(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError> {
if let Some((prev, _)) = self.peek_prev() {
Expand All @@ -3160,19 +3212,16 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMutKey<'a, K, V, A> {
Ok(())
}

/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMutKey` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap after the
/// newly inserted element.
///
/// # Panics
///
/// This function panics if:
/// - the given key compares greater than or equal to the current element
/// (if any).
/// - the given key compares less than or equal to the previous element (if
/// any).
/// If the inserted key is not greater than the key before the cursor
/// (if any), or if it not less than the key after the cursor (if any),
/// then an [`UnorderedKeyError`] is returned since this would
/// invalidate the [`Ord`] invariant between the keys of the map.
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn insert_before(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError> {
if let Some((prev, _)) = self.peek_prev() {
Expand Down Expand Up @@ -3239,10 +3288,10 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMutKey<'a, K, V, A> {
}

impl<'a, K: Ord, V, A: Allocator + Clone> CursorMut<'a, K, V, A> {
/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMut` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap before the
/// After the insertion the cursor will be pointing at the gap after the
/// newly inserted element.
///
/// # Safety
Expand All @@ -3257,8 +3306,8 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMut<'a, K, V, A> {
unsafe { self.inner.insert_after_unchecked(key, value) }
}

/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMut` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap after the
/// newly inserted element.
Expand All @@ -3275,37 +3324,31 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMut<'a, K, V, A> {
unsafe { self.inner.insert_before_unchecked(key, value) }
}

/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMut` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap before the
/// newly inserted element.
///
/// # Panics
///
/// This function panics if:
/// - the given key compares less than or equal to the current element (if
/// any).
/// - the given key compares greater than or equal to the next element (if
/// any).
/// If the inserted key is not greater than the key before the cursor
/// (if any), or if it not less than the key after the cursor (if any),
/// then an [`UnorderedKeyError`] is returned since this would
/// invalidate the [`Ord`] invariant between the keys of the map.
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn insert_after(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError> {
self.inner.insert_after(key, value)
}

/// Inserts a new element into the `BTreeMap` in the gap that the
/// `CursorMut` is currently pointing to.
/// Inserts a new key-value pair into the map in the gap that the
/// cursor is currently pointing to.
///
/// After the insertion the cursor will be pointing at the gap after the
/// newly inserted element.
///
/// # Panics
///
/// This function panics if:
/// - the given key compares greater than or equal to the current element
/// (if any).
/// - the given key compares less than or equal to the previous element (if
/// any).
/// If the inserted key is not greater than the key before the cursor
/// (if any), or if it not less than the key after the cursor (if any),
/// then an [`UnorderedKeyError`] is returned since this would
/// invalidate the [`Ord`] invariant between the keys of the map.
#[unstable(feature = "btree_cursors", issue = "107540")]
pub fn insert_before(&mut self, key: K, value: V) -> Result<(), UnorderedKeyError> {
self.inner.insert_before(key, value)
Expand Down