Skip to content

Commit a660f77

Browse files
Rollup merge of #154461 - lms0806:issue_154452, r=Mark-Simulacrum
Edit the docs new_in() and with_capacity_in() I have updated the documentation for new_in(). While reviewing the code, I noticed that the documentation for with_capacity_in() was also inaccurate, so I have corrected it. Close #154452
2 parents ab3532f + a374727 commit a660f77

10 files changed

Lines changed: 97 additions & 19 deletions

File tree

library/alloc/src/boxed.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,15 @@ impl<T, A: Allocator> Box<T, A> {
695695
/// does the same as <code>[Box::into_pin]\([Box::new_in]\(x, alloc))</code>. Consider using
696696
/// [`into_pin`](Box::into_pin) if you already have a `Box<T, A>`, or if you want to
697697
/// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
698+
///
699+
/// # Examples
700+
///
701+
/// ```
702+
/// #![feature(allocator_api)]
703+
/// use std::alloc::System;
704+
///
705+
/// let x = Box::pin_in(1, System);
706+
/// ```
698707
#[cfg(not(no_global_oom_handling))]
699708
#[unstable(feature = "allocator_api", issue = "32838")]
700709
#[must_use]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
549549
///
550550
/// use std::alloc::System;
551551
/// use std::collections::BinaryHeap;
552-
/// let mut heap = BinaryHeap::new_in(System);
553-
/// heap.push(4);
552+
///
553+
/// let heap : BinaryHeap<i32, System> = BinaryHeap::new_in(System);
554554
/// ```
555555
#[unstable(feature = "allocator_api", issue = "32838")]
556556
#[must_use]
@@ -573,8 +573,8 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
573573
///
574574
/// use std::alloc::System;
575575
/// use std::collections::BinaryHeap;
576-
/// let mut heap = BinaryHeap::with_capacity_in(10, System);
577-
/// heap.push(4);
576+
///
577+
/// let heap: BinaryHeap<i32, System> = BinaryHeap::with_capacity_in(10, System);
578578
/// ```
579579
#[unstable(feature = "allocator_api", issue = "32838")]
580580
#[must_use]

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,11 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
684684
/// ```
685685
/// # #![feature(allocator_api)]
686686
/// # #![feature(btreemap_alloc)]
687+
///
687688
/// use std::collections::BTreeMap;
688689
/// use std::alloc::Global;
689690
///
690-
/// let mut map = BTreeMap::new_in(Global);
691-
///
692-
/// // entries can now be inserted into the empty map
693-
/// map.insert(1, "a");
691+
/// let map: BTreeMap<i32, i32> = BTreeMap::new_in(Global);
694692
/// ```
695693
#[unstable(feature = "btreemap_alloc", issue = "32838")]
696694
#[must_use]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,11 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
355355
/// # #![allow(unused_mut)]
356356
/// # #![feature(allocator_api)]
357357
/// # #![feature(btreemap_alloc)]
358+
///
358359
/// use std::collections::BTreeSet;
359360
/// use std::alloc::Global;
360361
///
361-
/// let mut set: BTreeSet<i32> = BTreeSet::new_in(Global);
362+
/// let set: BTreeSet<i32> = BTreeSet::new_in(Global);
362363
/// ```
363364
#[unstable(feature = "btreemap_alloc", issue = "32838")]
364365
#[must_use]

library/alloc/src/collections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
509509
/// use std::alloc::System;
510510
/// use std::collections::LinkedList;
511511
///
512-
/// let list: LinkedList<u32, _> = LinkedList::new_in(System);
512+
/// let list: LinkedList<i32, System> = LinkedList::new_in(System);
513513
/// ```
514514
#[inline]
515515
#[unstable(feature = "allocator_api", issue = "32838")]

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl<T> VecDeque<T> {
790790
/// ```
791791
/// use std::collections::VecDeque;
792792
///
793-
/// let deque: VecDeque<u32> = VecDeque::with_capacity(10);
793+
/// let deque: VecDeque<i32> = VecDeque::with_capacity(10);
794794
/// ```
795795
#[inline]
796796
#[stable(feature = "rust1", since = "1.0.0")]
@@ -830,9 +830,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
830830
/// # Examples
831831
///
832832
/// ```
833+
/// # #![feature(allocator_api)]
834+
///
833835
/// use std::collections::VecDeque;
836+
/// use std::alloc::Global;
834837
///
835-
/// let deque: VecDeque<u32> = VecDeque::new();
838+
/// let deque: VecDeque<i32> = VecDeque::new_in(Global);
836839
/// ```
837840
#[inline]
838841
#[unstable(feature = "allocator_api", issue = "32838")]
@@ -845,9 +848,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
845848
/// # Examples
846849
///
847850
/// ```
851+
/// # #![feature(allocator_api)]
852+
///
848853
/// use std::collections::VecDeque;
854+
/// use std::alloc::Global;
849855
///
850-
/// let deque: VecDeque<u32> = VecDeque::with_capacity(10);
856+
/// let deque: VecDeque<i32> = VecDeque::with_capacity_in(10, Global);
851857
/// ```
852858
#[unstable(feature = "allocator_api", issue = "32838")]
853859
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A> {

library/alloc/src/rc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ impl<T, A: Allocator> Rc<T, A> {
737737
///
738738
/// ```
739739
/// #![feature(allocator_api)]
740+
///
740741
/// use std::rc::Rc;
741742
/// use std::alloc::System;
742743
///

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,7 @@ impl<T, A: Allocator> Vec<T, A> {
10621062
///
10631063
/// use std::alloc::System;
10641064
///
1065-
/// # #[allow(unused_mut)]
1066-
/// let mut vec: Vec<i32, _> = Vec::new_in(System);
1065+
/// let vec: Vec<i32, System> = Vec::new_in(System);
10671066
/// ```
10681067
#[inline]
10691068
#[unstable(feature = "allocator_api", issue = "32838")]

library/std/src/collections/hash/map.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ impl<K, V, A: Allocator> HashMap<K, V, RandomState, A> {
301301
/// # Examples
302302
///
303303
/// ```
304+
/// # #![feature(allocator_api)]
304305
/// use std::collections::HashMap;
305-
/// let mut map: HashMap<&str, i32> = HashMap::new();
306+
/// use std::alloc::Global;
307+
///
308+
/// let map: HashMap<i32, i32> = HashMap::new_in(Global);
306309
/// ```
307310
#[inline]
308311
#[must_use]
@@ -321,8 +324,11 @@ impl<K, V, A: Allocator> HashMap<K, V, RandomState, A> {
321324
/// # Examples
322325
///
323326
/// ```
327+
/// # #![feature(allocator_api)]
324328
/// use std::collections::HashMap;
325-
/// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
329+
/// use std::alloc::Global;
330+
///
331+
/// let map: HashMap<i32, i32> = HashMap::with_capacity_in(10, Global);
326332
/// ```
327333
#[inline]
328334
#[must_use]
@@ -410,6 +416,18 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
410416
///
411417
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
412418
/// the `HashMap` to be useful, see its documentation for details.
419+
///
420+
/// # Examples
421+
///
422+
/// ```
423+
/// #![feature(allocator_api)]
424+
/// use std::alloc::Global;
425+
/// use std::collections::HashMap;
426+
/// use std::hash::RandomState;
427+
///
428+
/// let s = RandomState::new();
429+
/// let map: HashMap<i32, i32> = HashMap::with_hasher_in(s, Global);
430+
/// ```
413431
#[inline]
414432
#[must_use]
415433
#[unstable(feature = "allocator_api", issue = "32838")]
@@ -432,6 +450,17 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
432450
/// The `hasher` passed should implement the [`BuildHasher`] trait for
433451
/// the `HashMap` to be useful, see its documentation for details.
434452
///
453+
/// # Examples
454+
///
455+
/// ```
456+
/// #![feature(allocator_api)]
457+
/// use std::alloc::Global;
458+
/// use std::collections::HashMap;
459+
/// use std::hash::RandomState;
460+
///
461+
/// let s = RandomState::new();
462+
/// let map: HashMap<i32, i32> = HashMap::with_capacity_and_hasher_in(10, s, Global);
463+
/// ```
435464
#[inline]
436465
#[must_use]
437466
#[unstable(feature = "allocator_api", issue = "32838")]

library/std/src/collections/hash/set.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ impl<T, A: Allocator> HashSet<T, RandomState, A> {
176176
///
177177
/// The hash set is initially created with a capacity of 0, so it will not allocate until it
178178
/// is first inserted into.
179+
/// # Examples
180+
///
181+
/// ```
182+
/// # #![feature(allocator_api)]
183+
/// use std::alloc::Global;
184+
/// use std::collections::HashSet;
185+
///
186+
/// let set: HashSet<i32> = HashSet::new_in(Global);
187+
/// ```
179188
#[inline]
180189
#[must_use]
181190
#[unstable(feature = "allocator_api", issue = "32838")]
@@ -192,9 +201,11 @@ impl<T, A: Allocator> HashSet<T, RandomState, A> {
192201
/// # Examples
193202
///
194203
/// ```
204+
/// # #![feature(allocator_api)]
195205
/// use std::collections::HashSet;
196-
/// let set: HashSet<i32> = HashSet::with_capacity(10);
197-
/// assert!(set.capacity() >= 10);
206+
/// use std::alloc::Global;
207+
///
208+
/// let set: HashSet<i32> = HashSet::with_capacity_in(10, Global);
198209
/// ```
199210
#[inline]
200211
#[must_use]
@@ -282,6 +293,18 @@ impl<T, S, A: Allocator> HashSet<T, S, A> {
282293
///
283294
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
284295
/// the `HashSet` to be useful, see its documentation for details.
296+
///
297+
/// # Examples
298+
///
299+
/// ```
300+
/// # #![feature(allocator_api)]
301+
/// use std::alloc::Global;
302+
/// use std::collections::HashSet;
303+
/// use std::hash::RandomState;
304+
///
305+
/// let s = RandomState::new();
306+
/// let set: HashSet<i32> = HashSet::with_hasher_in(s, Global);
307+
/// ```
285308
#[inline]
286309
#[must_use]
287310
#[unstable(feature = "allocator_api", issue = "32838")]
@@ -303,6 +326,18 @@ impl<T, S, A: Allocator> HashSet<T, S, A> {
303326
///
304327
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
305328
/// the `HashSet` to be useful, see its documentation for details.
329+
///
330+
/// # Examples
331+
///
332+
/// ```
333+
/// # #![feature(allocator_api)]
334+
/// use std::alloc::Global;
335+
/// use std::collections::HashSet;
336+
/// use std::hash::RandomState;
337+
///
338+
/// let s = RandomState::new();
339+
/// let set: HashSet<i32> = HashSet::with_capacity_and_hasher_in(10, s, Global);
340+
/// ```
306341
#[inline]
307342
#[must_use]
308343
#[unstable(feature = "allocator_api", issue = "32838")]

0 commit comments

Comments
 (0)