From 1e91e4e20a5d6e50e281c6e87a3a61cc735e266f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 22 Nov 2019 23:11:56 +0100 Subject: enable panic-catching tests in Miri --- src/liballoc/tests/binary_heap.rs | 2 +- src/liballoc/tests/vec.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/liballoc/tests') diff --git a/src/liballoc/tests/binary_heap.rs b/src/liballoc/tests/binary_heap.rs index a44cf1eaf6d..81b22ca815b 100644 --- a/src/liballoc/tests/binary_heap.rs +++ b/src/liballoc/tests/binary_heap.rs @@ -347,7 +347,7 @@ fn assert_covariance() { // Destructors must be called exactly once per element. // FIXME: re-enable emscripten once it can unwind again #[test] -#[cfg(not(any(miri, target_os = "emscripten")))] // Miri does not support catching panics +#[cfg(not(target_os = "emscripten"))] fn panic_safe() { use std::cmp; use std::panic::{self, AssertUnwindSafe}; diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 80537217697..58b555ecb4e 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -944,10 +944,9 @@ fn drain_filter_complex() { } } -// Miri does not support catching panics // FIXME: re-enable emscripten once it can unwind again #[test] -#[cfg(not(any(miri, target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] fn drain_filter_consumed_panic() { use std::rc::Rc; use std::sync::Mutex; @@ -999,7 +998,7 @@ fn drain_filter_consumed_panic() { // FIXME: Re-enable emscripten once it can catch panics #[test] -#[cfg(not(any(miri, target_os = "emscripten")))] // Miri does not support catching panics +#[cfg(not(target_os = "emscripten"))] fn drain_filter_unconsumed_panic() { use std::rc::Rc; use std::sync::Mutex; -- cgit 1.4.1-3-g733a5 From 3277209af5c3369cbf1786d25cbf48c9a131996b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 22 Nov 2019 23:21:20 +0100 Subject: use catch_panic instead of thread::spawn to catch panics --- src/liballoc/tests/slice.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/liballoc/tests') diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index ad2cd7c95eb..62b33c02cae 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -4,7 +4,6 @@ use std::mem; use std::panic; use std::rc::Rc; use std::sync::atomic::{Ordering::Relaxed, AtomicUsize}; -use std::thread; use rand::{Rng, RngCore, thread_rng}; use rand::seq::SliceRandom; @@ -1406,11 +1405,10 @@ fn test_box_slice_clone() { #[test] #[allow(unused_must_use)] // here, we care about the side effects of `.clone()` #[cfg_attr(target_os = "emscripten", ignore)] -#[cfg(not(miri))] // Miri does not support threads +#[cfg(not(miri))] // Miri does not support catching panics fn test_box_slice_clone_panics() { use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; - use std::thread::spawn; struct Canary { count: Arc, @@ -1446,7 +1444,7 @@ fn test_box_slice_clone_panics() { panics: true, }; - spawn(move || { + std::panic::catch_unwind(move || { // When xs is dropped, +5. let xs = vec![canary.clone(), canary.clone(), canary.clone(), panic, canary] .into_boxed_slice(); @@ -1454,7 +1452,6 @@ fn test_box_slice_clone_panics() { // When panic is cloned, +3. xs.clone(); }) - .join() .unwrap_err(); // Total = 8 @@ -1566,7 +1563,7 @@ macro_rules! test { } let v = $input.to_owned(); - let _ = thread::spawn(move || { + let _ = std::panic::catch_unwind(move || { let mut v = v; let mut panic_countdown = panic_countdown; v.$func(|a, b| { @@ -1577,7 +1574,7 @@ macro_rules! test { panic_countdown -= 1; a.cmp(b) }) - }).join(); + }); // Check that the number of things dropped is exactly // what we expect (i.e., the contents of `v`). @@ -1598,7 +1595,7 @@ thread_local!(static SILENCE_PANIC: Cell = Cell::new(false)); #[test] #[cfg_attr(target_os = "emscripten", ignore)] // no threads -#[cfg(not(miri))] // Miri does not support threads +#[cfg(not(miri))] // Miri does not support catching panics fn panic_safe() { let prev = panic::take_hook(); panic::set_hook(Box::new(move |info| { -- cgit 1.4.1-3-g733a5 From 8af2f22985c672bf4cb23b615ac97af00031a2ca Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 22 Nov 2019 23:35:56 +0100 Subject: enable panic-catching tests in Miri --- src/liballoc/tests/slice.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/liballoc/tests') diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 62b33c02cae..6433cbd1842 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -1405,7 +1405,6 @@ fn test_box_slice_clone() { #[test] #[allow(unused_must_use)] // here, we care about the side effects of `.clone()` #[cfg_attr(target_os = "emscripten", ignore)] -#[cfg(not(miri))] // Miri does not support catching panics fn test_box_slice_clone_panics() { use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -1595,7 +1594,6 @@ thread_local!(static SILENCE_PANIC: Cell = Cell::new(false)); #[test] #[cfg_attr(target_os = "emscripten", ignore)] // no threads -#[cfg(not(miri))] // Miri does not support catching panics fn panic_safe() { let prev = panic::take_hook(); panic::set_hook(Box::new(move |info| { @@ -1606,7 +1604,12 @@ fn panic_safe() { let mut rng = thread_rng(); - for len in (1..20).chain(70..MAX_LEN) { + #[cfg(not(miri))] // Miri is too slow + let large_range = 70..MAX_LEN; + #[cfg(miri)] + let large_range = 0..0; // empty range + + for len in (1..20).chain(large_range) { for &modulus in &[5, 20, 50] { for &has_runs in &[false, true] { let mut input = (0..len) -- cgit 1.4.1-3-g733a5 From a2299799e6193799f4d2cb546e56589c5dd587aa Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 23 Nov 2019 08:53:53 +0100 Subject: enable more panic-catching tests in Miri --- src/liballoc/tests/binary_heap.rs | 3 +++ src/liballoc/tests/slice.rs | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/liballoc/tests') diff --git a/src/liballoc/tests/binary_heap.rs b/src/liballoc/tests/binary_heap.rs index 81b22ca815b..a896a1064d9 100644 --- a/src/liballoc/tests/binary_heap.rs +++ b/src/liballoc/tests/binary_heap.rs @@ -376,7 +376,10 @@ fn panic_safe() { } let mut rng = thread_rng(); const DATASZ: usize = 32; + #[cfg(not(miri))] // Miri is too slow const NTEST: usize = 10; + #[cfg(miri)] + const NTEST: usize = 1; // don't use 0 in the data -- we want to catch the zeroed-out case. let data = (1..=DATASZ).collect::>(); diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 6433cbd1842..d9707b95740 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -1605,12 +1605,17 @@ fn panic_safe() { let mut rng = thread_rng(); #[cfg(not(miri))] // Miri is too slow - let large_range = 70..MAX_LEN; + let lens = (1..20).chain(70..MAX_LEN); + #[cfg(not(miri))] // Miri is too slow + let moduli = &[5, 20, 50]; + #[cfg(miri)] - let large_range = 0..0; // empty range + let lens = (1..13); + #[cfg(miri)] + let moduli = &[10]; - for len in (1..20).chain(large_range) { - for &modulus in &[5, 20, 50] { + for len in lens { + for &modulus in moduli { for &has_runs in &[false, true] { let mut input = (0..len) .map(|id| { @@ -1643,6 +1648,9 @@ fn panic_safe() { } } } + + // Set default panic hook again. + drop(panic::take_hook()); } #[test] -- cgit 1.4.1-3-g733a5 From 16fabd8efd416a8b957e369b8be2470e1271af9e Mon Sep 17 00:00:00 2001 From: Brian Wignall Date: Tue, 26 Nov 2019 22:19:54 -0500 Subject: Fix spelling typos --- src/bootstrap/compile.rs | 2 +- src/liballoc/collections/btree/node.rs | 2 +- src/liballoc/tests/vec.rs | 2 +- src/liballoc/vec.rs | 2 +- src/libcore/hint.rs | 2 +- src/libcore/intrinsics.rs | 2 +- src/libpanic_unwind/dwarf/eh.rs | 2 +- src/librustc/mir/interpret/error.rs | 2 +- src/librustc/mir/mod.rs | 2 +- src/librustc/traits/auto_trait.rs | 6 +++--- src/librustc/ty/diagnostics.rs | 4 ++-- src/librustc/ty/print/pretty.rs | 2 +- src/librustc_data_structures/stable_hasher.rs | 2 +- src/librustc_error_codes/error_codes/E0307.md | 2 +- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/build/matches/test.rs | 2 +- src/librustc_mir/const_eval.rs | 2 +- src/librustc_mir/interpret/machine.rs | 2 +- src/librustc_mir/transform/promote_consts.rs | 2 +- src/librustc_parse/parser/diagnostics.rs | 4 ++-- src/librustc_parse/parser/item.rs | 2 +- src/librustc_target/spec/i686_unknown_uefi.rs | 2 +- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/expr.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 2 +- src/libstd/error.rs | 2 +- src/libstd/sys/unix/fs.rs | 4 ++-- src/libstd/sys/wasm/fast_thread_local.rs | 2 +- src/libsyntax_expand/mbe/macro_rules.rs | 2 +- src/test/rustdoc/issue-66159.rs | 2 +- src/test/ui/layout/homogeneous-aggr-zero-sized-c-struct.rs | 2 +- ...ait-object-with-self-in-projection-output-repeated-supertrait.rs | 2 +- 32 files changed, 37 insertions(+), 37 deletions(-) (limited to 'src/liballoc/tests') diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 8e5fe2520ca..f686dfe71b9 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -113,7 +113,7 @@ impl Step for Std { } } -/// Copies third pary objects needed by various targets. +/// Copies third party objects needed by various targets. fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: Interned) -> Vec { diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index 0b5a271dbea..ab010b35f6a 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -596,7 +596,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef, K, V, Type> { // (We might be one-past-the-end, but that is allowed by LLVM.) // Getting the pointer is tricky though. `NodeHeader` does not have a `keys` // field because we want its size to not depend on the alignment of `K` - // (needed becuase `as_header` should be safe). We cannot call `as_leaf` + // (needed because `as_header` should be safe). We cannot call `as_leaf` // because we might be the shared root. // For this reason, `NodeHeader` has this `K2` parameter (that's usually `()` // and hence just adds a size-0-align-1 field, not affecting layout). diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 80537217697..0cc8da096f3 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -985,7 +985,7 @@ fn drain_filter_consumed_panic() { }; let drain = data.drain_filter(filter); - // NOTE: The DrainFilter is explictly consumed + // NOTE: The DrainFilter is explicitly consumed drain.for_each(drop); }); diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 07e4358d644..3329a48b7c4 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2837,7 +2837,7 @@ pub struct DrainFilter<'a, T, F> old_len: usize, /// The filter test predicate. pred: F, - /// A flag that indicates a panic has occured in the filter test prodicate. + /// A flag that indicates a panic has occurred in the filter test prodicate. /// This is used as a hint in the drop implmentation to prevent consumption /// of the remainder of the `DrainFilter`. Any unprocessed items will be /// backshifted in the `vec`, but no further items will be dropped or diff --git a/src/libcore/hint.rs b/src/libcore/hint.rs index f68a3e5a76f..a295e65bb55 100644 --- a/src/libcore/hint.rs +++ b/src/libcore/hint.rs @@ -113,7 +113,7 @@ pub fn spin_loop() { pub fn black_box(dummy: T) -> T { // We need to "use" the argument in some way LLVM can't introspect, and on // targets that support it we can typically leverage inline assembly to do - // this. LLVM's intepretation of inline assembly is that it's, well, a black + // this. LLVM's interpretation of inline assembly is that it's, well, a black // box. This isn't the greatest implementation since it probably deoptimizes // more than we want, but it's so far good enough. unsafe { diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 6de20418bb2..e3dc5630c94 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1279,7 +1279,7 @@ extern "rust-intrinsic" { /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`. pub fn unchecked_add(x: T, y: T) -> T; - /// Returns the result of an unchecked substraction, resulting in + /// Returns the result of an unchecked subtraction, resulting in /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`. pub fn unchecked_sub(x: T, y: T) -> T; diff --git a/src/libpanic_unwind/dwarf/eh.rs b/src/libpanic_unwind/dwarf/eh.rs index 1e9e7e4b835..242eb6750b3 100644 --- a/src/libpanic_unwind/dwarf/eh.rs +++ b/src/libpanic_unwind/dwarf/eh.rs @@ -130,7 +130,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>, foreign_e fn interpret_cs_action(cs_action: u64, lpad: usize, foreign_exception: bool) -> EHAction { if cs_action == 0 { // If cs_action is 0 then this is a cleanup (Drop::drop). We run these - // for both Rust panics and foriegn exceptions. + // for both Rust panics and foreign exceptions. EHAction::Cleanup(lpad) } else if foreign_exception { // catch_unwind should not catch foreign exceptions, only Rust panics. diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 4fe82f03b03..7fb669314eb 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -185,7 +185,7 @@ pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<' } /// Packages the kind of error we got from the const code interpreter -/// up with a Rust-level backtrace of where the error occured. +/// up with a Rust-level backtrace of where the error occurred. /// Thsese should always be constructed by calling `.into()` on /// a `InterpError`. In `librustc_mir::interpret`, we have `throw_err_*` /// macros for this. diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index bd793fd07bf..c48298dacf4 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -450,7 +450,7 @@ impl rustc_serialize::UseSpecializedDecodable for ClearCrossCrate< /// Grouped information about the source code origin of a MIR entity. /// Intended to be inspected by diagnostics and debuginfo. /// Most passes can work with it as a whole, within a single function. -// The unoffical Cranelift backend, at least as of #65828, needs `SourceInfo` to implement `Eq` and +// The unofficial Cranelift backend, at least as of #65828, needs `SourceInfo` to implement `Eq` and // `Hash`. Please ping @bjorn3 if removing them. #[derive(Copy, Clone, Debug, Eq, PartialEq, RustcEncodable, RustcDecodable, Hash, HashStable)] pub struct SourceInfo { diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index 479bffc3ea0..a0d9f52d28a 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -461,7 +461,7 @@ impl AutoTraitFinder<'tcx> { // The old predicate has a region variable where the new // predicate has some other kind of region. An region // variable isn't something we can actually display to a user, - // so we choose ther new predicate (which doesn't have a region + // so we choose their new predicate (which doesn't have a region // varaible). // // In both cases, we want to remove the old predicate, @@ -703,7 +703,7 @@ impl AutoTraitFinder<'tcx> { // that we could add to our ParamEnv that would 'fix' this kind // of error, as it's not caused by an unimplemented type. // - // 2. We succesfully project the predicate (Ok(Some(_))), generating + // 2. We successfully project the predicate (Ok(Some(_))), generating // some subobligations. We then process these subobligations // like any other generated sub-obligations. // @@ -770,7 +770,7 @@ impl AutoTraitFinder<'tcx> { Ok(None) => { // It's ok not to make progress when hvave no inference variables - // in that case, we were only performing unifcation to check if an - // error occured (which would indicate that it's impossible for our + // error occurred (which would indicate that it's impossible for our // type to implement the auto trait). // However, we should always make progress (either by generating // subobligations or getting an error) when we started off with diff --git a/src/librustc/ty/diagnostics.rs b/src/librustc/ty/diagnostics.rs index 95bdce2d222..3a55aefe85d 100644 --- a/src/librustc/ty/diagnostics.rs +++ b/src/librustc/ty/diagnostics.rs @@ -15,7 +15,7 @@ impl<'tcx> TyS<'tcx> { } } - /// Whether the type is succinctly representable as a type instead of just refered to with a + /// Whether the type is succinctly representable as a type instead of just referred to with a /// description in error messages. This is used in the main error message. pub fn is_simple_ty(&self) -> bool { match self.kind { @@ -28,7 +28,7 @@ impl<'tcx> TyS<'tcx> { } } - /// Whether the type is succinctly representable as a type instead of just refered to with a + /// Whether the type is succinctly representable as a type instead of just referred to with a /// description in error messages. This is used in the primary span label. Beyond what /// `is_simple_ty` includes, it also accepts ADTs with no type arguments and references to /// ADTs with no type arguments. diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index e7143396f09..2a311ea9624 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -54,7 +54,7 @@ thread_local! { } /// Avoids running any queries during any prints that occur -/// during the closure. This may alter the apperance of some +/// during the closure. This may alter the appearance of some /// types (e.g. forcing verbose printing for opaque types). /// This method is used during some queries (e.g. `predicates_of` /// for opaque types), to ensure that any debug printing that diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index ce62021ac17..70492d49922 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -149,7 +149,7 @@ impl Hasher for StableHasher { /// /// That second condition is usually not required for hash functions /// (e.g. `Hash`). In practice this means that `hash_stable` must feed any -/// information into the hasher that a `PartialEq` comparision takes into +/// information into the hasher that a `PartialEq` comparison takes into /// account. See [#49300](https://github.com/rust-lang/rust/issues/49300) /// for an example where violating this invariant has caused trouble in the /// past. diff --git a/src/librustc_error_codes/error_codes/E0307.md b/src/librustc_error_codes/error_codes/E0307.md index c382f406e4b..1779e5dbb30 100644 --- a/src/librustc_error_codes/error_codes/E0307.md +++ b/src/librustc_error_codes/error_codes/E0307.md @@ -1,5 +1,5 @@ This error indicates that the `self` parameter in a method has an invalid -"reciever type". +"receiver type". Methods take a special first parameter, of which there are three variants: `self`, `&self`, and `&mut self`. These are syntactic sugar for diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 90e39286ec8..b52ad6d6500 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -937,7 +937,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.check_access_for_conflict(location, place_span, sd, rw, flow_state); if let (Activation(_, borrow_idx), true) = (kind.1, conflict_error) { - // Suppress this warning when there's an error being emited for the + // Suppress this warning when there's an error being emitted for the // same borrow: fixing the error is likely to fix the warning. self.reservation_warnings.remove(&borrow_idx); } diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index 5c2f72c0a06..07c5d640a32 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -488,7 +488,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// Given that we are performing `test` against `test_place`, this job /// sorts out what the status of `candidate` will be after the test. See /// `test_candidates` for the usage of this function. The returned index is - /// the index that this candiate should be placed in the + /// the index that this candidate should be placed in the /// `target_candidates` vec. The candidate may be modified to update its /// `match_pairs`. /// diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 640b5fbdff3..eb9d04f7d8e 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -55,7 +55,7 @@ fn op_to_const<'tcx>( ecx: &CompileTimeEvalContext<'_, 'tcx>, op: OpTy<'tcx>, ) -> &'tcx ty::Const<'tcx> { - // We do not have value optmizations for everything. + // We do not have value optimizations for everything. // Only scalars and slices, since they are very common. // Note that further down we turn scalars of undefined bits back to `ByRef`. These can result // from scalar unions that are initialized with one of their zero sized variants. We could diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index d2ea55a5d3c..b7cde626415 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -95,7 +95,7 @@ pub trait Machine<'mir, 'tcx>: Sized { type PointerTag: ::std::fmt::Debug + Copy + Eq + Hash + 'static; /// Machines can define extra (non-instance) things that represent values of function pointers. - /// For example, Miri uses this to return a fucntion pointer from `dlsym` + /// For example, Miri uses this to return a function pointer from `dlsym` /// that can later be called to execute the right thing. type ExtraFnVal: ::std::fmt::Debug + Copy; diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 86ecfbb4fbe..9a7f47389bc 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -185,7 +185,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> { // Ignore drops, if the temp gets promoted, // then it's constant and thus drop is noop. - // Non-uses are also irrelevent. + // Non-uses are also irrelevant. if context.is_drop() || !context.is_use() { debug!( "visit_local: context.is_drop={:?} context.is_use={:?}", diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index fc334a558f5..da8bf89ebf3 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -1515,11 +1515,11 @@ impl<'a> Parser<'a> { } } - /// Replace duplicated recovered parameters with `_` pattern to avoid unecessary errors. + /// Replace duplicated recovered parameters with `_` pattern to avoid unnecessary errors. /// /// This is necessary because at this point we don't know whether we parsed a function with /// anonymous parameters or a function with names but no types. In order to minimize - /// unecessary errors, we assume the parameters are in the shape of `fn foo(a, b, c)` where + /// unnecessary errors, we assume the parameters are in the shape of `fn foo(a, b, c)` where /// the parameters are *names* (so we don't emit errors about not being able to find `b` in /// the local scope), but if we find the same name multiple times, like in `fn foo(i8, i8)`, /// we deduplicate them to not complain about duplicated parameter names. diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 2c9d4004226..64c03da4e28 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -2028,7 +2028,7 @@ impl<'a> Parser<'a> { let mut params: Vec<_> = params.into_iter().filter_map(|x| x).collect(); - // Replace duplicated recovered params with `_` pattern to avoid unecessary errors. + // Replace duplicated recovered params with `_` pattern to avoid unnecessary errors. self.deduplicate_recovered_params_names(&mut params); if c_variadic && params.len() <= 1 { diff --git a/src/librustc_target/spec/i686_unknown_uefi.rs b/src/librustc_target/spec/i686_unknown_uefi.rs index c60f7b422d1..e4b8b667ad0 100644 --- a/src/librustc_target/spec/i686_unknown_uefi.rs +++ b/src/librustc_target/spec/i686_unknown_uefi.rs @@ -32,7 +32,7 @@ pub fn target() -> TargetResult { // Backgound and Problem: // If we use i686-unknown-windows, the LLVM IA32 MSVC generates compiler intrinsic // _alldiv, _aulldiv, _allrem, _aullrem, _allmul, which will cause undefined symbol. - // A real issue is __aulldiv() is refered by __udivdi3() - udivmod_inner!(), from + // A real issue is __aulldiv() is referred by __udivdi3() - udivmod_inner!(), from // https://github.com/rust-lang-nursery/compiler-builtins. // As result, rust-lld generates link error finally. // Root-cause: diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index eda19a1a2da..4331d441aa0 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -434,7 +434,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { segment.ident.name, ) { // If this expression had a clone call when suggesting borrowing - // we want to suggest removing it because it'd now be unecessary. + // we want to suggest removing it because it'd now be unnecessary. sugg_sp = arg.span; } } diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 6c24f3184ca..4766360c048 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -550,7 +550,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } // Here we want to prevent struct constructors from returning unsized types. // There were two cases this happened: fn pointer coercion in stable - // and usual function call in presense of unsized_locals. + // and usual function call in presence of unsized_locals. // Also, as we just want to check sizedness, instead of introducing // placeholder lifetimes with probing, we just replace higher lifetimes // with fresh vars. diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 6508295b8ed..2a66e0539a1 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -916,7 +916,7 @@ fn receiver_is_valid<'fcx, 'tcx>( debug!("receiver_is_valid: type `{:?}` does not deref to `{:?}`", receiver_ty, self_ty); // If he receiver already has errors reported due to it, consider it valid to avoid - // unecessary errors (#58712). + // unnecessary errors (#58712). return receiver_ty.references_error(); } diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 74a9e7c9e33..ec1c444bcf8 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -206,7 +206,7 @@ pub trait Error: Debug + Display { TypeId::of::() } - /// Returns a stack backtrace, if available, of where this error ocurred. + /// Returns a stack backtrace, if available, of where this error occurred. /// /// This function allows inspecting the location, in code, of where an error /// happened. The returned `Backtrace` contains information about the stack diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index cbf751bec95..8669c48e3bb 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -128,7 +128,7 @@ cfg_has_statx! {{ // It is a trick to call `statx` with NULL pointers to check if the syscall // is available. According to the manual, it is expected to fail with EFAULT. // We do this mainly for performance, since it is nearly hundreds times - // faster than a normal successfull call. + // faster than a normal successful call. let err = cvt(statx(0, ptr::null(), 0, libc::STATX_ALL, ptr::null_mut())) .err() .and_then(|e| e.raw_os_error()); @@ -1223,7 +1223,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result { // The code below ensures that `FreeOnDrop` is never a null pointer unsafe { // `copyfile_state_free` returns -1 if the `to` or `from` files - // cannot be closed. However, this is not considerd this an + // cannot be closed. However, this is not considered this an // error. copyfile_state_free(self.0); } diff --git a/src/libstd/sys/wasm/fast_thread_local.rs b/src/libstd/sys/wasm/fast_thread_local.rs index ff2198175f0..3b0993fdb58 100644 --- a/src/libstd/sys/wasm/fast_thread_local.rs +++ b/src/libstd/sys/wasm/fast_thread_local.rs @@ -3,7 +3,7 @@ pub unsafe fn register_dtor(_t: *mut u8, _dtor: unsafe extern fn(*mut u8)) { // FIXME: right now there is no concept of "thread exit", but this is likely // going to show up at some point in the form of an exported symbol that the - // wasm runtime is oging to be expected to call. For now we basically just + // wasm runtime is going to be expected to call. For now we basically just // ignore the arguments, but if such a function starts to exist it will // likely look like the OSX implementation in `unix/fast_thread_local.rs` } diff --git a/src/libsyntax_expand/mbe/macro_rules.rs b/src/libsyntax_expand/mbe/macro_rules.rs index 72b7996628a..a1d8b5a5338 100644 --- a/src/libsyntax_expand/mbe/macro_rules.rs +++ b/src/libsyntax_expand/mbe/macro_rules.rs @@ -190,7 +190,7 @@ fn generic_extension<'cx>( // Take a snapshot of the state of pre-expansion gating at this point. // This is used so that if a matcher is not `Success(..)`ful, - // then the spans which became gated when parsing the unsucessful matcher + // then the spans which became gated when parsing the unsuccessful matcher // are not recorded. On the first `Success(..)`ful matcher, the spans are merged. let mut gated_spans_snaphot = mem::take(&mut *cx.parse_sess.gated_spans.spans.borrow_mut()); diff --git a/src/test/rustdoc/issue-66159.rs b/src/test/rustdoc/issue-66159.rs index a0a7adf6e81..a69ba61a283 100644 --- a/src/test/rustdoc/issue-66159.rs +++ b/src/test/rustdoc/issue-66159.rs @@ -4,7 +4,7 @@ // The issue was an ICE which meant that we never actually generated the docs // so if we have generated the docs, we're okay. -// Since we don't generate the docs for the auxilliary files, we can't actually +// Since we don't generate the docs for the auxiliary files, we can't actually // verify that the struct is linked correctly. // @has issue_66159/index.html diff --git a/src/test/ui/layout/homogeneous-aggr-zero-sized-c-struct.rs b/src/test/ui/layout/homogeneous-aggr-zero-sized-c-struct.rs index 622709e7de5..1c70624e4a2 100644 --- a/src/test/ui/layout/homogeneous-aggr-zero-sized-c-struct.rs +++ b/src/test/ui/layout/homogeneous-aggr-zero-sized-c-struct.rs @@ -2,7 +2,7 @@ // Show that `homogeneous_aggregate` code ignores zero-length C // arrays. This matches the recent C standard, though not the -// behavior of all older compilers, which somtimes consider `T[0]` to +// behavior of all older compilers, which sometimes consider `T[0]` to // be a "flexible array member" (see discussion on #56877 for // details). diff --git a/src/test/ui/traits/trait-object-with-self-in-projection-output-repeated-supertrait.rs b/src/test/ui/traits/trait-object-with-self-in-projection-output-repeated-supertrait.rs index 83dfe6664a5..39e817168f6 100644 --- a/src/test/ui/traits/trait-object-with-self-in-projection-output-repeated-supertrait.rs +++ b/src/test/ui/traits/trait-object-with-self-in-projection-output-repeated-supertrait.rs @@ -4,7 +4,7 @@ #![crate_name = "trait_test"] // Regression test related to #56288. Check that a supertrait projection (of -// `Output`) that references `Self` is ok if there is another occurence of +// `Output`) that references `Self` is ok if there is another occurrence of // the same supertrait that specifies the projection explicitly, even if // the projection's associated type is not explicitly specified in the object type. // -- cgit 1.4.1-3-g733a5 From 1c4d4539690fe841aefea2f54c243be5f0579970 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Nov 2019 19:30:49 -0800 Subject: Format liballoc with rustfmt --- src/liballoc/alloc/tests.rs | 6 +- src/liballoc/benches/btree/map.rs | 38 +++--- src/liballoc/benches/slice.rs | 63 +++++----- src/liballoc/benches/str.rs | 35 +++--- src/liballoc/benches/vec_deque.rs | 2 +- src/liballoc/benches/vec_deque_append.rs | 5 +- src/liballoc/collections/btree/mod.rs | 2 +- src/liballoc/collections/btree/search.rs | 42 ++++--- src/liballoc/collections/linked_list/tests.rs | 17 ++- src/liballoc/collections/vec_deque/tests.rs | 12 +- src/liballoc/fmt.rs | 22 ++-- src/liballoc/prelude/v1.rs | 12 +- src/liballoc/raw_vec/tests.rs | 9 +- src/liballoc/slice.rs | 173 ++++++++++++++------------ src/liballoc/tests.rs | 6 +- src/liballoc/tests/arc.rs | 39 +++--- src/liballoc/tests/boxed.rs | 2 +- src/liballoc/tests/btree/mod.rs | 7 +- src/liballoc/tests/linked_list.rs | 75 +++++------ src/liballoc/tests/rc.rs | 41 +++--- src/liballoc/tests/vec_deque.rs | 166 ++++++++++++------------ 21 files changed, 373 insertions(+), 401 deletions(-) (limited to 'src/liballoc/tests') diff --git a/src/liballoc/alloc/tests.rs b/src/liballoc/alloc/tests.rs index c69f4e49ee1..956298d7836 100644 --- a/src/liballoc/alloc/tests.rs +++ b/src/liballoc/alloc/tests.rs @@ -1,15 +1,15 @@ use super::*; extern crate test; -use test::Bencher; use crate::boxed::Box; +use test::Bencher; #[test] fn allocate_zeroed() { unsafe { let layout = Layout::from_size_align(1024, 1).unwrap(); - let ptr = Global.alloc_zeroed(layout.clone()) - .unwrap_or_else(|_| handle_alloc_error(layout)); + let ptr = + Global.alloc_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout)); let mut i = ptr.cast::().as_ptr(); let end = i.add(layout.size()); diff --git a/src/liballoc/benches/btree/map.rs b/src/liballoc/benches/btree/map.rs index b541fa94e95..eb5f51d9adc 100644 --- a/src/liballoc/benches/btree/map.rs +++ b/src/liballoc/benches/btree/map.rs @@ -1,12 +1,12 @@ +use std::collections::BTreeMap; use std::iter::Iterator; use std::vec::Vec; -use std::collections::BTreeMap; -use rand::{Rng, seq::SliceRandom, thread_rng}; -use test::{Bencher, black_box}; +use rand::{seq::SliceRandom, thread_rng, Rng}; +use test::{black_box, Bencher}; macro_rules! map_insert_rand_bench { - ($name: ident, $n: expr, $map: ident) => ( + ($name: ident, $n: expr, $map: ident) => { #[bench] pub fn $name(b: &mut Bencher) { let n: usize = $n; @@ -27,11 +27,11 @@ macro_rules! map_insert_rand_bench { }); black_box(map); } - ) + }; } macro_rules! map_insert_seq_bench { - ($name: ident, $n: expr, $map: ident) => ( + ($name: ident, $n: expr, $map: ident) => { #[bench] pub fn $name(b: &mut Bencher) { let mut map = $map::new(); @@ -50,11 +50,11 @@ macro_rules! map_insert_seq_bench { }); black_box(map); } - ) + }; } macro_rules! map_find_rand_bench { - ($name: ident, $n: expr, $map: ident) => ( + ($name: ident, $n: expr, $map: ident) => { #[bench] pub fn $name(b: &mut Bencher) { let mut map = $map::new(); @@ -78,11 +78,11 @@ macro_rules! map_find_rand_bench { black_box(t); }) } - ) + }; } macro_rules! map_find_seq_bench { - ($name: ident, $n: expr, $map: ident) => ( + ($name: ident, $n: expr, $map: ident) => { #[bench] pub fn $name(b: &mut Bencher) { let mut map = $map::new(); @@ -101,20 +101,20 @@ macro_rules! map_find_seq_bench { black_box(x); }) } - ) + }; } -map_insert_rand_bench!{insert_rand_100, 100, BTreeMap} -map_insert_rand_bench!{insert_rand_10_000, 10_000, BTreeMap} +map_insert_rand_bench! {insert_rand_100, 100, BTreeMap} +map_insert_rand_bench! {insert_rand_10_000, 10_000, BTreeMap} -map_insert_seq_bench!{insert_seq_100, 100, BTreeMap} -map_insert_seq_bench!{insert_seq_10_000, 10_000, BTreeMap} +map_insert_seq_bench! {insert_seq_100, 100, BTreeMap} +map_insert_seq_bench! {insert_seq_10_000, 10_000, BTreeMap} -map_find_rand_bench!{find_rand_100, 100, BTreeMap} -map_find_rand_bench!{find_rand_10_000, 10_000, BTreeMap} +map_find_rand_bench! {find_rand_100, 100, BTreeMap} +map_find_rand_bench! {find_rand_10_000, 10_000, BTreeMap} -map_find_seq_bench!{find_seq_100, 100, BTreeMap} -map_find_seq_bench!{find_seq_10_000, 10_000, BTreeMap} +map_find_seq_bench! {find_seq_100, 100, BTreeMap} +map_find_seq_bench! {find_seq_10_000, 10_000, BTreeMap} fn bench_iter(b: &mut Bencher, size: i32) { let mut map = BTreeMap::::new(); diff --git a/src/liballoc/benches/slice.rs b/src/liballoc/benches/slice.rs index ef91d801dc7..e20c043286e 100644 --- a/src/liballoc/benches/slice.rs +++ b/src/liballoc/benches/slice.rs @@ -1,9 +1,9 @@ use std::{mem, ptr}; +use rand::distributions::{Alphanumeric, Standard}; use rand::{thread_rng, Rng, SeedableRng}; -use rand::distributions::{Standard, Alphanumeric}; use rand_xorshift::XorShiftRng; -use test::{Bencher, black_box}; +use test::{black_box, Bencher}; #[bench] fn iterator(b: &mut Bencher) { @@ -239,7 +239,7 @@ macro_rules! sort { b.iter(|| v.clone().$f()); b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64; } - } + }; } macro_rules! sort_strings { @@ -251,7 +251,7 @@ macro_rules! sort_strings { b.iter(|| v.clone().$f()); b.bytes = $len * mem::size_of::<&str>() as u64; } - } + }; } macro_rules! sort_expensive { @@ -273,7 +273,7 @@ macro_rules! sort_expensive { }); b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64; } - } + }; } macro_rules! sort_lexicographic { @@ -284,7 +284,7 @@ macro_rules! sort_lexicographic { b.iter(|| v.clone().$f(|x| x.to_string())); b.bytes = $len * mem::size_of_val(&$gen(1)[0]) as u64; } - } + }; } sort!(sort, sort_small_ascending, gen_ascending, 10); @@ -325,24 +325,25 @@ macro_rules! reverse { fn $name(b: &mut Bencher) { // odd length and offset by 1 to be as unaligned as possible let n = 0xFFFFF; - let mut v: Vec<_> = - (0..1+(n / mem::size_of::<$ty>() as u64)) - .map($f) - .collect(); + let mut v: Vec<_> = (0..1 + (n / mem::size_of::<$ty>() as u64)).map($f).collect(); b.iter(|| black_box(&mut v[1..]).reverse()); b.bytes = n; } - } + }; } reverse!(reverse_u8, u8, |x| x as u8); reverse!(reverse_u16, u16, |x| x as u16); -reverse!(reverse_u8x3, [u8;3], |x| [x as u8, (x>>8) as u8, (x>>16) as u8]); +reverse!(reverse_u8x3, [u8; 3], |x| [x as u8, (x >> 8) as u8, (x >> 16) as u8]); reverse!(reverse_u32, u32, |x| x as u32); reverse!(reverse_u64, u64, |x| x as u64); reverse!(reverse_u128, u128, |x| x as u128); -#[repr(simd)] struct F64x4(f64, f64, f64, f64); -reverse!(reverse_simd_f64x4, F64x4, |x| { let x = x as f64; F64x4(x,x,x,x) }); +#[repr(simd)] +struct F64x4(f64, f64, f64, f64); +reverse!(reverse_simd_f64x4, F64x4, |x| { + let x = x as f64; + F64x4(x, x, x, x) +}); macro_rules! rotate { ($name:ident, $gen:expr, $len:expr, $mid:expr) => { @@ -350,32 +351,32 @@ macro_rules! rotate { fn $name(b: &mut Bencher) { let size = mem::size_of_val(&$gen(1)[0]); let mut v = $gen($len * 8 / size); - b.iter(|| black_box(&mut v).rotate_left(($mid*8+size-1)/size)); + b.iter(|| black_box(&mut v).rotate_left(($mid * 8 + size - 1) / size)); b.bytes = (v.len() * size) as u64; } - } + }; } rotate!(rotate_tiny_by1, gen_random, 16, 1); -rotate!(rotate_tiny_half, gen_random, 16, 16/2); -rotate!(rotate_tiny_half_plus_one, gen_random, 16, 16/2+1); +rotate!(rotate_tiny_half, gen_random, 16, 16 / 2); +rotate!(rotate_tiny_half_plus_one, gen_random, 16, 16 / 2 + 1); rotate!(rotate_medium_by1, gen_random, 9158, 1); rotate!(rotate_medium_by727_u64, gen_random, 9158, 727); rotate!(rotate_medium_by727_bytes, gen_random_bytes, 9158, 727); rotate!(rotate_medium_by727_strings, gen_strings, 9158, 727); -rotate!(rotate_medium_half, gen_random, 9158, 9158/2); -rotate!(rotate_medium_half_plus_one, gen_random, 9158, 9158/2+1); +rotate!(rotate_medium_half, gen_random, 9158, 9158 / 2); +rotate!(rotate_medium_half_plus_one, gen_random, 9158, 9158 / 2 + 1); // Intended to use more RAM than the machine has cache -rotate!(rotate_huge_by1, gen_random, 5*1024*1024, 1); -rotate!(rotate_huge_by9199_u64, gen_random, 5*1024*1024, 9199); -rotate!(rotate_huge_by9199_bytes, gen_random_bytes, 5*1024*1024, 9199); -rotate!(rotate_huge_by9199_strings, gen_strings, 5*1024*1024, 9199); -rotate!(rotate_huge_by9199_big, gen_big_random, 5*1024*1024, 9199); -rotate!(rotate_huge_by1234577_u64, gen_random, 5*1024*1024, 1234577); -rotate!(rotate_huge_by1234577_bytes, gen_random_bytes, 5*1024*1024, 1234577); -rotate!(rotate_huge_by1234577_strings, gen_strings, 5*1024*1024, 1234577); -rotate!(rotate_huge_by1234577_big, gen_big_random, 5*1024*1024, 1234577); -rotate!(rotate_huge_half, gen_random, 5*1024*1024, 5*1024*1024/2); -rotate!(rotate_huge_half_plus_one, gen_random, 5*1024*1024, 5*1024*1024/2+1); +rotate!(rotate_huge_by1, gen_random, 5 * 1024 * 1024, 1); +rotate!(rotate_huge_by9199_u64, gen_random, 5 * 1024 * 1024, 9199); +rotate!(rotate_huge_by9199_bytes, gen_random_bytes, 5 * 1024 * 1024, 9199); +rotate!(rotate_huge_by9199_strings, gen_strings, 5 * 1024 * 1024, 9199); +rotate!(rotate_huge_by9199_big, gen_big_random, 5 * 1024 * 1024, 9199); +rotate!(rotate_huge_by1234577_u64, gen_random, 5 * 1024 * 1024, 1234577); +rotate!(rotate_huge_by1234577_bytes, gen_random_bytes, 5 * 1024 * 1024, 1234577); +rotate!(rotate_huge_by1234577_strings, gen_strings, 5 * 1024 * 1024, 1234577); +rotate!(rotate_huge_by1234577_big, gen_big_random, 5 * 1024 * 1024, 1234577); +rotate!(rotate_huge_half, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2); +rotate!(rotate_huge_half_plus_one, gen_random, 5 * 1024 * 1024, 5 * 1024 * 1024 / 2 + 1); diff --git a/src/liballoc/benches/str.rs b/src/liballoc/benches/str.rs index 7f8661bd968..391475bc0c7 100644 --- a/src/liballoc/benches/str.rs +++ b/src/liballoc/benches/str.rs @@ -1,4 +1,4 @@ -use test::{Bencher, black_box}; +use test::{black_box, Bencher}; #[bench] fn char_iterator(b: &mut Bencher) { @@ -12,7 +12,9 @@ fn char_iterator_for(b: &mut Bencher) { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; b.iter(|| { - for ch in s.chars() { black_box(ch); } + for ch in s.chars() { + black_box(ch); + } }); } @@ -40,7 +42,9 @@ fn char_iterator_rev_for(b: &mut Bencher) { let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb"; b.iter(|| { - for ch in s.chars().rev() { black_box(ch); } + for ch in s.chars().rev() { + black_box(ch); + } }); } @@ -79,7 +83,9 @@ fn split_ascii(b: &mut Bencher) { fn split_extern_fn(b: &mut Bencher) { let s = "Mary had a little lamb, Little lamb, little-lamb."; let len = s.split(' ').count(); - fn pred(c: char) -> bool { c == ' ' } + fn pred(c: char) -> bool { + c == ' ' + } b.iter(|| assert_eq!(s.split(pred).count(), len)); } @@ -185,16 +191,19 @@ fn bench_contains_equal(b: &mut Bencher) { }) } - macro_rules! make_test_inner { ($s:ident, $code:expr, $name:ident, $str:expr, $iters:expr) => { #[bench] fn $name(bencher: &mut Bencher) { let mut $s = $str; black_box(&mut $s); - bencher.iter(|| for _ in 0..$iters { black_box($code); }); + bencher.iter(|| { + for _ in 0..$iters { + black_box($code); + } + }); } - } + }; } macro_rules! make_test { @@ -261,15 +270,9 @@ make_test!(match_indices_a_str, s, s.match_indices("a").count()); make_test!(split_a_str, s, s.split("a").count()); -make_test!(trim_ascii_char, s, { - s.trim_matches(|c: char| c.is_ascii()) -}); -make_test!(trim_start_ascii_char, s, { - s.trim_start_matches(|c: char| c.is_ascii()) -}); -make_test!(trim_end_ascii_char, s, { - s.trim_end_matches(|c: char| c.is_ascii()) -}); +make_test!(trim_ascii_char, s, { s.trim_matches(|c: char| c.is_ascii()) }); +make_test!(trim_start_ascii_char, s, { s.trim_start_matches(|c: char| c.is_ascii()) }); +make_test!(trim_end_ascii_char, s, { s.trim_end_matches(|c: char| c.is_ascii()) }); make_test!(find_underscore_char, s, s.find('_')); make_test!(rfind_underscore_char, s, s.rfind('_')); diff --git a/src/liballoc/benches/vec_deque.rs b/src/liballoc/benches/vec_deque.rs index 7d2d3cfa612..bf2dffd1e93 100644 --- a/src/liballoc/benches/vec_deque.rs +++ b/src/liballoc/benches/vec_deque.rs @@ -1,5 +1,5 @@ use std::collections::VecDeque; -use test::{Bencher, black_box}; +use test::{black_box, Bencher}; #[bench] fn bench_new(b: &mut Bencher) { diff --git a/src/liballoc/benches/vec_deque_append.rs b/src/liballoc/benches/vec_deque_append.rs index 78ec91d9e3e..5825bdc355f 100644 --- a/src/liballoc/benches/vec_deque_append.rs +++ b/src/liballoc/benches/vec_deque_append.rs @@ -30,8 +30,5 @@ fn main() { assert!(BENCH_N % 2 == 0); let median = (durations[(l / 2) - 1] + durations[l / 2]) / 2; - println!( - "\ncustom-bench vec_deque_append {:?} ns/iter\n", - median.as_nanos() - ); + println!("\ncustom-bench vec_deque_append {:?} ns/iter\n", median.as_nanos()); } diff --git a/src/liballoc/collections/btree/mod.rs b/src/liballoc/collections/btree/mod.rs index 8b7dc07063b..f73a24d0991 100644 --- a/src/liballoc/collections/btree/mod.rs +++ b/src/liballoc/collections/btree/mod.rs @@ -1,6 +1,6 @@ +pub mod map; mod node; mod search; -pub mod map; pub mod set; #[doc(hidden)] diff --git a/src/liballoc/collections/btree/search.rs b/src/liballoc/collections/btree/search.rs index dfb67d2ea57..3f3c49a2ef8 100644 --- a/src/liballoc/collections/btree/search.rs +++ b/src/liballoc/collections/btree/search.rs @@ -1,21 +1,23 @@ use core::borrow::Borrow; use core::cmp::Ordering; -use super::node::{Handle, NodeRef, marker, ForceResult::*}; +use super::node::{marker, ForceResult::*, Handle, NodeRef}; use SearchResult::*; pub enum SearchResult { Found(Handle, marker::KV>), - GoDown(Handle, marker::Edge>) + GoDown(Handle, marker::Edge>), } pub fn search_tree( mut node: NodeRef, - key: &Q + key: &Q, ) -> SearchResult - where Q: Ord, K: Borrow { - +where + Q: Ord, + K: Borrow, +{ loop { match search_node(node, key) { Found(handle) => return Found(handle), @@ -25,38 +27,38 @@ pub fn search_tree( node = internal.descend(); continue; } - } + }, } } } pub fn search_node( node: NodeRef, - key: &Q + key: &Q, ) -> SearchResult - where Q: Ord, K: Borrow { - +where + Q: Ord, + K: Borrow, +{ match search_linear(&node, key) { - (idx, true) => Found( - Handle::new_kv(node, idx) - ), - (idx, false) => SearchResult::GoDown( - Handle::new_edge(node, idx) - ) + (idx, true) => Found(Handle::new_kv(node, idx)), + (idx, false) => SearchResult::GoDown(Handle::new_edge(node, idx)), } } pub fn search_linear( node: &NodeRef, - key: &Q + key: &Q, ) -> (usize, bool) - where Q: Ord, K: Borrow { - +where + Q: Ord, + K: Borrow, +{ for (i, k) in node.keys().iter().enumerate() { match key.cmp(k.borrow()) { - Ordering::Greater => {}, + Ordering::Greater => {} Ordering::Equal => return (i, true), - Ordering::Less => return (i, false) + Ordering::Less => return (i, false), } } (node.keys().len(), false) diff --git a/src/liballoc/collections/linked_list/tests.rs b/src/liballoc/collections/linked_list/tests.rs index 1001f6bba3b..94b92df1294 100644 --- a/src/liballoc/collections/linked_list/tests.rs +++ b/src/liballoc/collections/linked_list/tests.rs @@ -177,8 +177,7 @@ fn test_insert_prev() { } check_links(&m); assert_eq!(m.len(), 3 + len * 2); - assert_eq!(m.into_iter().collect::>(), - [-2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1]); + assert_eq!(m.into_iter().collect::>(), [-2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1]); } #[test] @@ -187,13 +186,13 @@ fn test_insert_prev() { fn test_send() { let n = list_from(&[1, 2, 3]); thread::spawn(move || { - check_links(&n); - let a: &[_] = &[&1, &2, &3]; - assert_eq!(a, &*n.iter().collect::>()); - }) - .join() - .ok() - .unwrap(); + check_links(&n); + let a: &[_] = &[&1, &2, &3]; + assert_eq!(a, &*n.iter().collect::>()); + }) + .join() + .ok() + .unwrap(); } #[test] diff --git a/src/liballoc/collections/vec_deque/tests.rs b/src/liballoc/collections/vec_deque/tests.rs index 09009ff516a..8dc097cc088 100644 --- a/src/liballoc/collections/vec_deque/tests.rs +++ b/src/liballoc/collections/vec_deque/tests.rs @@ -66,11 +66,8 @@ fn test_swap_front_back_remove() { let final_len = usable_cap / 2; for len in 0..final_len { - let expected: VecDeque<_> = if back { - (0..len).collect() - } else { - (0..len).rev().collect() - }; + let expected: VecDeque<_> = + if back { (0..len).collect() } else { (0..len).rev().collect() }; for tail_pos in 0..usable_cap { tester.tail = tail_pos; tester.head = tail_pos; @@ -111,7 +108,6 @@ fn test_insert() { // this test isn't covering what it wants to let cap = tester.capacity(); - // len is the length *after* insertion for len in 1..cap { // 0, 1, 2, .., len - 1 @@ -198,9 +194,7 @@ fn test_drain() { assert!(tester.head < tester.cap()); // We should see the correct values in the VecDeque - let expected: VecDeque<_> = (0..drain_start) - .chain(drain_end..len) - .collect(); + let expected: VecDeque<_> = (0..drain_start).chain(drain_end..len).collect(); assert_eq!(expected, tester); } } diff --git a/src/liballoc/fmt.rs b/src/liballoc/fmt.rs index cbfc55233a1..18ebae33309 100644 --- a/src/liballoc/fmt.rs +++ b/src/liballoc/fmt.rs @@ -516,24 +516,24 @@ #[unstable(feature = "fmt_internals", issue = "0")] pub use core::fmt::rt; +#[stable(feature = "fmt_flags_align", since = "1.28.0")] +pub use core::fmt::Alignment; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::fmt::{Formatter, Result, Write}; +pub use core::fmt::Error; +#[stable(feature = "rust1", since = "1.0.0")] +pub use core::fmt::{write, ArgumentV1, Arguments}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::fmt::{Binary, Octal}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::fmt::{Debug, Display}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::fmt::{LowerHex, Pointer, UpperHex}; -#[stable(feature = "rust1", since = "1.0.0")] -pub use core::fmt::{LowerExp, UpperExp}; +pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::fmt::Error; +pub use core::fmt::{Formatter, Result, Write}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::fmt::{write, ArgumentV1, Arguments}; +pub use core::fmt::{LowerExp, UpperExp}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple}; -#[stable(feature = "fmt_flags_align", since = "1.28.0")] -pub use core::fmt::{Alignment}; +pub use core::fmt::{LowerHex, Pointer, UpperHex}; use crate::string; @@ -568,8 +568,6 @@ use crate::string; pub fn format(args: Arguments<'_>) -> string::String { let capacity = args.estimated_capacity(); let mut output = string::String::with_capacity(capacity); - output - .write_fmt(args) - .expect("a formatting trait implementation returned an error"); + output.write_fmt(args).expect("a formatting trait implementation returned an error"); output } diff --git a/src/liballoc/prelude/v1.rs b/src/liballoc/prelude/v1.rs index 3cb285bf049..6a53b4ca1f6 100644 --- a/src/liballoc/prelude/v1.rs +++ b/src/liballoc/prelude/v1.rs @@ -4,7 +4,11 @@ #![unstable(feature = "alloc_prelude", issue = "58935")] -#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::borrow::ToOwned; -#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::boxed::Box; -#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::string::{String, ToString}; -#[unstable(feature = "alloc_prelude", issue = "58935")] pub use crate::vec::Vec; +#[unstable(feature = "alloc_prelude", issue = "58935")] +pub use crate::borrow::ToOwned; +#[unstable(feature = "alloc_prelude", issue = "58935")] +pub use crate::boxed::Box; +#[unstable(feature = "alloc_prelude", issue = "58935")] +pub use crate::string::{String, ToString}; +#[unstable(feature = "alloc_prelude", issue = "58935")] +pub use crate::vec::Vec; diff --git a/src/liballoc/raw_vec/tests.rs b/src/liballoc/raw_vec/tests.rs index d35b62fc1ef..b214cef3011 100644 --- a/src/liballoc/raw_vec/tests.rs +++ b/src/liballoc/raw_vec/tests.rs @@ -16,7 +16,9 @@ fn allocator_param() { // A dumb allocator that consumes a fixed amount of fuel // before allocation attempts start failing. - struct BoundedAlloc { fuel: usize } + struct BoundedAlloc { + fuel: usize, + } unsafe impl Alloc for BoundedAlloc { unsafe fn alloc(&mut self, layout: Layout) -> Result, AllocErr> { let size = layout.size(); @@ -24,7 +26,10 @@ fn allocator_param() { return Err(AllocErr); } match Global.alloc(layout) { - ok @ Ok(_) => { self.fuel -= size; ok } + ok @ Ok(_) => { + self.fuel -= size; + ok + } err @ Err(_) => err, } } diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 08243ef7c51..2f6d10c027b 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -82,7 +82,6 @@ //! [`.chunks`]: ../../std/primitive.slice.html#method.chunks //! [`.windows`]: ../../std/primitive.slice.html#method.windows #![stable(feature = "rust1", since = "1.0.0")] - // Many of the usings in this module are only used in the test configuration. // It's cleaner to just turn off the unused_imports warning than to fix them. #![cfg_attr(test, allow(unused_imports, dead_code))] @@ -91,32 +90,32 @@ use core::borrow::{Borrow, BorrowMut}; use core::cmp::Ordering::{self, Less}; use core::mem::{self, size_of}; use core::ptr; -use core::{u8, u16, u32}; +use core::{u16, u32, u8}; use crate::borrow::ToOwned; use crate::boxed::Box; use crate::vec::Vec; +#[stable(feature = "slice_get_slice", since = "1.28.0")] +pub use core::slice::SliceIndex; +#[stable(feature = "from_ref", since = "1.28.0")] +pub use core::slice::{from_mut, from_ref}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::slice::{Chunks, Windows}; +pub use core::slice::{from_raw_parts, from_raw_parts_mut}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::slice::{Iter, IterMut}; +pub use core::slice::{Chunks, Windows}; +#[stable(feature = "chunks_exact", since = "1.31.0")] +pub use core::slice::{ChunksExact, ChunksExactMut}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::slice::{SplitMut, ChunksMut, Split}; +pub use core::slice::{ChunksMut, Split, SplitMut}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::slice::{SplitN, RSplitN, SplitNMut, RSplitNMut}; +pub use core::slice::{Iter, IterMut}; +#[stable(feature = "rchunks", since = "1.31.0")] +pub use core::slice::{RChunks, RChunksExact, RChunksExactMut, RChunksMut}; #[stable(feature = "slice_rsplit", since = "1.27.0")] pub use core::slice::{RSplit, RSplitMut}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::slice::{from_raw_parts, from_raw_parts_mut}; -#[stable(feature = "from_ref", since = "1.28.0")] -pub use core::slice::{from_ref, from_mut}; -#[stable(feature = "slice_get_slice", since = "1.28.0")] -pub use core::slice::SliceIndex; -#[stable(feature = "chunks_exact", since = "1.31.0")] -pub use core::slice::{ChunksExact, ChunksExactMut}; -#[stable(feature = "rchunks", since = "1.31.0")] -pub use core::slice::{RChunks, RChunksMut, RChunksExact, RChunksExactMut}; +pub use core::slice::{RSplitN, RSplitNMut, SplitN, SplitNMut}; //////////////////////////////////////////////////////////////////////////////// // Basic slice extension methods @@ -138,9 +137,9 @@ pub use hack::to_vec; // `test_permutations` test mod hack { use crate::boxed::Box; - use crate::vec::Vec; #[cfg(test)] use crate::string::ToString; + use crate::vec::Vec; pub fn into_vec(b: Box<[T]>) -> Vec { unsafe { @@ -153,7 +152,8 @@ mod hack { #[inline] pub fn to_vec(s: &[T]) -> Vec - where T: Clone + where + T: Clone, { let mut vector = Vec::with_capacity(s.len()); vector.extend_from_slice(s); @@ -193,7 +193,8 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sort(&mut self) - where T: Ord + where + T: Ord, { merge_sort(self, |a, b| a.lt(b)); } @@ -246,7 +247,8 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sort_by(&mut self, mut compare: F) - where F: FnMut(&T, &T) -> Ordering + where + F: FnMut(&T, &T) -> Ordering, { merge_sort(self, |a, b| compare(a, b) == Less); } @@ -285,7 +287,9 @@ impl [T] { #[stable(feature = "slice_sort_by_key", since = "1.7.0")] #[inline] pub fn sort_by_key(&mut self, mut f: F) - where F: FnMut(&T) -> K, K: Ord + where + F: FnMut(&T) -> K, + K: Ord, { merge_sort(self, |a, b| f(a).lt(&f(b))); } @@ -325,11 +329,13 @@ impl [T] { #[stable(feature = "slice_sort_by_cached_key", since = "1.34.0")] #[inline] pub fn sort_by_cached_key(&mut self, f: F) - where F: FnMut(&T) -> K, K: Ord + where + F: FnMut(&T) -> K, + K: Ord, { // Helper macro for indexing our vector by the smallest possible type, to reduce allocation. macro_rules! sort_by_key { - ($t:ty, $slice:ident, $f:ident) => ({ + ($t:ty, $slice:ident, $f:ident) => {{ let mut indices: Vec<_> = $slice.iter().map($f).enumerate().map(|(i, k)| (k, i as $t)).collect(); // The elements of `indices` are unique, as they are indexed, so any sort will be @@ -344,19 +350,27 @@ impl [T] { indices[i].1 = index; $slice.swap(i, index as usize); } - }) + }}; } - let sz_u8 = mem::size_of::<(K, u8)>(); - let sz_u16 = mem::size_of::<(K, u16)>(); - let sz_u32 = mem::size_of::<(K, u32)>(); + let sz_u8 = mem::size_of::<(K, u8)>(); + let sz_u16 = mem::size_of::<(K, u16)>(); + let sz_u32 = mem::size_of::<(K, u32)>(); let sz_usize = mem::size_of::<(K, usize)>(); let len = self.len(); - if len < 2 { return } - if sz_u8 < sz_u16 && len <= ( u8::MAX as usize) { return sort_by_key!( u8, self, f) } - if sz_u16 < sz_u32 && len <= (u16::MAX as usize) { return sort_by_key!(u16, self, f) } - if sz_u32 < sz_usize && len <= (u32::MAX as usize) { return sort_by_key!(u32, self, f) } + if len < 2 { + return; + } + if sz_u8 < sz_u16 && len <= (u8::MAX as usize) { + return sort_by_key!(u8, self, f); + } + if sz_u16 < sz_u32 && len <= (u16::MAX as usize) { + return sort_by_key!(u16, self, f); + } + if sz_u32 < sz_usize && len <= (u32::MAX as usize) { + return sort_by_key!(u32, self, f); + } sort_by_key!(usize, self, f) } @@ -373,7 +387,8 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn to_vec(&self) -> Vec - where T: Clone + where + T: Clone, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self) @@ -421,7 +436,10 @@ impl [T] { /// b"0123456789abcdef".repeat(usize::max_value()); /// ``` #[stable(feature = "repeat_generic_slice", since = "1.40.0")] - pub fn repeat(&self, n: usize) -> Vec where T: Copy { + pub fn repeat(&self, n: usize) -> Vec + where + T: Copy, + { if n == 0 { return Vec::new(); } @@ -486,7 +504,8 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn concat(&self) -> >::Output - where Self: Concat + where + Self: Concat, { Concat::concat(self) } @@ -503,7 +522,8 @@ impl [T] { /// ``` #[stable(feature = "rename_connect_to_join", since = "1.3.0")] pub fn join(&self, sep: Separator) -> >::Output - where Self: Join + where + Self: Join, { Join::join(self, sep) } @@ -521,11 +541,11 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(since = "1.3.0", reason = "renamed to join")] pub fn connect(&self, sep: Separator) -> >::Output - where Self: Join + where + Self: Join, { Join::join(self, sep) } - } #[lang = "slice_u8_alloc"] @@ -668,8 +688,8 @@ impl> Join<&[T]> for [V] { Some(first) => first, None => return vec![], }; - let size = slice.iter().map(|v| v.borrow().len()).sum::() + - sep.len() * (slice.len() - 1); + let size = + slice.iter().map(|v| v.borrow().len()).sum::() + sep.len() * (slice.len() - 1); let mut result = Vec::with_capacity(size); result.extend_from_slice(first.borrow()); @@ -734,7 +754,8 @@ impl ToOwned for [T] { /// /// This is the integral subroutine of insertion sort. fn insert_head(v: &mut [T], is_less: &mut F) - where F: FnMut(&T, &T) -> bool +where + F: FnMut(&T, &T) -> bool, { if v.len() >= 2 && is_less(&v[1], &v[0]) { unsafe { @@ -767,10 +788,7 @@ fn insert_head(v: &mut [T], is_less: &mut F) // If `is_less` panics at any point during the process, `hole` will get dropped and // fill the hole in `v` with `tmp`, thus ensuring that `v` still holds every object it // initially held exactly once. - let mut hole = InsertionHole { - src: &mut *tmp, - dest: &mut v[1], - }; + let mut hole = InsertionHole { src: &mut *tmp, dest: &mut v[1] }; ptr::copy_nonoverlapping(&v[1], &mut v[0], 1); for i in 2..v.len() { @@ -792,7 +810,9 @@ fn insert_head(v: &mut [T], is_less: &mut F) impl Drop for InsertionHole { fn drop(&mut self) { - unsafe { ptr::copy_nonoverlapping(self.src, self.dest, 1); } + unsafe { + ptr::copy_nonoverlapping(self.src, self.dest, 1); + } } } } @@ -805,7 +825,8 @@ fn insert_head(v: &mut [T], is_less: &mut F) /// The two slices must be non-empty and `mid` must be in bounds. Buffer `buf` must be long enough /// to hold a copy of the shorter slice. Also, `T` must not be a zero-sized type. unsafe fn merge(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F) - where F: FnMut(&T, &T) -> bool +where + F: FnMut(&T, &T) -> bool, { let len = v.len(); let v = v.as_mut_ptr(); @@ -834,11 +855,7 @@ unsafe fn merge(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F) if mid <= len - mid { // The left run is shorter. ptr::copy_nonoverlapping(v, buf, mid); - hole = MergeHole { - start: buf, - end: buf.add(mid), - dest: v, - }; + hole = MergeHole { start: buf, end: buf.add(mid), dest: v }; // Initially, these pointers point to the beginnings of their arrays. let left = &mut hole.start; @@ -858,11 +875,7 @@ unsafe fn merge(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F) } else { // The right run is shorter. ptr::copy_nonoverlapping(v_mid, buf, len - mid); - hole = MergeHole { - start: buf, - end: buf.add(len - mid), - dest: v_mid, - }; + hole = MergeHole { start: buf, end: buf.add(len - mid), dest: v_mid }; // Initially, these pointers point past the ends of their arrays. let left = &mut hole.dest; @@ -905,7 +918,9 @@ unsafe fn merge(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F) fn drop(&mut self) { // `T` is not a zero-sized type, so it's okay to divide by its size. let len = (self.end as usize - self.start as usize) / mem::size_of::(); - unsafe { ptr::copy_nonoverlapping(self.start, self.dest, len); } + unsafe { + ptr::copy_nonoverlapping(self.start, self.dest, len); + } } } } @@ -923,7 +938,8 @@ unsafe fn merge(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F) /// /// The invariants ensure that the total running time is `O(n log n)` worst-case. fn merge_sort(v: &mut [T], mut is_less: F) - where F: FnMut(&T, &T) -> bool +where + F: FnMut(&T, &T) -> bool, { // Slices of up to this length get sorted using insertion sort. const MAX_INSERTION: usize = 20; @@ -940,7 +956,7 @@ fn merge_sort(v: &mut [T], mut is_less: F) // Short arrays get sorted in-place via insertion sort to avoid allocations. if len <= MAX_INSERTION { if len >= 2 { - for i in (0..len-1).rev() { + for i in (0..len - 1).rev() { insert_head(&mut v[i..], &mut is_less); } } @@ -966,14 +982,13 @@ fn merge_sort(v: &mut [T], mut is_less: F) start -= 1; unsafe { if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) { - while start > 0 && is_less(v.get_unchecked(start), - v.get_unchecked(start - 1)) { + while start > 0 && is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) { start -= 1; } v[start..end].reverse(); } else { - while start > 0 && !is_less(v.get_unchecked(start), - v.get_unchecked(start - 1)) { + while start > 0 && !is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) + { start -= 1; } } @@ -988,10 +1003,7 @@ fn merge_sort(v: &mut [T], mut is_less: F) } // Push this run onto the stack. - runs.push(Run { - start, - len: end - start, - }); + runs.push(Run { start, len: end - start }); end = start; // Merge some pairs of adjacent runs to satisfy the invariants. @@ -999,13 +1011,14 @@ fn merge_sort(v: &mut [T], mut is_less: F) let left = runs[r + 1]; let right = runs[r]; unsafe { - merge(&mut v[left.start .. right.start + right.len], left.len, buf.as_mut_ptr(), - &mut is_less); + merge( + &mut v[left.start..right.start + right.len], + left.len, + buf.as_mut_ptr(), + &mut is_less, + ); } - runs[r] = Run { - start: left.start, - len: left.len + right.len, - }; + runs[r] = Run { start: left.start, len: left.len + right.len }; runs.remove(r + 1); } } @@ -1030,15 +1043,13 @@ fn merge_sort(v: &mut [T], mut is_less: F) #[inline] fn collapse(runs: &[Run]) -> Option { let n = runs.len(); - if n >= 2 && (runs[n - 1].start == 0 || - runs[n - 2].len <= runs[n - 1].len || - (n >= 3 && runs[n - 3].len <= runs[n - 2].len + runs[n - 1].len) || - (n >= 4 && runs[n - 4].len <= runs[n - 3].len + runs[n - 2].len)) { - if n >= 3 && runs[n - 3].len < runs[n - 1].len { - Some(n - 3) - } else { - Some(n - 2) - } + if n >= 2 + && (runs[n - 1].start == 0 + || runs[n - 2].len <= runs[n - 1].len + || (n >= 3 && runs[n - 3].len <= runs[n - 2].len + runs[n - 1].len) + || (n >= 4 && runs[n - 4].len <= runs[n - 3].len + runs[n - 2].len)) + { + if n >= 3 && runs[n - 3].len < runs[n - 1].len { Some(n - 3) } else { Some(n - 2) } } else { None } diff --git a/src/liballoc/tests.rs b/src/liballoc/tests.rs index ed46ba8a1b9..1b6e0bb291c 100644 --- a/src/liballoc/tests.rs +++ b/src/liballoc/tests.rs @@ -1,12 +1,12 @@ //! Test for `boxed` mod. use core::any::Any; -use core::convert::TryInto; -use core::ops::Deref; -use core::result::Result::{Err, Ok}; use core::clone::Clone; +use core::convert::TryInto; use core::f64; use core::i64; +use core::ops::Deref; +use core::result::Result::{Err, Ok}; use std::boxed::Box; diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index cf2ad2a8e60..2fbb59b0419 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -1,9 +1,9 @@ use std::any::Any; -use std::sync::{Arc, Weak}; use std::cell::RefCell; use std::cmp::PartialEq; use std::iter::TrustedLen; use std::mem; +use std::sync::{Arc, Weak}; #[test] fn uninhabited() { @@ -12,7 +12,7 @@ fn uninhabited() { a = a.clone(); assert!(a.upgrade().is_none()); - let mut a: Weak = a; // Unsizing + let mut a: Weak = a; // Unsizing a = a.clone(); assert!(a.upgrade().is_none()); } @@ -20,8 +20,8 @@ fn uninhabited() { #[test] fn slice() { let a: Arc<[u32; 3]> = Arc::new([3, 2, 1]); - let a: Arc<[u32]> = a; // Unsizing - let b: Arc<[u32]> = Arc::from(&[3, 2, 1][..]); // Conversion + let a: Arc<[u32]> = a; // Unsizing + let b: Arc<[u32]> = Arc::from(&[3, 2, 1][..]); // Conversion assert_eq!(a, b); // Exercise is_dangling() with a DST @@ -33,7 +33,7 @@ fn slice() { #[test] fn trait_object() { let a: Arc = Arc::new(4); - let a: Arc = a; // Unsizing + let a: Arc = a; // Unsizing // Exercise is_dangling() with a DST let mut a = Arc::downgrade(&a); @@ -43,7 +43,7 @@ fn trait_object() { let mut b = Weak::::new(); b = b.clone(); assert!(b.upgrade().is_none()); - let mut b: Weak = b; // Unsizing + let mut b: Weak = b; // Unsizing b = b.clone(); assert!(b.upgrade().is_none()); } @@ -57,7 +57,7 @@ fn float_nan_ne() { #[test] fn partial_eq() { - struct TestPEq (RefCell); + struct TestPEq(RefCell); impl PartialEq for TestPEq { fn eq(&self, other: &TestPEq) -> bool { *self.0.borrow_mut() += 1; @@ -74,7 +74,7 @@ fn partial_eq() { #[test] fn eq() { #[derive(Eq)] - struct TestEq (RefCell); + struct TestEq(RefCell); impl PartialEq for TestEq { fn eq(&self, other: &TestEq) -> bool { *self.0.borrow_mut() += 1; @@ -160,13 +160,10 @@ fn shared_from_iter_trustedlen_normal() { fn shared_from_iter_trustedlen_panic() { // Exercise the `TrustedLen` implementation when `size_hint()` matches // `(_, Some(exact_len))` but where `.next()` drops before the last iteration. - let iter = (0..SHARED_ITER_MAX) - .map(|val| { - match val { - 98 => panic!("I've almost got 99 problems."), - _ => Box::new(val), - } - }); + let iter = (0..SHARED_ITER_MAX).map(|val| match val { + 98 => panic!("I've almost got 99 problems."), + _ => Box::new(val), + }); assert_trusted_len(&iter); let _ = iter.collect::>(); @@ -193,16 +190,8 @@ fn shared_from_iter_trustedlen_no_fuse() { } } - let vec = vec![ - Some(Box::new(42)), - Some(Box::new(24)), - None, - Some(Box::new(12)), - ]; + let vec = vec![Some(Box::new(42)), Some(Box::new(24)), None, Some(Box::new(12))]; let iter = Iter(vec.into_iter()); assert_trusted_len(&iter); - assert_eq!( - &[Box::new(42), Box::new(24)], - &*iter.collect::>() - ); + assert_eq!(&[Box::new(42), Box::new(24)], &*iter.collect::>()); } diff --git a/src/liballoc/tests/boxed.rs b/src/liballoc/tests/boxed.rs index bc3d53bf30d..66782ecbeb7 100644 --- a/src/liballoc/tests/boxed.rs +++ b/src/liballoc/tests/boxed.rs @@ -1,5 +1,5 @@ -use std::ptr::NonNull; use std::mem::MaybeUninit; +use std::ptr::NonNull; #[test] fn unitialized_zero_size_box() { diff --git a/src/liballoc/tests/btree/mod.rs b/src/liballoc/tests/btree/mod.rs index 4c704d0f8c2..1d08ae13e05 100644 --- a/src/liballoc/tests/btree/mod.rs +++ b/src/liballoc/tests/btree/mod.rs @@ -11,12 +11,7 @@ struct DeterministicRng { impl DeterministicRng { fn new() -> Self { - DeterministicRng { - x: 0x193a6754, - y: 0xa8a7d469, - z: 0x97830e05, - w: 0x113ba7bb, - } + DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb } } fn next(&mut self) -> u32 { diff --git a/src/liballoc/tests/linked_list.rs b/src/liballoc/tests/linked_list.rs index 8a26454c389..daa49c48c6a 100644 --- a/src/liballoc/tests/linked_list.rs +++ b/src/liballoc/tests/linked_list.rs @@ -102,7 +102,6 @@ fn test_split_off() { assert_eq!(m.back(), Some(&1)); assert_eq!(m.front(), Some(&1)); } - } #[test] @@ -305,8 +304,7 @@ fn test_show() { assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let list: LinkedList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect(); - assert_eq!(format!("{:?}", list), - "[\"just\", \"one\", \"test\", \"more\"]"); + assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]"); } #[test] @@ -446,19 +444,14 @@ fn drain_filter_true() { #[test] fn drain_filter_complex() { - - { // [+xxx++++++xxxxx++++x+x++] + { + // [+xxx++++++xxxxx++++x+x++] let mut list = vec![ - 1, - 2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36, - 37, 39 - ].into_iter().collect::>(); + 1, 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, + 39, + ] + .into_iter() + .collect::>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -471,17 +464,13 @@ fn drain_filter_complex() { ); } - { // [xxx++++++xxxxx++++x+x++] + { + // [xxx++++++xxxxx++++x+x++] let mut list = vec![ - 2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36, - 37, 39 - ].into_iter().collect::>(); + 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 39, + ] + .into_iter() + .collect::>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -494,16 +483,12 @@ fn drain_filter_complex() { ); } - { // [xxx++++++xxxxx++++x+x] - let mut list = vec![ - 2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36 - ].into_iter().collect::>(); + { + // [xxx++++++xxxxx++++x+x] + let mut list = + vec![2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36] + .into_iter() + .collect::>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -516,11 +501,11 @@ fn drain_filter_complex() { ); } - { // [xxxxxxxxxx+++++++++++] - let mut list = vec![ - 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, - 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 - ].into_iter().collect::>(); + { + // [xxxxxxxxxx+++++++++++] + let mut list = vec![2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19] + .into_iter() + .collect::>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); @@ -530,11 +515,11 @@ fn drain_filter_complex() { assert_eq!(list.into_iter().collect::>(), vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19]); } - { // [+++++++++++xxxxxxxxxx] - let mut list = vec![ - 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, - 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 - ].into_iter().collect::>(); + { + // [+++++++++++xxxxxxxxxx] + let mut list = vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20] + .into_iter() + .collect::>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::>(); assert_eq!(removed.len(), 10); diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index 7854ca0fc16..e77c57d9a5a 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -1,9 +1,9 @@ use std::any::Any; -use std::rc::{Rc, Weak}; use std::cell::RefCell; use std::cmp::PartialEq; -use std::mem; use std::iter::TrustedLen; +use std::mem; +use std::rc::{Rc, Weak}; #[test] fn uninhabited() { @@ -12,7 +12,7 @@ fn uninhabited() { a = a.clone(); assert!(a.upgrade().is_none()); - let mut a: Weak = a; // Unsizing + let mut a: Weak = a; // Unsizing a = a.clone(); assert!(a.upgrade().is_none()); } @@ -20,8 +20,8 @@ fn uninhabited() { #[test] fn slice() { let a: Rc<[u32; 3]> = Rc::new([3, 2, 1]); - let a: Rc<[u32]> = a; // Unsizing - let b: Rc<[u32]> = Rc::from(&[3, 2, 1][..]); // Conversion + let a: Rc<[u32]> = a; // Unsizing + let b: Rc<[u32]> = Rc::from(&[3, 2, 1][..]); // Conversion assert_eq!(a, b); // Exercise is_dangling() with a DST @@ -33,7 +33,7 @@ fn slice() { #[test] fn trait_object() { let a: Rc = Rc::new(4); - let a: Rc = a; // Unsizing + let a: Rc = a; // Unsizing // Exercise is_dangling() with a DST let mut a = Rc::downgrade(&a); @@ -43,7 +43,7 @@ fn trait_object() { let mut b = Weak::::new(); b = b.clone(); assert!(b.upgrade().is_none()); - let mut b: Weak = b; // Unsizing + let mut b: Weak = b; // Unsizing b = b.clone(); assert!(b.upgrade().is_none()); } @@ -57,7 +57,7 @@ fn float_nan_ne() { #[test] fn partial_eq() { - struct TestPEq (RefCell); + struct TestPEq(RefCell); impl PartialEq for TestPEq { fn eq(&self, other: &TestPEq) -> bool { *self.0.borrow_mut() += 1; @@ -74,7 +74,7 @@ fn partial_eq() { #[test] fn eq() { #[derive(Eq)] - struct TestEq (RefCell); + struct TestEq(RefCell); impl PartialEq for TestEq { fn eq(&self, other: &TestEq) -> bool { *self.0.borrow_mut() += 1; @@ -156,13 +156,10 @@ fn shared_from_iter_trustedlen_normal() { fn shared_from_iter_trustedlen_panic() { // Exercise the `TrustedLen` implementation when `size_hint()` matches // `(_, Some(exact_len))` but where `.next()` drops before the last iteration. - let iter = (0..SHARED_ITER_MAX) - .map(|val| { - match val { - 98 => panic!("I've almost got 99 problems."), - _ => Box::new(val), - } - }); + let iter = (0..SHARED_ITER_MAX).map(|val| match val { + 98 => panic!("I've almost got 99 problems."), + _ => Box::new(val), + }); assert_trusted_len(&iter); let _ = iter.collect::>(); @@ -189,16 +186,8 @@ fn shared_from_iter_trustedlen_no_fuse() { } } - let vec = vec![ - Some(Box::new(42)), - Some(Box::new(24)), - None, - Some(Box::new(12)), - ]; + let vec = vec![Some(Box::new(42)), Some(Box::new(24)), None, Some(Box::new(12))]; let iter = Iter(vec.into_iter()); assert_trusted_len(&iter); - assert_eq!( - &[Box::new(42), Box::new(24)], - &*iter.collect::>() - ); + assert_eq!(&[Box::new(42), Box::new(24)], &*iter.collect::>()); } diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index d49b553fc02..5a0162a5361 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -1,8 +1,8 @@ -use std::fmt::Debug; -use std::collections::{VecDeque, vec_deque::Drain}; use std::collections::TryReserveError::*; +use std::collections::{vec_deque::Drain, VecDeque}; +use std::fmt::Debug; use std::mem::size_of; -use std::{usize, isize}; +use std::{isize, usize}; use crate::hash; @@ -148,34 +148,20 @@ fn test_param_taggy() { #[test] fn test_param_taggypar() { - test_parameterized::>(Onepar::(1), - Twopar::(1, 2), - Threepar::(1, 2, 3), - Twopar::(17, 42)); + test_parameterized::>( + Onepar::(1), + Twopar::(1, 2), + Threepar::(1, 2, 3), + Twopar::(17, 42), + ); } #[test] fn test_param_reccy() { - let reccy1 = RecCy { - x: 1, - y: 2, - t: One(1), - }; - let reccy2 = RecCy { - x: 345, - y: 2, - t: Two(1, 2), - }; - let reccy3 = RecCy { - x: 1, - y: 777, - t: Three(1, 2, 3), - }; - let reccy4 = RecCy { - x: 19, - y: 252, - t: Two(17, 42), - }; + let reccy1 = RecCy { x: 1, y: 2, t: One(1) }; + let reccy2 = RecCy { x: 345, y: 2, t: Two(1, 2) }; + let reccy3 = RecCy { x: 1, y: 777, t: Three(1, 2, 3) }; + let reccy4 = RecCy { x: 19, y: 252, t: Two(17, 42) }; test_parameterized::(reccy1, reccy2, reccy3, reccy4); } @@ -320,8 +306,7 @@ fn test_mut_rev_iter_wrap() { assert_eq!(d.pop_front(), Some(1)); d.push_back(4); - assert_eq!(d.iter_mut().rev().map(|x| *x).collect::>(), - vec![4, 3, 2]); + assert_eq!(d.iter_mut().rev().map(|x| *x).collect::>(), vec![4, 3, 2]); } #[test] @@ -372,7 +357,6 @@ fn test_mut_rev_iter() { #[test] fn test_into_iter() { - // Empty iter { let d: VecDeque = VecDeque::new(); @@ -431,7 +415,6 @@ fn test_into_iter() { #[test] fn test_drain() { - // Empty iter { let mut d: VecDeque = VecDeque::new(); @@ -650,12 +633,8 @@ fn test_show() { let ringbuf: VecDeque<_> = (0..10).collect(); assert_eq!(format!("{:?}", ringbuf), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); - let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"] - .iter() - .cloned() - .collect(); - assert_eq!(format!("{:?}", ringbuf), - "[\"just\", \"one\", \"test\", \"more\"]"); + let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"].iter().cloned().collect(); + assert_eq!(format!("{:?}", ringbuf), "[\"just\", \"one\", \"test\", \"more\"]"); } #[test] @@ -955,7 +934,6 @@ fn test_append_permutations() { // doesn't pop more values than are pushed for src_pop_back in 0..(src_push_back + src_push_front) { for src_pop_front in 0..(src_push_back + src_push_front - src_pop_back) { - let src = construct_vec_deque( src_push_back, src_pop_back, @@ -966,8 +944,8 @@ fn test_append_permutations() { for dst_push_back in 0..MAX { for dst_push_front in 0..MAX { for dst_pop_back in 0..(dst_push_back + dst_push_front) { - for dst_pop_front - in 0..(dst_push_back + dst_push_front - dst_pop_back) + for dst_pop_front in + 0..(dst_push_back + dst_push_front - dst_pop_back) { let mut dst = construct_vec_deque( dst_push_back, @@ -1124,7 +1102,6 @@ fn test_reserve_exact_2() { #[test] #[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve() { - // These are the interesting cases: // * exactly isize::MAX should never trigger a CapacityOverflow (can be OOM) // * > isize::MAX should always fail @@ -1158,22 +1135,27 @@ fn test_try_reserve() { if guards_against_isize { // Check isize::MAX + 1 does count as overflow if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_CAP + 1) { - } else { panic!("isize::MAX + 1 should trigger an overflow!") } + } else { + panic!("isize::MAX + 1 should trigger an overflow!") + } // Check usize::MAX does count as overflow if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } else { // Check isize::MAX is an OOM // VecDeque starts with capacity 7, always adds 1 to the capacity // and also rounds the number to next power of 2 so this is the // furthest we can go without triggering CapacityOverflow if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_CAP) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } } - { // Same basic idea, but with non-zero len let mut ten_bytes: VecDeque = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); @@ -1186,33 +1168,42 @@ fn test_try_reserve() { } if guards_against_isize { if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { if let Err(AllocError { .. }) = ten_bytes.try_reserve(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } // Should always overflow in the add-to-len if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } - { // Same basic idea, but with interesting type size let mut ten_u32s: VecDeque = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); - if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } - if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } if guards_against_isize { - if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { - if let Err(AllocError { .. }) = ten_u32s.try_reserve(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + if let Err(AllocError { .. }) = ten_u32s.try_reserve(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } // Should fail in the mul-by-size if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_USIZE - 20) { @@ -1220,13 +1211,11 @@ fn test_try_reserve() { panic!("usize::MAX should trigger an overflow!"); } } - } #[test] #[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve_exact() { - // This is exactly the same as test_try_reserve with the method changed. // See that test for comments. @@ -1247,21 +1236,26 @@ fn test_try_reserve_exact() { if guards_against_isize { if let Err(CapacityOverflow) = empty_bytes.try_reserve_exact(MAX_CAP + 1) { - } else { panic!("isize::MAX + 1 should trigger an overflow!") } + } else { + panic!("isize::MAX + 1 should trigger an overflow!") + } if let Err(CapacityOverflow) = empty_bytes.try_reserve_exact(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } else { // Check isize::MAX is an OOM // VecDeque starts with capacity 7, always adds 1 to the capacity // and also rounds the number to next power of 2 so this is the // furthest we can go without triggering CapacityOverflow if let Err(AllocError { .. }) = empty_bytes.try_reserve_exact(MAX_CAP) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } } - { let mut ten_bytes: VecDeque = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); @@ -1273,36 +1267,46 @@ fn test_try_reserve_exact() { } if guards_against_isize { if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { if let Err(AllocError { .. }) = ten_bytes.try_reserve_exact(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } - { let mut ten_u32s: VecDeque = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); - if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } - if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } if guards_against_isize { - if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { - if let Err(AllocError { .. }) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + if let Err(AllocError { .. }) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_USIZE - 20) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } - } #[test] @@ -1404,9 +1408,8 @@ fn test_rotate_right_parts() { #[test] fn test_rotate_left_random() { let shifts = [ - 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, - 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, - 9, 4, 12, 3, 12, 9, 11, 1, 7, 9, 7, 2, + 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, 9, 4, 12, 3, + 12, 9, 11, 1, 7, 9, 7, 2, ]; let n = 12; let mut v: VecDeque<_> = (0..n).collect(); @@ -1423,9 +1426,8 @@ fn test_rotate_left_random() { #[test] fn test_rotate_right_random() { let shifts = [ - 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, - 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, - 9, 4, 12, 3, 12, 9, 11, 1, 7, 9, 7, 2, + 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, 9, 4, 12, 3, + 12, 9, 11, 1, 7, 9, 7, 2, ]; let n = 12; let mut v: VecDeque<_> = (0..n).collect(); @@ -1447,8 +1449,7 @@ fn test_try_fold_empty() { #[test] fn test_try_fold_none() { let v: VecDeque = (0..12).collect(); - assert_eq!(None, v.into_iter().try_fold(0, |a, b| - if b < 11 { Some(a + b) } else { None })); + assert_eq!(None, v.into_iter().try_fold(0, |a, b| if b < 11 { Some(a + b) } else { None })); } #[test] @@ -1463,7 +1464,6 @@ fn test_try_fold_unit() { assert_eq!(Some(()), v.into_iter().try_fold((), |(), ()| Some(()))); } - #[test] fn test_try_fold_unit_none() { let v: std::collections::VecDeque<()> = [(); 10].iter().cloned().collect(); @@ -1534,7 +1534,7 @@ fn test_try_rfold_rotated() { #[test] fn test_try_rfold_moves_iter() { - let v : VecDeque<_> = [10, 20, 30, 40, 100, 60, 70, 80, 90].iter().collect(); + let v: VecDeque<_> = [10, 20, 30, 40, 100, 60, 70, 80, 90].iter().collect(); let mut iter = v.into_iter(); assert_eq!(iter.try_rfold(0_i8, |acc, &x| acc.checked_add(x)), None); assert_eq!(iter.next_back(), Some(&70)); -- cgit 1.4.1-3-g733a5