Skip to content

Commit e3420f4

Browse files
authored
Rollup merge of #135367 - Urgau:unreach_pub-std-3, r=Noratrieb
Enable `unreachable_pub` lint in `alloc` This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) lint as warn in the `alloc` crate. Most of changes are in the btree implementation and in tests. *The diff was mostly generated with `./x.py fix --stage 1 library/alloc/ -- --broken-code`, as well as manual edits for code in macros and in tests.* Continuation of #134286 and #135366 r? libs
2 parents da5e22d + 656d1cc commit e3420f4

21 files changed

+251
-210
lines changed

library/alloc/src/collections/btree/append.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<K, V> Root<K, V> {
1616
/// a `BTreeMap`, both iterators should produce keys in strictly ascending
1717
/// order, each greater than all keys in the tree, including any keys
1818
/// already in the tree upon entry.
19-
pub fn append_from_sorted_iters<I, A: Allocator + Clone>(
19+
pub(super) fn append_from_sorted_iters<I, A: Allocator + Clone>(
2020
&mut self,
2121
left: I,
2222
right: I,
@@ -36,8 +36,12 @@ impl<K, V> Root<K, V> {
3636
/// Pushes all key-value pairs to the end of the tree, incrementing a
3737
/// `length` variable along the way. The latter makes it easier for the
3838
/// caller to avoid a leak when the iterator panicks.
39-
pub fn bulk_push<I, A: Allocator + Clone>(&mut self, iter: I, length: &mut usize, alloc: A)
40-
where
39+
pub(super) fn bulk_push<I, A: Allocator + Clone>(
40+
&mut self,
41+
iter: I,
42+
length: &mut usize,
43+
alloc: A,
44+
) where
4145
I: Iterator<Item = (K, V)>,
4246
{
4347
let mut cur_node = self.borrow_mut().last_leaf_edge().into_node();

library/alloc/src/collections/btree/borrow.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use core::ptr::NonNull;
1111
/// the compiler to follow. A `DormantMutRef` allows you to check borrowing
1212
/// yourself, while still expressing its stacked nature, and encapsulating
1313
/// the raw pointer code needed to do this without undefined behavior.
14-
pub struct DormantMutRef<'a, T> {
14+
pub(super) struct DormantMutRef<'a, T> {
1515
ptr: NonNull<T>,
1616
_marker: PhantomData<&'a mut T>,
1717
}
@@ -23,7 +23,7 @@ impl<'a, T> DormantMutRef<'a, T> {
2323
/// Capture a unique borrow, and immediately reborrow it. For the compiler,
2424
/// the lifetime of the new reference is the same as the lifetime of the
2525
/// original reference, but you promise to use it for a shorter period.
26-
pub fn new(t: &'a mut T) -> (&'a mut T, Self) {
26+
pub(super) fn new(t: &'a mut T) -> (&'a mut T, Self) {
2727
let ptr = NonNull::from(t);
2828
// SAFETY: we hold the borrow throughout 'a via `_marker`, and we expose
2929
// only this reference, so it is unique.
@@ -37,7 +37,7 @@ impl<'a, T> DormantMutRef<'a, T> {
3737
///
3838
/// The reborrow must have ended, i.e., the reference returned by `new` and
3939
/// all pointers and references derived from it, must not be used anymore.
40-
pub unsafe fn awaken(self) -> &'a mut T {
40+
pub(super) unsafe fn awaken(self) -> &'a mut T {
4141
// SAFETY: our own safety conditions imply this reference is again unique.
4242
unsafe { &mut *self.ptr.as_ptr() }
4343
}
@@ -48,7 +48,7 @@ impl<'a, T> DormantMutRef<'a, T> {
4848
///
4949
/// The reborrow must have ended, i.e., the reference returned by `new` and
5050
/// all pointers and references derived from it, must not be used anymore.
51-
pub unsafe fn reborrow(&mut self) -> &'a mut T {
51+
pub(super) unsafe fn reborrow(&mut self) -> &'a mut T {
5252
// SAFETY: our own safety conditions imply this reference is again unique.
5353
unsafe { &mut *self.ptr.as_ptr() }
5454
}
@@ -59,7 +59,7 @@ impl<'a, T> DormantMutRef<'a, T> {
5959
///
6060
/// The reborrow must have ended, i.e., the reference returned by `new` and
6161
/// all pointers and references derived from it, must not be used anymore.
62-
pub unsafe fn reborrow_shared(&self) -> &'a T {
62+
pub(super) unsafe fn reborrow_shared(&self) -> &'a T {
6363
// SAFETY: our own safety conditions imply this reference is again unique.
6464
unsafe { &*self.ptr.as_ptr() }
6565
}

library/alloc/src/collections/btree/dedup_sorted_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::iter::Peekable;
66
/// Used by [`BTreeMap::bulk_build_from_sorted_iter`][1].
77
///
88
/// [1]: crate::collections::BTreeMap::bulk_build_from_sorted_iter
9-
pub struct DedupSortedIter<K, V, I>
9+
pub(super) struct DedupSortedIter<K, V, I>
1010
where
1111
I: Iterator<Item = (K, V)>,
1212
{
@@ -17,7 +17,7 @@ impl<K, V, I> DedupSortedIter<K, V, I>
1717
where
1818
I: Iterator<Item = (K, V)>,
1919
{
20-
pub fn new(iter: I) -> Self {
20+
pub(super) fn new(iter: I) -> Self {
2121
Self { iter: iter.peekable() }
2222
}
2323
}

library/alloc/src/collections/btree/fix.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
5757
///
5858
/// This method does not expect ancestors to already be underfull upon entry
5959
/// and panics if it encounters an empty ancestor.
60-
pub fn fix_node_and_affected_ancestors<A: Allocator + Clone>(mut self, alloc: A) -> bool {
60+
pub(super) fn fix_node_and_affected_ancestors<A: Allocator + Clone>(
61+
mut self,
62+
alloc: A,
63+
) -> bool {
6164
loop {
6265
match self.fix_node_through_parent(alloc.clone()) {
6366
Ok(Some(parent)) => self = parent.forget_type(),
@@ -70,7 +73,7 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
7073

7174
impl<K, V> Root<K, V> {
7275
/// Removes empty levels on the top, but keeps an empty leaf if the entire tree is empty.
73-
pub fn fix_top<A: Allocator + Clone>(&mut self, alloc: A) {
76+
pub(super) fn fix_top<A: Allocator + Clone>(&mut self, alloc: A) {
7477
while self.height() > 0 && self.len() == 0 {
7578
self.pop_internal_level(alloc.clone());
7679
}
@@ -79,7 +82,7 @@ impl<K, V> Root<K, V> {
7982
/// Stocks up or merge away any underfull nodes on the right border of the
8083
/// tree. The other nodes, those that are not the root nor a rightmost edge,
8184
/// must already have at least MIN_LEN elements.
82-
pub fn fix_right_border<A: Allocator + Clone>(&mut self, alloc: A) {
85+
pub(super) fn fix_right_border<A: Allocator + Clone>(&mut self, alloc: A) {
8386
self.fix_top(alloc.clone());
8487
if self.len() > 0 {
8588
self.borrow_mut().last_kv().fix_right_border_of_right_edge(alloc.clone());
@@ -88,7 +91,7 @@ impl<K, V> Root<K, V> {
8891
}
8992

9093
/// The symmetric clone of `fix_right_border`.
91-
pub fn fix_left_border<A: Allocator + Clone>(&mut self, alloc: A) {
94+
pub(super) fn fix_left_border<A: Allocator + Clone>(&mut self, alloc: A) {
9295
self.fix_top(alloc.clone());
9396
if self.len() > 0 {
9497
self.borrow_mut().first_kv().fix_left_border_of_left_edge(alloc.clone());
@@ -99,7 +102,7 @@ impl<K, V> Root<K, V> {
99102
/// Stocks up any underfull nodes on the right border of the tree.
100103
/// The other nodes, those that are neither the root nor a rightmost edge,
101104
/// must be prepared to have up to MIN_LEN elements stolen.
102-
pub fn fix_right_border_of_plentiful(&mut self) {
105+
pub(super) fn fix_right_border_of_plentiful(&mut self) {
103106
let mut cur_node = self.borrow_mut();
104107
while let Internal(internal) = cur_node.force() {
105108
// Check if rightmost child is underfull.

library/alloc/src/collections/btree/mem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::{intrinsics, mem, ptr};
66
/// If a panic occurs in the `change` closure, the entire process will be aborted.
77
#[allow(dead_code)] // keep as illustration and for future use
88
#[inline]
9-
pub fn take_mut<T>(v: &mut T, change: impl FnOnce(T) -> T) {
9+
pub(super) fn take_mut<T>(v: &mut T, change: impl FnOnce(T) -> T) {
1010
replace(v, |value| (change(value), ()))
1111
}
1212

@@ -15,7 +15,7 @@ pub fn take_mut<T>(v: &mut T, change: impl FnOnce(T) -> T) {
1515
///
1616
/// If a panic occurs in the `change` closure, the entire process will be aborted.
1717
#[inline]
18-
pub fn replace<T, R>(v: &mut T, change: impl FnOnce(T) -> (T, R)) -> R {
18+
pub(super) fn replace<T, R>(v: &mut T, change: impl FnOnce(T) -> (T, R)) -> R {
1919
struct PanicGuard;
2020
impl Drop for PanicGuard {
2121
fn drop(&mut self) {

library/alloc/src/collections/btree/merge_iter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::iter::FusedIterator;
44

55
/// Core of an iterator that merges the output of two strictly ascending iterators,
66
/// for instance a union or a symmetric difference.
7-
pub struct MergeIterInner<I: Iterator> {
7+
pub(super) struct MergeIterInner<I: Iterator> {
88
a: I,
99
b: I,
1010
peeked: Option<Peeked<I>>,
@@ -40,7 +40,7 @@ where
4040

4141
impl<I: Iterator> MergeIterInner<I> {
4242
/// Creates a new core for an iterator merging a pair of sources.
43-
pub fn new(a: I, b: I) -> Self {
43+
pub(super) fn new(a: I, b: I) -> Self {
4444
MergeIterInner { a, b, peeked: None }
4545
}
4646

@@ -51,7 +51,7 @@ impl<I: Iterator> MergeIterInner<I> {
5151
/// the sources are not strictly ascending). If neither returned option
5252
/// contains a value, iteration has finished and subsequent calls will
5353
/// return the same empty pair.
54-
pub fn nexts<Cmp: Fn(&I::Item, &I::Item) -> Ordering>(
54+
pub(super) fn nexts<Cmp: Fn(&I::Item, &I::Item) -> Ordering>(
5555
&mut self,
5656
cmp: Cmp,
5757
) -> (Option<I::Item>, Option<I::Item>)
@@ -85,7 +85,7 @@ impl<I: Iterator> MergeIterInner<I> {
8585
}
8686

8787
/// Returns a pair of upper bounds for the `size_hint` of the final iterator.
88-
pub fn lens(&self) -> (usize, usize)
88+
pub(super) fn lens(&self) -> (usize, usize)
8989
where
9090
I: ExactSizeIterator,
9191
{

library/alloc/src/collections/btree/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ mod append;
22
mod borrow;
33
mod dedup_sorted_iter;
44
mod fix;
5-
pub mod map;
5+
pub(super) mod map;
66
mod mem;
77
mod merge_iter;
88
mod navigate;
99
mod node;
1010
mod remove;
1111
mod search;
12-
pub mod set;
12+
pub(super) mod set;
1313
mod set_val;
1414
mod split;

0 commit comments

Comments
 (0)