| 1 | use superrust-analyzer cargo typed-arena 2.0.2 crate/::*; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/, AssertUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/AssertUnwindSafe#}; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/; |
| 6 | |
| 7 | struct DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#<'a>(&'a Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<u32>); |
| 8 | impl<'a> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#<'a> { |
| 9 | fn droprust-analyzer cargo typed-arena 2.0.2 test/impl#[`DropTracker<'a>`][Drop]drop().(&mut self) { |
| 10 | self.0rust-analyzer cargo typed-arena 2.0.2 test/DropTracker#0..setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(self.0rust-analyzer cargo typed-arena 2.0.2 test/DropTracker#0..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1); |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | struct Noderust-analyzer cargo typed-arena 2.0.2 test/Node#<'a, 'b: 'a>(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Noderust-analyzer cargo typed-arena 2.0.2 test/Node#<'a, 'b>>, u32, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#<'b>); |
| 15 | |
| 16 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 17 | fn arena_as_intendedrust-analyzer cargo typed-arena 2.0.2 test/arena_as_intended().() { |
| 18 | let drop_counter = Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(0); |
| 19 | { |
| 20 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(2); |
| 21 | |
| 22 | let mut node: &Noderust-analyzer cargo typed-arena 2.0.2 test/Node# = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 1, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 23 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0); |
| 24 | |
| 25 | node = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node), 2, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 26 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0); |
| 27 | |
| 28 | node = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node), 3, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 29 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 30 | |
| 31 | node = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node), 4, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 32 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 33 | |
| 34 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(node.1rust-analyzer cargo typed-arena 2.0.2 test/Node#1., 4); |
| 35 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(node.0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1rust-analyzer cargo typed-arena 2.0.2 test/Node#1., 3); |
| 36 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(node.0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1rust-analyzer cargo typed-arena 2.0.2 test/Node#1., 2); |
| 37 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(node.0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1rust-analyzer cargo typed-arena 2.0.2 test/Node#1., 1); |
| 38 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(node.0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 39 | |
| 40 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.lenrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]len().(), 4); |
| 41 | |
| 42 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(node); |
| 43 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 0); |
| 44 | |
| 45 | let mut node: &Noderust-analyzer cargo typed-arena 2.0.2 test/Node# = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 5, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 46 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 47 | |
| 48 | node = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node), 6, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 49 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 50 | |
| 51 | node = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node), 7, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 52 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 53 | |
| 54 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 0); |
| 55 | |
| 56 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(node.1rust-analyzer cargo typed-arena 2.0.2 test/Node#1., 7); |
| 57 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(node.0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1rust-analyzer cargo typed-arena 2.0.2 test/Node#1., 6); |
| 58 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(node.0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1rust-analyzer cargo typed-arena 2.0.2 test/Node#1., 5); |
| 59 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(node.0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0rust-analyzer cargo typed-arena 2.0.2 test/Node#0..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 60 | |
| 61 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 0); |
| 62 | } |
| 63 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 7); |
| 64 | } |
| 65 | |
| 66 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 67 | fn ensure_into_vec_maintains_order_of_allocationrust-analyzer cargo typed-arena 2.0.2 test/ensure_into_vec_maintains_order_of_allocation().() { |
| 68 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(1); // force multiple inner vecs |
| 69 | for &s in &["t", "e", "s", "t"] { |
| 70 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(s)); |
| 71 | } |
| 72 | let vec = arena.into_vecrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]into_vec().(); |
| 73 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["t", "e", "s", "t"]); |
| 74 | } |
| 75 | |
| 76 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 77 | fn test_zero_caprust-analyzer cargo typed-arena 2.0.2 test/test_zero_cap().() { |
| 78 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(0); |
| 79 | let a = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(1); |
| 80 | let b = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(2); |
| 81 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().a, 1); |
| 82 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().b, 2); |
| 83 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.lenrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]len().(), 2); |
| 84 | } |
| 85 | |
| 86 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 87 | fn test_alloc_extendrust-analyzer cargo typed-arena 2.0.2 test/test_alloc_extend().() { |
| 88 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(2); |
| 89 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#15 { |
| 90 | let slice = arena.alloc_extendrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_extend().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i); |
| 91 | for (j, &elem) in slice.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 92 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(j, elem); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 98 | fn test_alloc_uninitializedrust-analyzer cargo typed-arena 2.0.2 test/test_alloc_uninitialized().() { |
| 99 | const LIMITrust-analyzer cargo typed-arena 2.0.2 test/LIMIT.: usize = 15; |
| 100 | let drop_counter = Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(0); |
| 101 | unsafe { |
| 102 | let arena: Arenarust-analyzer cargo typed-arena 2.0.2 Arena#<Noderust-analyzer cargo typed-arena 2.0.2 test/Node#> = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(4); |
| 103 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#LIMITrust-analyzer cargo typed-arena 2.0.2 test/LIMIT. { |
| 104 | let slice = arena.alloc_uninitializedrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_uninitialized().(i); |
| 105 | for (j, elem) in slice.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 106 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().( |
| 107 | elem.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().(), |
| 108 | Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, j as u32, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter)), |
| 109 | ); |
| 110 | } |
| 111 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 0); |
| 112 | } |
| 113 | } |
| 114 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), (0..LIMITrust-analyzer cargo typed-arena 2.0.2 test/LIMIT.).foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(0, |a, e| a +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). e) as u32); |
| 115 | } |
| 116 | |
| 117 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 118 | fn test_alloc_extend_with_drop_counterrust-analyzer cargo typed-arena 2.0.2 test/test_alloc_extend_with_drop_counter().() { |
| 119 | let drop_counter = Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(0); |
| 120 | { |
| 121 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(2); |
| 122 | let iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#100).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|j| Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, j as u32, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 123 | let older_ref = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&arena.alloc_extendrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_extend().(iter)[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 124 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 0); |
| 125 | let iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#100).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|j| Noderust-analyzer cargo typed-arena 2.0.2 test/Node#(older_ref, j as u32, DropTrackerrust-analyzer cargo typed-arena 2.0.2 test/DropTracker#(&drop_counter))); |
| 126 | arena.alloc_extendrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_extend().(iter); |
| 127 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 0); |
| 128 | } |
| 129 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(drop_counter.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]get().(), 200); |
| 130 | } |
| 131 | |
| 132 | /// Test with bools. |
| 133 | /// |
| 134 | /// Bools, unlike integers, have invalid bit patterns. Therefore, ever having an uninitialized bool |
| 135 | /// is insta-UB. Make sure miri doesn't find any such thing. |
| 136 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 137 | fn test_alloc_uninitialized_boolsrust-analyzer cargo typed-arena 2.0.2 test/test_alloc_uninitialized_bools().() { |
| 138 | const LENrust-analyzer cargo typed-arena 2.0.2 test/LEN.: usize = 20; |
| 139 | unsafe { |
| 140 | let arena: Arenarust-analyzer cargo typed-arena 2.0.2 Arena#<bool> = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(2); |
| 141 | let slice = arena.alloc_uninitializedrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_uninitialized().(LENrust-analyzer cargo typed-arena 2.0.2 test/LEN.); |
| 142 | for elem in slice.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() { |
| 143 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(elem.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().(), true); |
| 144 | } |
| 145 | // Now it is fully initialized, we can safely transmute the slice. |
| 146 | let slice: &mut [bool] = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().(slice); |
| 147 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&[true; LENrust-analyzer cargo typed-arena 2.0.2 test/LEN.], slice); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /// Check nothing bad happens by panicking during initialization of borrowed slice. |
| 152 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 153 | fn alloc_uninitialized_with_panicrust-analyzer cargo typed-arena 2.0.2 test/alloc_uninitialized_with_panic().() { |
| 154 | struct Dropperrust-analyzer cargo typed-arena 2.0.2 test/Dropper#(bool); |
| 155 | |
| 156 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Dropperrust-analyzer cargo typed-arena 2.0.2 test/Dropper# { |
| 157 | fn droprust-analyzer cargo typed-arena 2.0.2 test/impl#[Dropper][Drop]drop().(&mut self) { |
| 158 | // Just make sure we touch the value, to make sure miri would bite if it was |
| 159 | // unitialized |
| 160 | if self.0rust-analyzer cargo typed-arena 2.0.2 test/Dropper#0. { |
| 161 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | let mut reached_first_init = false; |
| 166 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::catch_unwindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/catch_unwind().(AssertUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/AssertUnwindSafe#(|| unsafe { |
| 167 | let arena: Arenarust-analyzer cargo typed-arena 2.0.2 Arena#<Dropperrust-analyzer cargo typed-arena 2.0.2 test/Dropper#> = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::newrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]new().(); |
| 168 | arena.reserve_extendrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]reserve_extend().(2); |
| 169 | let uninitialized = arena.uninitialized_arrayrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]uninitialized_array().(); |
| 170 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().uninitialized).lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= 2); |
| 171 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().uninitialized)[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/index/impl#[`[T]`][`IndexMut<I>`]index_mut()..as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().(), Dropperrust-analyzer cargo typed-arena 2.0.2 test/Dropper#(false)); |
| 172 | reached_first_init = true; |
| 173 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("To drop the arena"); |
| 174 | // If it didn't panic, we would continue by initializing the second one and confirming by |
| 175 | // .alloc_uninitialized(); |
| 176 | })) |
| 177 | .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(); |
| 178 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reached_first_init); |
| 179 | } |
| 180 | |
| 181 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 182 | fn test_uninitialized_arrayrust-analyzer cargo typed-arena 2.0.2 test/test_uninitialized_array().() { |
| 183 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(2); |
| 184 | let uninit = arena.uninitialized_arrayrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]uninitialized_array().(); |
| 185 | arena.alloc_extendrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_extend().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2); |
| 186 | unsafe { |
| 187 | for (&a, b) in (&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().uninit).iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2) { |
| 188 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(a.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().(), b); |
| 189 | } |
| 190 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!((&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().arena.uninitialized_arrayrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]uninitialized_array().()).as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() != (&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().uninit).as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().()); |
| 191 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(0); |
| 192 | let uninit = arena.uninitialized_arrayrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]uninitialized_array().(); |
| 193 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!((&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().uninit).lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 3); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 198 | fn dont_trust_the_iterator_sizerust-analyzer cargo typed-arena 2.0.2 test/dont_trust_the_iterator_size().() { |
| 199 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat/repeat().; |
| 200 | |
| 201 | struct WrongSizeIterrust-analyzer cargo typed-arena 2.0.2 test/WrongSizeIter#<I>(I); |
| 202 | impl<I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for WrongSizeIterrust-analyzer cargo typed-arena 2.0.2 test/WrongSizeIter#<I> |
| 203 | where |
| 204 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 205 | { |
| 206 | type Itemrust-analyzer cargo typed-arena 2.0.2 test/impl#[`WrongSizeIter<I>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#; |
| 207 | |
| 208 | fn nextrust-analyzer cargo typed-arena 2.0.2 test/impl#[`WrongSizeIter<I>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo typed-arena 2.0.2 test/impl#[`WrongSizeIter<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 209 | self.0rust-analyzer cargo typed-arena 2.0.2 test/WrongSizeIter#0..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() |
| 210 | } |
| 211 | |
| 212 | fn size_hintrust-analyzer cargo typed-arena 2.0.2 test/impl#[`WrongSizeIter<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 213 | (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | impl<I> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for WrongSizeIterrust-analyzer cargo typed-arena 2.0.2 test/WrongSizeIter#<I> where I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# {} |
| 218 | |
| 219 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(2); |
| 220 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(0); |
| 221 | let slice = arena.alloc_extendrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_extend().(WrongSizeIterrust-analyzer cargo typed-arena 2.0.2 test/WrongSizeIter#(repeatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat/repeat().(1).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(1_000))); |
| 222 | // Allocation of 1000 elements should have created a new chunk |
| 223 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 224 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(slice.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 1000); |
| 225 | } |
| 226 | |
| 227 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 228 | fn arena_is_sendrust-analyzer cargo typed-arena 2.0.2 test/arena_is_send().() { |
| 229 | fn assert_is_sendrust-analyzer cargo typed-arena 2.0.2 test/assert_is_send().<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(_: T) {} |
| 230 | |
| 231 | // If `T` is `Send`, ... |
| 232 | assert_is_sendrust-analyzer cargo typed-arena 2.0.2 test/assert_is_send().(42_u32); |
| 233 | |
| 234 | // Then `Arena<T>` is also `Send`. |
| 235 | let arena: Arenarust-analyzer cargo typed-arena 2.0.2 Arena#<u32> = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::newrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]new().(); |
| 236 | assert_is_sendrust-analyzer cargo typed-arena 2.0.2 test/assert_is_send().(arena); |
| 237 | } |
| 238 | |
| 239 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 240 | fn iter_mut_low_capacityrust-analyzer cargo typed-arena 2.0.2 test/iter_mut_low_capacity().() { |
| 241 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 242 | struct NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(usize); |
| 243 | |
| 244 | const MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX.: usize = 1_000; |
| 245 | const CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.: usize = 16; |
| 246 | |
| 247 | let mut arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.); |
| 248 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 249 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)); |
| 250 | } |
| 251 | |
| 252 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 253 | arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 1, |
| 254 | "expected multiple chunks" |
| 255 | ); |
| 256 | |
| 257 | let mut iter = arena.iter_mutrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]iter_mut().(); |
| 258 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 259 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)), iter.nextrust-analyzer cargo typed-arena 2.0.2 impl#[`IterMut<'a, T>`][Iterator]next().()); |
| 260 | } |
| 261 | |
| 262 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, iter.nextrust-analyzer cargo typed-arena 2.0.2 impl#[`IterMut<'a, T>`][Iterator]next().()); |
| 263 | } |
| 264 | |
| 265 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 266 | fn iter_mut_high_capacityrust-analyzer cargo typed-arena 2.0.2 test/iter_mut_high_capacity().() { |
| 267 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 268 | struct NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(usize); |
| 269 | |
| 270 | const MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX.: usize = 1_000; |
| 271 | const CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.: usize = 8192; |
| 272 | |
| 273 | let mut arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.); |
| 274 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 275 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)); |
| 276 | } |
| 277 | |
| 278 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 279 | arena.chunksrust-analyzer cargo typed-arena 2.0.2 Arena#chunks..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().().restrust-analyzer cargo typed-arena 2.0.2 ChunkList#rest..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 280 | "expected single chunk" |
| 281 | ); |
| 282 | |
| 283 | let mut iter = arena.iter_mutrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]iter_mut().(); |
| 284 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 285 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)), iter.nextrust-analyzer cargo typed-arena 2.0.2 impl#[`IterMut<'a, T>`][Iterator]next().()); |
| 286 | } |
| 287 | |
| 288 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, iter.nextrust-analyzer cargo typed-arena 2.0.2 impl#[`IterMut<'a, T>`][Iterator]next().()); |
| 289 | } |
| 290 | |
| 291 | fn assert_size_hintrust-analyzer cargo typed-arena 2.0.2 test/assert_size_hint().<T>(arena_len: usize, iter: IterMutrust-analyzer cargo typed-arena 2.0.2 IterMut#<'_, T>) { |
| 292 | let (min, max) = iter.size_hintrust-analyzer cargo typed-arena 2.0.2 impl#[`IterMut<'a, T>`][Iterator]size_hint().(); |
| 293 | |
| 294 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(max.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 295 | let max = max.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 296 | |
| 297 | // Check that the actual arena length lies between the estimated min and max |
| 298 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(min <= arena_len); |
| 299 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(max >= arena_len); |
| 300 | |
| 301 | // Check that the min and max estimates are within a factor of 3 |
| 302 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(min >= arena_len /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). 3); |
| 303 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(max <= arena_len *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 3); |
| 304 | } |
| 305 | |
| 306 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 307 | fn size_hintrust-analyzer cargo typed-arena 2.0.2 test/size_hint().() { |
| 308 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 309 | struct NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(usize); |
| 310 | |
| 311 | const MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX.: usize = 32; |
| 312 | const CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.: usize = 0; |
| 313 | |
| 314 | for cap in CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().16/* check some non-power-of-two capacities */) { |
| 315 | let mut arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(cap); |
| 316 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 317 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)); |
| 318 | let iter = arena.iter_mutrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]iter_mut().(); |
| 319 | assert_size_hintrust-analyzer cargo typed-arena 2.0.2 test/assert_size_hint().(i, iter); |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // Ensure that `alloc_extend` doesn't violate provenance of |
| 325 | // existing references. (Note: This test is pointless except |
| 326 | // under miri). |
| 327 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 328 | fn check_extend_provenancerust-analyzer cargo typed-arena 2.0.2 test/check_extend_provenance().() { |
| 329 | let arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::newrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]new().(); |
| 330 | let a = arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(0); |
| 331 | arena.alloc_extendrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc_extend().([0]); |
| 332 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().a = 1; |
| 333 | } |
| 334 | |
| 335 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 336 | fn size_hint_low_initial_capacitiesrust-analyzer cargo typed-arena 2.0.2 test/size_hint_low_initial_capacities().() { |
| 337 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 338 | struct NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(usize); |
| 339 | |
| 340 | const MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX.: usize = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(miri) { 100 } else { 25_000 }; |
| 341 | const CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.: usize = 0; |
| 342 | |
| 343 | for cap in CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().128/* check some non-power-of-two capacities */) { |
| 344 | let mut arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(cap); |
| 345 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 346 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)); |
| 347 | let iter = arena.iter_mutrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]iter_mut().(); |
| 348 | assert_size_hintrust-analyzer cargo typed-arena 2.0.2 test/assert_size_hint().(i, iter); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 354 | fn size_hint_high_initial_capacitiesrust-analyzer cargo typed-arena 2.0.2 test/size_hint_high_initial_capacities().() { |
| 355 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 356 | struct NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(usize); |
| 357 | |
| 358 | const MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX.: usize = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(miri) { 100 } else { 25_000 }; |
| 359 | const CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.: usize = 8164; |
| 360 | |
| 361 | for cap in CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().128/* check some non-power-of-two capacities */) { |
| 362 | let mut arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(cap); |
| 363 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 364 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)); |
| 365 | let iter = arena.iter_mutrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]iter_mut().(); |
| 366 | assert_size_hintrust-analyzer cargo typed-arena 2.0.2 test/assert_size_hint().(i, iter); |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 372 | fn size_hint_many_itemsrust-analyzer cargo typed-arena 2.0.2 test/size_hint_many_items().() { |
| 373 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 374 | struct NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(usize); |
| 375 | |
| 376 | const MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX.: usize = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(miri) { 500 } else { 5_000_000 }; |
| 377 | const CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.: usize = 16; |
| 378 | |
| 379 | let mut arena = Arenarust-analyzer cargo typed-arena 2.0.2 Arena#::with_capacityrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]with_capacity().(CAPrust-analyzer cargo typed-arena 2.0.2 test/CAP.); |
| 380 | for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#MAXrust-analyzer cargo typed-arena 2.0.2 test/MAX. { |
| 381 | arena.allocrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]alloc().(NonCopyrust-analyzer cargo typed-arena 2.0.2 test/NonCopy#(i)); |
| 382 | let iter = arena.iter_mutrust-analyzer cargo typed-arena 2.0.2 impl#[`Arena<T>`]iter_mut().(); |
| 383 | assert_size_hintrust-analyzer cargo typed-arena 2.0.2 test/assert_size_hint().(i, iter); |
| 384 | } |
| 385 | } |