From 83a8ad70026509ca88a84d10fc4247648671d264 Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Sun, 2 Oct 2022 11:54:03 +0200 Subject: [PATCH] Fixed warning and errors while running `unstable-strict-oom-checks` --- tests/alloc.rs | 26 +++++++++++++++++++++----- tests/basic_types.rs | 1 - 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/alloc.rs b/tests/alloc.rs index 08c07bb0..afb6419b 100644 --- a/tests/alloc.rs +++ b/tests/alloc.rs @@ -6,12 +6,19 @@ extern crate alloc; mod utils; use alloc::borrow::Cow; +#[cfg(not(feature = "unstable-strict-oom-checks"))] use alloc::collections::*; -#[cfg(not(feature = "serde"))] +#[cfg(all(not(feature = "serde"), not(feature = "unstable-strict-oom-checks")))] use alloc::rc::Rc; -#[cfg(all(target_has_atomic = "ptr", not(feature = "serde")))] +#[cfg(all( + target_has_atomic = "ptr", + not(feature = "serde"), + not(feature = "unstable-strict-oom-checks") +))] use alloc::sync::Arc; -use utils::{the_same, the_same_with_comparer}; +use utils::the_same; +#[cfg(not(feature = "unstable-strict-oom-checks"))] +use utils::the_same_with_comparer; struct Foo { pub a: u32, @@ -85,7 +92,7 @@ fn test_alloc_commons() { the_same(Box::<[u32]>::from(vec![1, 2, 3, 4, 5])); the_same(Cow::::Owned(5)); the_same(Cow::::Borrowed(&5)); - #[cfg(not(feature = "serde"))] + #[cfg(all(not(feature = "serde"), not(feature = "unstable-strict-oom-checks")))] { // Serde doesn't support Rc or Arc the_same(Rc::::new(5)); @@ -98,6 +105,7 @@ fn test_alloc_commons() { } } + #[cfg(not(feature = "unstable-strict-oom-checks"))] the_same_with_comparer( { let mut map = BinaryHeap::::new(); @@ -110,16 +118,19 @@ fn test_alloc_commons() { }, |a, b| a.iter().collect::>() == b.iter().collect::>(), ); + #[cfg(not(feature = "unstable-strict-oom-checks"))] the_same({ let mut map = BTreeMap::::new(); map.insert(5, -5); map }); + #[cfg(not(feature = "unstable-strict-oom-checks"))] the_same({ let mut set = BTreeSet::::new(); set.insert(5); set }); + #[cfg(not(feature = "unstable-strict-oom-checks"))] the_same({ let mut set = VecDeque::::new(); set.push_back(15); @@ -161,9 +172,13 @@ fn test_container_limits() { } for slice in test_cases { + #[cfg(not(feature = "unstable-strict-oom-checks"))] validate_fail::>(slice); + #[cfg(not(feature = "unstable-strict-oom-checks"))] validate_fail::>(slice); + #[cfg(not(feature = "unstable-strict-oom-checks"))] validate_fail::>(slice); + #[cfg(not(feature = "unstable-strict-oom-checks"))] validate_fail::>(slice); validate_fail::>(slice); validate_fail::(slice); @@ -175,7 +190,7 @@ fn test_container_limits() { } } -#[cfg(target_has_atomic = "ptr")] +#[cfg(all(target_has_atomic = "ptr", not(feature = "unstable-strict-oom-checks")))] #[test] fn test_arc_str() { use alloc::sync::Arc; @@ -188,6 +203,7 @@ fn test_arc_str() { let start: Arc = Arc::clone(&start); bincode::encode_into_slice(start, &mut target, config).unwrap() }; + let slice = &target[..len]; let decoded: Arc = bincode::borrow_decode_from_slice(slice, config).unwrap().0; diff --git a/tests/basic_types.rs b/tests/basic_types.rs index f63416e6..8ef4ce2e 100644 --- a/tests/basic_types.rs +++ b/tests/basic_types.rs @@ -24,7 +24,6 @@ fn test_numbers() { the_same(5i128); the_same(5isize); - println!("Test {:?}", 5.0f32); the_same_with_comparer(5.0f32, |a, b| (a - b).abs() <= f32::EPSILON); the_same_with_comparer(5.0f64, |a, b| (a - b).abs() <= f64::EPSILON);