summaryrefslogtreecommitdiff
path: root/src/liballoc/raw_vec/tests.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-07-27 17:39:01 +0000
committerbors <bors@rust-lang.org>2020-07-27 17:39:01 +0000
commit54e000891ffccd4cbfb92146b92736c83085df63 (patch)
tree1200bb13eb9ae22def4c43bc657bc56da8faedc6 /src/liballoc/raw_vec/tests.rs
parent4a90e36c85336d1d4b209556c1a9733210bbff19 (diff)
parent6d9705220fec4553d693a7c19d99496e14c89edf (diff)
downloadrust-tmp-nightly.tar.gz
Auto merge of #73265 - mark-i-m:mv-std, r=<try>tmp-nightly
mv std libs to library/ This is the first step in refactoring the directory layout of this repository, with further followup steps planned (but not done yet). Background: currently, all crates are under src/, without nested src directories and with the unconventional `lib*` prefixes (e.g., `src/libcore/lib.rs`). This directory structures is not idiomatic and makes the `src/` directory rather overwhelming. To improve contributor experience and make things a bit more approachable, we are reorganizing the repo a bit. In this PR, we move the standard libs (basically anything that is "runtime", as opposed to part of the compiler, build system, or one of the tools, etc). The new layout moves these libraries to a new `library/` directory in the root of the repo. Additionally, we remove the `lib*` prefixes and add nested `src/` directories. The other crates/tools in this repo are not touched. So in summary: ``` library/<crate>/src/*.rs src/<all the rest> // unchanged ``` where `<crate>` is: - core - alloc - std - test - proc_macro - panic_abort - panic_unwind - profiler_builtins - term - unwind - rtstartup - backtrace - rustc-std-workspace-* There was a lot of discussion about this and a few rounds of compiler team approvals, FCPs, MCPs, and nominations. The original MCP is https://github.com/rust-lang/compiler-team/issues/298. The final approval of the compiler team was given here: https://github.com/rust-lang/rust/pull/73265#issuecomment-659498446. The name `library` was chosen to complement a later move of the compiler crates to a `compiler/` directory. There was a lot of discussion around adding the nested `src/` directories. Note that this does increase the nesting depth (plausibly important for manual traversal of the tree, e.g., through GitHub's UI or `cd`), but this is deemed to be better as it fits the standard layout of Rust crates throughout most of the ecosystem, though there is some debate about how much this should apply to multi-crate projects. Overall, there seem to be more people in favor of nested `src/` than against. After this PR, there are no dependencies out of the `library/` directory except on the `build_helper` (or crates.io crates).
Diffstat (limited to 'src/liballoc/raw_vec/tests.rs')
-rw-r--r--src/liballoc/raw_vec/tests.rs78
1 files changed, 0 insertions, 78 deletions
diff --git a/src/liballoc/raw_vec/tests.rs b/src/liballoc/raw_vec/tests.rs
deleted file mode 100644
index 5408faa079c..00000000000
--- a/src/liballoc/raw_vec/tests.rs
+++ /dev/null
@@ -1,78 +0,0 @@
-use super::*;
-
-#[test]
-fn allocator_param() {
- use crate::alloc::AllocErr;
-
- // Writing a test of integration between third-party
- // allocators and `RawVec` is a little tricky because the `RawVec`
- // API does not expose fallible allocation methods, so we
- // cannot check what happens when allocator is exhausted
- // (beyond detecting a panic).
- //
- // Instead, this just checks that the `RawVec` methods do at
- // least go through the Allocator API when it reserves
- // storage.
-
- // A dumb allocator that consumes a fixed amount of fuel
- // before allocation attempts start failing.
- struct BoundedAlloc {
- fuel: usize,
- }
- unsafe impl AllocRef for BoundedAlloc {
- fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
- let size = layout.size();
- if size > self.fuel {
- return Err(AllocErr);
- }
- match Global.alloc(layout, init) {
- ok @ Ok(_) => {
- self.fuel -= size;
- ok
- }
- err @ Err(_) => err,
- }
- }
- unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
- unsafe { Global.dealloc(ptr, layout) }
- }
- }
-
- let a = BoundedAlloc { fuel: 500 };
- let mut v: RawVec<u8, _> = RawVec::with_capacity_in(50, a);
- assert_eq!(v.alloc.fuel, 450);
- v.reserve(50, 150); // (causes a realloc, thus using 50 + 150 = 200 units of fuel)
- assert_eq!(v.alloc.fuel, 250);
-}
-
-#[test]
-fn reserve_does_not_overallocate() {
- {
- let mut v: RawVec<u32> = RawVec::new();
- // First, `reserve` allocates like `reserve_exact`.
- v.reserve(0, 9);
- assert_eq!(9, v.capacity());
- }
-
- {
- let mut v: RawVec<u32> = RawVec::new();
- v.reserve(0, 7);
- assert_eq!(7, v.capacity());
- // 97 is more than double of 7, so `reserve` should work
- // like `reserve_exact`.
- v.reserve(7, 90);
- assert_eq!(97, v.capacity());
- }
-
- {
- let mut v: RawVec<u32> = RawVec::new();
- v.reserve(0, 12);
- assert_eq!(12, v.capacity());
- v.reserve(12, 3);
- // 3 is less than half of 12, so `reserve` must grow
- // exponentially. At the time of writing this test grow
- // factor is 2, so new capacity is 24, however, grow factor
- // of 1.5 is OK too. Hence `>= 18` in assert.
- assert!(v.capacity() >= 12 + 12 / 2);
- }
-}