summaryrefslogtreecommitdiffstats
path: root/library/core/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /library/core/tests
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/tests')
-rw-r--r--library/core/tests/asserting.rs6
-rw-r--r--library/core/tests/atomic.rs2
-rw-r--r--library/core/tests/bool.rs2
-rw-r--r--library/core/tests/cell.rs2
-rw-r--r--library/core/tests/char.rs2
-rw-r--r--library/core/tests/clone.rs1
-rw-r--r--library/core/tests/cmp.rs6
-rw-r--r--library/core/tests/convert.rs2
-rw-r--r--library/core/tests/hash/mod.rs24
-rw-r--r--library/core/tests/hash/sip.rs4
-rw-r--r--library/core/tests/lazy.rs4
-rw-r--r--library/core/tests/lib.rs6
-rw-r--r--library/core/tests/mem.rs210
-rw-r--r--library/core/tests/nonzero.rs20
-rw-r--r--library/core/tests/num/const_from.rs2
-rw-r--r--library/core/tests/num/ieee754.rs1
-rw-r--r--library/core/tests/num/int_macros.rs26
-rw-r--r--library/core/tests/num/mod.rs58
-rw-r--r--library/core/tests/num/uint_macros.rs26
-rw-r--r--library/core/tests/option.rs24
-rw-r--r--library/core/tests/time.rs12
21 files changed, 404 insertions, 36 deletions
diff --git a/library/core/tests/asserting.rs b/library/core/tests/asserting.rs
index 4b626ba6f..1d9670886 100644
--- a/library/core/tests/asserting.rs
+++ b/library/core/tests/asserting.rs
@@ -24,7 +24,7 @@ struct NoCopyNoDebug;
struct NoDebug;
test!(
- capture_with_non_copyable_and_non_debugabble_elem_has_correct_params,
+ capture_with_non_copyable_and_non_debuggable_elem_has_correct_params,
NoCopyNoDebug,
None,
"N/A"
@@ -32,6 +32,6 @@ test!(
test!(capture_with_non_copyable_elem_has_correct_params, NoCopy, None, "N/A");
-test!(capture_with_non_debugabble_elem_has_correct_params, NoDebug, None, "N/A");
+test!(capture_with_non_debuggable_elem_has_correct_params, NoDebug, None, "N/A");
-test!(capture_with_copyable_and_debugabble_elem_has_correct_params, 1i32, Some(1i32), "1");
+test!(capture_with_copyable_and_debuggable_elem_has_correct_params, 1i32, Some(1i32), "1");
diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs
index 94b031060..a67a842d3 100644
--- a/library/core/tests/atomic.rs
+++ b/library/core/tests/atomic.rs
@@ -306,9 +306,11 @@ fn atomic_compare_exchange() {
ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
}
+/* FIXME(#110395)
#[test]
fn atomic_const_from() {
const _ATOMIC_U8: AtomicU8 = AtomicU8::from(1);
const _ATOMIC_BOOL: AtomicBool = AtomicBool::from(true);
const _ATOMIC_PTR: AtomicPtr<u32> = AtomicPtr::from(core::ptr::null_mut());
}
+*/
diff --git a/library/core/tests/bool.rs b/library/core/tests/bool.rs
index 4819ce911..47f645991 100644
--- a/library/core/tests/bool.rs
+++ b/library/core/tests/bool.rs
@@ -89,6 +89,7 @@ fn test_bool_to_option() {
assert_eq!(false.then(|| 0), None);
assert_eq!(true.then(|| 0), Some(0));
+ /* FIXME(#110395)
const fn zero() -> i32 {
0
}
@@ -102,4 +103,5 @@ fn test_bool_to_option() {
assert_eq!(B, Some(0));
assert_eq!(C, None);
assert_eq!(D, Some(0));
+ */
}
diff --git a/library/core/tests/cell.rs b/library/core/tests/cell.rs
index 7b77b2134..e084f8679 100644
--- a/library/core/tests/cell.rs
+++ b/library/core/tests/cell.rs
@@ -468,6 +468,7 @@ fn const_cells() {
const CELL: Cell<i32> = Cell::new(3);
const _: i32 = CELL.into_inner();
+/* FIXME(#110395)
const UNSAFE_CELL_FROM: UnsafeCell<i32> = UnsafeCell::from(3);
const _: i32 = UNSAFE_CELL.into_inner();
@@ -476,4 +477,5 @@ fn const_cells() {
const CELL_FROM: Cell<i32> = Cell::from(3);
const _: i32 = CELL.into_inner();
+*/
}
diff --git a/library/core/tests/char.rs b/library/core/tests/char.rs
index ac0b2ca16..85ba51c92 100644
--- a/library/core/tests/char.rs
+++ b/library/core/tests/char.rs
@@ -21,6 +21,7 @@ fn test_convert() {
assert!(char::try_from(0xFFFF_FFFF_u32).is_err());
}
+/* FIXME(#110395)
#[test]
const fn test_convert_const() {
assert!(u32::from('a') == 0x61);
@@ -30,6 +31,7 @@ const fn test_convert_const() {
assert!(char::from(b'a') == 'a');
assert!(char::from(b'\xFF') == '\u{FF}');
}
+*/
#[test]
fn test_from_str() {
diff --git a/library/core/tests/clone.rs b/library/core/tests/clone.rs
index 33ca9f2c6..aafe5ced2 100644
--- a/library/core/tests/clone.rs
+++ b/library/core/tests/clone.rs
@@ -1,4 +1,5 @@
#[test]
+#[cfg_attr(not(bootstrap), allow(suspicious_double_ref_op))]
fn test_borrowed_clone() {
let x = 5;
let y: &i32 = &x;
diff --git a/library/core/tests/cmp.rs b/library/core/tests/cmp.rs
index 8d0e59d5a..72fdd490d 100644
--- a/library/core/tests/cmp.rs
+++ b/library/core/tests/cmp.rs
@@ -217,18 +217,19 @@ fn cmp_default() {
assert_eq!(Fool(false), Fool(true));
}
+/* FIXME(#110395)
mod const_cmp {
use super::*;
struct S(i32);
- impl const PartialEq for S {
+ impl PartialEq for S {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
- impl const PartialOrd for S {
+ impl PartialOrd for S {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let ret = match (self.0, other.0) {
(a, b) if a > b => Ordering::Greater,
@@ -248,3 +249,4 @@ mod const_cmp {
const _: () = assert!(S(0) < S(1));
const _: () = assert!(S(1) > S(0));
}
+*/
diff --git a/library/core/tests/convert.rs b/library/core/tests/convert.rs
index f1048f4cf..f76dd2778 100644
--- a/library/core/tests/convert.rs
+++ b/library/core/tests/convert.rs
@@ -1,3 +1,4 @@
+/* FIXME(#110395)
#[test]
fn convert() {
const fn from(x: i32) -> i32 {
@@ -14,3 +15,4 @@ fn convert() {
const BAR: Vec<String> = into(Vec::new());
assert_eq!(BAR, Vec::<String>::new());
}
+*/
diff --git a/library/core/tests/hash/mod.rs b/library/core/tests/hash/mod.rs
index 267245f05..033bd1ed6 100644
--- a/library/core/tests/hash/mod.rs
+++ b/library/core/tests/hash/mod.rs
@@ -9,13 +9,13 @@ struct MyHasher {
hash: u64,
}
-impl const Default for MyHasher {
+impl Default for MyHasher {
fn default() -> MyHasher {
MyHasher { hash: 0 }
}
}
-impl const Hasher for MyHasher {
+impl Hasher for MyHasher {
fn write(&mut self, buf: &[u8]) {
// FIXME(const_trait_impl): change to for loop
let mut i = 0;
@@ -35,13 +35,14 @@ impl const Hasher for MyHasher {
#[test]
fn test_writer_hasher() {
- const fn hash<T: ~const Hash>(t: &T) -> u64 {
+ // FIXME(#110395)
+ /* const */ fn hash<T: Hash>(t: &T) -> u64 {
let mut s = MyHasher { hash: 0 };
t.hash(&mut s);
s.finish()
}
- const {
+ /* const {
// FIXME(fee1-dead): assert_eq
assert!(hash(&()) == 0);
assert!(hash(&5_u8) == 5);
@@ -52,7 +53,7 @@ fn test_writer_hasher() {
let s: &str = "a";
assert!(hash(&s) == 97 + 0xFF);
- };
+ }; */
assert_eq!(hash(&()), 0);
@@ -113,7 +114,7 @@ struct CustomHasher {
output: u64,
}
-impl const Hasher for CustomHasher {
+impl Hasher for CustomHasher {
fn finish(&self) -> u64 {
self.output
}
@@ -125,21 +126,22 @@ impl const Hasher for CustomHasher {
}
}
-impl const Default for CustomHasher {
+impl Default for CustomHasher {
fn default() -> CustomHasher {
CustomHasher { output: 0 }
}
}
-impl const Hash for Custom {
- fn hash<H: ~const Hasher>(&self, state: &mut H) {
+impl Hash for Custom {
+ fn hash<H: Hasher>(&self, state: &mut H) {
state.write_u64(self.hash);
}
}
#[test]
fn test_custom_state() {
- const fn hash<T: ~const Hash>(t: &T) -> u64 {
+ // FIXME(#110395)
+ /* const */ fn hash<T: Hash>(t: &T) -> u64 {
let mut c = CustomHasher { output: 0 };
t.hash(&mut c);
c.finish()
@@ -147,7 +149,7 @@ fn test_custom_state() {
assert_eq!(hash(&Custom { hash: 5 }), 5);
- const { assert!(hash(&Custom { hash: 6 }) == 6) };
+ // const { assert!(hash(&Custom { hash: 6 }) == 6) };
}
// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
diff --git a/library/core/tests/hash/sip.rs b/library/core/tests/hash/sip.rs
index 3abf6efcf..0a67c485c 100644
--- a/library/core/tests/hash/sip.rs
+++ b/library/core/tests/hash/sip.rs
@@ -23,12 +23,13 @@ fn hash<T: Hash>(x: &T) -> u64 {
hash_with(SipHasher::new(), x)
}
+/* FIXME(#110395)
#[test]
const fn test_const_sip() {
let val1 = 0x45;
let val2 = 0xfeed;
- const fn const_hash<T: ~const Hash>(x: &T) -> u64 {
+ const fn const_hash<T: Hash>(x: &T) -> u64 {
let mut st = SipHasher::new();
x.hash(&mut st);
st.finish()
@@ -36,6 +37,7 @@ const fn test_const_sip() {
assert!(const_hash(&(val1)) != const_hash(&(val2)));
}
+*/
#[test]
#[allow(unused_must_use)]
diff --git a/library/core/tests/lazy.rs b/library/core/tests/lazy.rs
index c7c3c479b..7f7f1f005 100644
--- a/library/core/tests/lazy.rs
+++ b/library/core/tests/lazy.rs
@@ -10,7 +10,7 @@ fn once_cell() {
c.get_or_init(|| 92);
assert_eq!(c.get(), Some(&92));
- c.get_or_init(|| panic!("Kabom!"));
+ c.get_or_init(|| panic!("Kaboom!"));
assert_eq!(c.get(), Some(&92));
}
@@ -46,11 +46,13 @@ fn unsync_once_cell_drop_empty() {
drop(x);
}
+/* FIXME(#110395)
#[test]
const fn once_cell_const() {
let _once_cell: OnceCell<u32> = OnceCell::new();
let _once_cell: OnceCell<u32> = OnceCell::from(32);
}
+*/
#[test]
fn clone() {
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 6cdafa411..3933e3289 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -8,20 +8,16 @@
#![feature(const_assume)]
#![feature(const_align_of_val_raw)]
#![feature(const_black_box)]
-#![feature(const_bool_to_option)]
#![feature(const_caller_location)]
#![feature(const_cell_into_inner)]
-#![feature(const_convert)]
#![feature(const_hash)]
#![feature(const_heap)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_maybe_uninit_assume_init_read)]
#![feature(const_nonnull_new)]
-#![feature(const_num_from_num)]
#![feature(const_pointer_byte_offsets)]
#![feature(const_pointer_is_aligned)]
#![feature(const_ptr_as_ref)]
-#![feature(const_ptr_read)]
#![feature(const_ptr_write)]
#![feature(const_trait_impl)]
#![feature(const_likely)]
@@ -57,6 +53,7 @@
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(min_specialization)]
#![feature(numfmt)]
+#![feature(num_midpoint)]
#![feature(step_trait)]
#![feature(str_internals)]
#![feature(std_internals)]
@@ -112,6 +109,7 @@
#![feature(utf8_chunks)]
#![feature(is_ascii_octdigit)]
#![feature(get_many_mut)]
+#![cfg_attr(not(bootstrap), feature(offset_of))]
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(fuzzy_provenance_casts)]
diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs
index f7740a114..aee9c89b5 100644
--- a/library/core/tests/mem.rs
+++ b/library/core/tests/mem.rs
@@ -364,3 +364,213 @@ fn const_maybe_uninit() {
assert_eq!(FIELD_BY_FIELD, Foo { x: 1, y: 2 });
}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of() {
+ #[repr(C)]
+ struct Foo {
+ x: u8,
+ y: u16,
+ z: Bar,
+ }
+
+ #[repr(C)]
+ struct Bar(u8, u8);
+
+ assert_eq!(offset_of!(Foo, x), 0);
+ assert_eq!(offset_of!(Foo, y), 2);
+ assert_eq!(offset_of!(Foo, z.0), 4);
+ assert_eq!(offset_of!(Foo, z.1), 5);
+
+ // Layout of tuples is unstable
+ assert!(offset_of!((u8, u16), 0) <= size_of::<(u8, u16)>() - 1);
+ assert!(offset_of!((u8, u16), 1) <= size_of::<(u8, u16)>() - 2);
+
+ #[repr(C)]
+ struct Generic<T> {
+ x: u8,
+ y: u32,
+ z: T
+ }
+
+ trait Trait {}
+
+ // Ensure that this type of generics works
+ fn offs_of_z<T>() -> usize {
+ offset_of!(Generic<T>, z)
+ }
+
+ assert_eq!(offset_of!(Generic<u8>, z), 8);
+ assert_eq!(offs_of_z::<u8>(), 8);
+
+ // Ensure that it works with the implicit lifetime in `Box<dyn Trait + '_>`.
+ assert_eq!(offset_of!(Generic<Box<dyn Trait>>, z), 8);
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of_union() {
+ #[repr(C)]
+ union Foo {
+ x: u8,
+ y: u16,
+ z: Bar,
+ }
+
+ #[repr(C)]
+ #[derive(Copy, Clone)]
+ struct Bar(u8, u8);
+
+ assert_eq!(offset_of!(Foo, x), 0);
+ assert_eq!(offset_of!(Foo, y), 0);
+ assert_eq!(offset_of!(Foo, z.0), 0);
+ assert_eq!(offset_of!(Foo, z.1), 1);
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of_dst() {
+ #[repr(C)]
+ struct Alpha {
+ x: u8,
+ y: u16,
+ z: [u8],
+ }
+
+ trait Trait {}
+
+ #[repr(C)]
+ struct Beta {
+ x: u8,
+ y: u16,
+ z: dyn Trait,
+ }
+
+ extern "C" {
+ type Extern;
+ }
+
+ #[repr(C)]
+ struct Gamma {
+ x: u8,
+ y: u16,
+ z: Extern,
+ }
+
+ assert_eq!(offset_of!(Alpha, x), 0);
+ assert_eq!(offset_of!(Alpha, y), 2);
+
+ assert_eq!(offset_of!(Beta, x), 0);
+ assert_eq!(offset_of!(Beta, y), 2);
+
+ assert_eq!(offset_of!(Gamma, x), 0);
+ assert_eq!(offset_of!(Gamma, y), 2);
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of_packed() {
+ #[repr(C, packed)]
+ struct Foo {
+ x: u8,
+ y: u16,
+ }
+
+ assert_eq!(offset_of!(Foo, x), 0);
+ assert_eq!(offset_of!(Foo, y), 1);
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of_projection() {
+ #[repr(C)]
+ struct Foo {
+ x: u8,
+ y: u16,
+ }
+
+ trait Projector {
+ type Type;
+ }
+
+ impl Projector for () {
+ type Type = Foo;
+ }
+
+ assert_eq!(offset_of!(<() as Projector>::Type, x), 0);
+ assert_eq!(offset_of!(<() as Projector>::Type, y), 2);
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of_alias() {
+ #[repr(C)]
+ struct Foo {
+ x: u8,
+ y: u16,
+ }
+
+ type Bar = Foo;
+
+ assert_eq!(offset_of!(Bar, x), 0);
+ assert_eq!(offset_of!(Bar, y), 2);
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn const_offset_of() {
+ #[repr(C)]
+ struct Foo {
+ x: u8,
+ y: u16,
+ }
+
+ const X_OFFSET: usize = offset_of!(Foo, x);
+ const Y_OFFSET: usize = offset_of!(Foo, y);
+
+ assert_eq!(X_OFFSET, 0);
+ assert_eq!(Y_OFFSET, 2);
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of_without_const_promotion() {
+ #[repr(C)]
+ struct Foo<SuppressConstPromotion> {
+ x: u8,
+ y: u16,
+ _scp: SuppressConstPromotion,
+ }
+
+ // Normally, offset_of is always const promoted.
+ // The generic parameter prevents this from happening.
+ // This is needed to test the codegen impl of offset_of
+ fn inner<SuppressConstPromotion>() {
+ assert_eq!(offset_of!(Foo<SuppressConstPromotion>, x), 0);
+ assert_eq!(offset_of!(Foo<SuppressConstPromotion>, y), 2);
+ }
+
+ inner::<()>();
+}
+
+#[test]
+#[cfg(not(bootstrap))]
+fn offset_of_addr() {
+ #[repr(C)]
+ struct Foo {
+ x: u8,
+ y: u16,
+ z: Bar,
+ }
+
+ #[repr(C)]
+ struct Bar(u8, u8);
+
+ let base = Foo { x: 0, y: 0, z: Bar(0, 0) };
+
+ assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, x), ptr::addr_of!(base.x).addr());
+ assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, y), ptr::addr_of!(base.y).addr());
+ assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, z.0), ptr::addr_of!(base.z.0).addr());
+ assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, z.1), ptr::addr_of!(base.z.1).addr());
+}
diff --git a/library/core/tests/nonzero.rs b/library/core/tests/nonzero.rs
index a0ca919a8..007f84425 100644
--- a/library/core/tests/nonzero.rs
+++ b/library/core/tests/nonzero.rs
@@ -215,11 +215,13 @@ fn nonzero_const() {
const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
assert!(ONE.is_some());
+ /* FIXME(#110395)
const FROM_NONZERO_U8: u8 = u8::from(NONZERO_U8);
assert_eq!(FROM_NONZERO_U8, 5);
const NONZERO_CONVERT: NonZeroU32 = NonZeroU32::from(NONZERO_U8);
assert_eq!(NONZERO_CONVERT.get(), 5);
+ */
}
#[test]
@@ -334,3 +336,21 @@ fn test_nonzero_uint_rem() {
let x: u32 = 42u32 % nz;
assert_eq!(x, 2u32);
}
+
+#[test]
+fn test_signed_nonzero_neg() {
+ assert_eq!((-NonZeroI8::new(1).unwrap()).get(), -1);
+ assert_eq!((-NonZeroI8::new(-1).unwrap()).get(), 1);
+
+ assert_eq!((-NonZeroI16::new(1).unwrap()).get(), -1);
+ assert_eq!((-NonZeroI16::new(-1).unwrap()).get(), 1);
+
+ assert_eq!((-NonZeroI32::new(1).unwrap()).get(), -1);
+ assert_eq!((-NonZeroI32::new(-1).unwrap()).get(), 1);
+
+ assert_eq!((-NonZeroI64::new(1).unwrap()).get(), -1);
+ assert_eq!((-NonZeroI64::new(-1).unwrap()).get(), 1);
+
+ assert_eq!((-NonZeroI128::new(1).unwrap()).get(), -1);
+ assert_eq!((-NonZeroI128::new(-1).unwrap()).get(), 1);
+}
diff --git a/library/core/tests/num/const_from.rs b/library/core/tests/num/const_from.rs
index aca18ef39..fa58e7718 100644
--- a/library/core/tests/num/const_from.rs
+++ b/library/core/tests/num/const_from.rs
@@ -1,3 +1,4 @@
+/* FIXME(#110395)
#[test]
fn from() {
use core::convert::TryFrom;
@@ -23,3 +24,4 @@ fn from() {
const I16_FROM_U16: Result<i16, TryFromIntError> = i16::try_from(1u16);
assert_eq!(I16_FROM_U16, Ok(1i16));
}
+*/
diff --git a/library/core/tests/num/ieee754.rs b/library/core/tests/num/ieee754.rs
index f6e5dfc98..48ab75b6f 100644
--- a/library/core/tests/num/ieee754.rs
+++ b/library/core/tests/num/ieee754.rs
@@ -39,7 +39,6 @@ macro_rules! assert_biteq {
// ToString uses the default fmt::Display impl without special concerns, and bypasses other parts
// of the formatting infrastructure, which makes it ideal for testing here.
-#[allow(unused_macros)]
macro_rules! roundtrip {
($f:expr => $t:ty) => {
($f).to_string().parse::<$t>().unwrap()
diff --git a/library/core/tests/num/int_macros.rs b/library/core/tests/num/int_macros.rs
index 18c55e43a..439bbe669 100644
--- a/library/core/tests/num/int_macros.rs
+++ b/library/core/tests/num/int_macros.rs
@@ -364,6 +364,32 @@ macro_rules! int_module {
assert_eq!((0 as $T).borrowing_sub($T::MIN, false), ($T::MIN, true));
assert_eq!((0 as $T).borrowing_sub($T::MIN, true), ($T::MAX, false));
}
+
+ #[test]
+ fn test_midpoint() {
+ assert_eq!(<$T>::midpoint(1, 3), 2);
+ assert_eq!(<$T>::midpoint(3, 1), 2);
+
+ assert_eq!(<$T>::midpoint(0, 0), 0);
+ assert_eq!(<$T>::midpoint(0, 2), 1);
+ assert_eq!(<$T>::midpoint(2, 0), 1);
+ assert_eq!(<$T>::midpoint(2, 2), 2);
+
+ assert_eq!(<$T>::midpoint(1, 4), 2);
+ assert_eq!(<$T>::midpoint(4, 1), 2);
+ assert_eq!(<$T>::midpoint(3, 4), 3);
+ assert_eq!(<$T>::midpoint(4, 3), 3);
+
+ assert_eq!(<$T>::midpoint(<$T>::MIN, <$T>::MAX), -1);
+ assert_eq!(<$T>::midpoint(<$T>::MAX, <$T>::MIN), -1);
+ assert_eq!(<$T>::midpoint(<$T>::MIN, <$T>::MIN), <$T>::MIN);
+ assert_eq!(<$T>::midpoint(<$T>::MAX, <$T>::MAX), <$T>::MAX);
+
+ assert_eq!(<$T>::midpoint(<$T>::MIN, 6), <$T>::MIN / 2 + 3);
+ assert_eq!(<$T>::midpoint(6, <$T>::MIN), <$T>::MIN / 2 + 3);
+ assert_eq!(<$T>::midpoint(<$T>::MAX, 6), <$T>::MAX / 2 + 3);
+ assert_eq!(<$T>::midpoint(6, <$T>::MAX), <$T>::MAX / 2 + 3);
+ }
}
};
}
diff --git a/library/core/tests/num/mod.rs b/library/core/tests/num/mod.rs
index c79e909e4..3f3659ba8 100644
--- a/library/core/tests/num/mod.rs
+++ b/library/core/tests/num/mod.rs
@@ -170,7 +170,7 @@ fn test_can_not_overflow() {
for base in 2..=36 {
let num = (<$t>::MAX as u128) + 1;
- // Calcutate the string length for the smallest overflowing number:
+ // Calculate the string length for the smallest overflowing number:
let max_len_string = format_radix(num, base as u128);
// Ensure that string length is deemed to potentially overflow:
assert!(can_overflow::<$t>(base, &max_len_string));
@@ -724,7 +724,7 @@ assume_usize_width! {
}
macro_rules! test_float {
- ($modname: ident, $fty: ty, $inf: expr, $neginf: expr, $nan: expr) => {
+ ($modname: ident, $fty: ty, $inf: expr, $neginf: expr, $nan: expr, $min: expr, $max: expr, $min_pos: expr) => {
mod $modname {
#[test]
fn min() {
@@ -845,6 +845,38 @@ macro_rules! test_float {
assert!(($nan as $fty).maximum($nan).is_nan());
}
#[test]
+ fn midpoint() {
+ assert_eq!((0.5 as $fty).midpoint(0.5), 0.5);
+ assert_eq!((0.5 as $fty).midpoint(2.5), 1.5);
+ assert_eq!((3.0 as $fty).midpoint(4.0), 3.5);
+ assert_eq!((-3.0 as $fty).midpoint(4.0), 0.5);
+ assert_eq!((3.0 as $fty).midpoint(-4.0), -0.5);
+ assert_eq!((-3.0 as $fty).midpoint(-4.0), -3.5);
+ assert_eq!((0.0 as $fty).midpoint(0.0), 0.0);
+ assert_eq!((-0.0 as $fty).midpoint(-0.0), -0.0);
+ assert_eq!((-5.0 as $fty).midpoint(5.0), 0.0);
+ assert_eq!(($max as $fty).midpoint($min), 0.0);
+ assert_eq!(($min as $fty).midpoint($max), -0.0);
+ assert_eq!(($max as $fty).midpoint($min_pos), $max / 2.);
+ assert_eq!((-$max as $fty).midpoint($min_pos), -$max / 2.);
+ assert_eq!(($max as $fty).midpoint(-$min_pos), $max / 2.);
+ assert_eq!((-$max as $fty).midpoint(-$min_pos), -$max / 2.);
+ assert_eq!(($min_pos as $fty).midpoint($max), $max / 2.);
+ assert_eq!(($min_pos as $fty).midpoint(-$max), -$max / 2.);
+ assert_eq!((-$min_pos as $fty).midpoint($max), $max / 2.);
+ assert_eq!((-$min_pos as $fty).midpoint(-$max), -$max / 2.);
+ assert_eq!(($max as $fty).midpoint($max), $max);
+ assert_eq!(($min_pos as $fty).midpoint($min_pos), $min_pos);
+ assert_eq!((-$min_pos as $fty).midpoint(-$min_pos), -$min_pos);
+ assert_eq!(($max as $fty).midpoint(5.0), $max / 2.0 + 2.5);
+ assert_eq!(($max as $fty).midpoint(-5.0), $max / 2.0 - 2.5);
+ assert_eq!(($inf as $fty).midpoint($inf), $inf);
+ assert_eq!(($neginf as $fty).midpoint($neginf), $neginf);
+ assert!(($nan as $fty).midpoint(1.0).is_nan());
+ assert!((1.0 as $fty).midpoint($nan).is_nan());
+ assert!(($nan as $fty).midpoint($nan).is_nan());
+ }
+ #[test]
fn rem_euclid() {
let a: $fty = 42.0;
assert!($inf.rem_euclid(a).is_nan());
@@ -867,5 +899,23 @@ macro_rules! test_float {
};
}
-test_float!(f32, f32, f32::INFINITY, f32::NEG_INFINITY, f32::NAN);
-test_float!(f64, f64, f64::INFINITY, f64::NEG_INFINITY, f64::NAN);
+test_float!(
+ f32,
+ f32,
+ f32::INFINITY,
+ f32::NEG_INFINITY,
+ f32::NAN,
+ f32::MIN,
+ f32::MAX,
+ f32::MIN_POSITIVE
+);
+test_float!(
+ f64,
+ f64,
+ f64::INFINITY,
+ f64::NEG_INFINITY,
+ f64::NAN,
+ f64::MIN,
+ f64::MAX,
+ f64::MIN_POSITIVE
+);
diff --git a/library/core/tests/num/uint_macros.rs b/library/core/tests/num/uint_macros.rs
index 15ae9f232..7d6203db0 100644
--- a/library/core/tests/num/uint_macros.rs
+++ b/library/core/tests/num/uint_macros.rs
@@ -252,6 +252,32 @@ macro_rules! uint_module {
assert_eq!($T::MAX.borrowing_sub(0, true), ($T::MAX - 1, false));
assert_eq!($T::MAX.borrowing_sub($T::MAX, true), ($T::MAX, true));
}
+
+ #[test]
+ fn test_midpoint() {
+ assert_eq!(<$T>::midpoint(1, 3), 2);
+ assert_eq!(<$T>::midpoint(3, 1), 2);
+
+ assert_eq!(<$T>::midpoint(0, 0), 0);
+ assert_eq!(<$T>::midpoint(0, 2), 1);
+ assert_eq!(<$T>::midpoint(2, 0), 1);
+ assert_eq!(<$T>::midpoint(2, 2), 2);
+
+ assert_eq!(<$T>::midpoint(1, 4), 2);
+ assert_eq!(<$T>::midpoint(4, 1), 2);
+ assert_eq!(<$T>::midpoint(3, 4), 3);
+ assert_eq!(<$T>::midpoint(4, 3), 3);
+
+ assert_eq!(<$T>::midpoint(<$T>::MIN, <$T>::MAX), (<$T>::MAX - <$T>::MIN) / 2);
+ assert_eq!(<$T>::midpoint(<$T>::MAX, <$T>::MIN), (<$T>::MAX - <$T>::MIN) / 2);
+ assert_eq!(<$T>::midpoint(<$T>::MIN, <$T>::MIN), <$T>::MIN);
+ assert_eq!(<$T>::midpoint(<$T>::MAX, <$T>::MAX), <$T>::MAX);
+
+ assert_eq!(<$T>::midpoint(<$T>::MIN, 6), <$T>::MIN / 2 + 3);
+ assert_eq!(<$T>::midpoint(6, <$T>::MIN), <$T>::MIN / 2 + 3);
+ assert_eq!(<$T>::midpoint(<$T>::MAX, 6), (<$T>::MAX - <$T>::MIN) / 2 + 3);
+ assert_eq!(<$T>::midpoint(6, <$T>::MAX), (<$T>::MAX - <$T>::MIN) / 2 + 3);
+ }
}
};
}
diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs
index dca6321cf..5defeb50d 100644
--- a/library/core/tests/option.rs
+++ b/library/core/tests/option.rs
@@ -88,6 +88,7 @@ fn test_and() {
assert_eq!(x.and(Some(2)), None);
assert_eq!(x.and(None::<isize>), None);
+ /* FIXME(#110395)
const FOO: Option<isize> = Some(1);
const A: Option<isize> = FOO.and(Some(2));
const B: Option<isize> = FOO.and(None);
@@ -99,6 +100,7 @@ fn test_and() {
const D: Option<isize> = BAR.and(None);
assert_eq!(C, None);
assert_eq!(D, None);
+ */
}
#[test]
@@ -119,6 +121,7 @@ fn test_and_then() {
assert_eq!(x.and_then(plus_one), None);
assert_eq!(x.and_then(none), None);
+ /* FIXME(#110395)
const FOO: Option<isize> = Some(1);
const A: Option<isize> = FOO.and_then(plus_one);
const B: Option<isize> = FOO.and_then(none);
@@ -130,6 +133,7 @@ fn test_and_then() {
const D: Option<isize> = BAR.and_then(none);
assert_eq!(C, None);
assert_eq!(D, None);
+ */
}
#[test]
@@ -142,6 +146,7 @@ fn test_or() {
assert_eq!(x.or(Some(2)), Some(2));
assert_eq!(x.or(None), None);
+ /* FIXME(#110395)
const FOO: Option<isize> = Some(1);
const A: Option<isize> = FOO.or(Some(2));
const B: Option<isize> = FOO.or(None);
@@ -153,6 +158,7 @@ fn test_or() {
const D: Option<isize> = BAR.or(None);
assert_eq!(C, Some(2));
assert_eq!(D, None);
+ */
}
#[test]
@@ -173,6 +179,7 @@ fn test_or_else() {
assert_eq!(x.or_else(two), Some(2));
assert_eq!(x.or_else(none), None);
+/* FIXME(#110395)
const FOO: Option<isize> = Some(1);
const A: Option<isize> = FOO.or_else(two);
const B: Option<isize> = FOO.or_else(none);
@@ -184,6 +191,7 @@ fn test_or_else() {
const D: Option<isize> = BAR.or_else(none);
assert_eq!(C, Some(2));
assert_eq!(D, None);
+*/
}
#[test]
@@ -215,10 +223,12 @@ fn test_unwrap_or() {
let x: Option<isize> = None;
assert_eq!(x.unwrap_or(2), 2);
+ /* FIXME(#110395)
const A: isize = Some(1).unwrap_or(2);
const B: isize = None.unwrap_or(2);
assert_eq!(A, 1);
assert_eq!(B, 2);
+ */
}
#[test]
@@ -233,10 +243,12 @@ fn test_unwrap_or_else() {
let x: Option<isize> = None;
assert_eq!(x.unwrap_or_else(two), 2);
+ /* FIXME(#110395)
const A: isize = Some(1).unwrap_or_else(two);
const B: isize = None.unwrap_or_else(two);
assert_eq!(A, 1);
assert_eq!(B, 2);
+ */
}
#[test]
@@ -439,14 +451,15 @@ fn option_const() {
const OPTION: Option<usize> = Some(32);
assert_eq!(OPTION, Some(32));
- const OPTION_FROM: Option<usize> = Option::from(32);
- assert_eq!(OPTION_FROM, Some(32));
+ // FIXME(#110395)
+ // const OPTION_FROM: Option<usize> = Option::from(32);
+ // assert_eq!(OPTION_FROM, Some(32));
const REF: Option<&usize> = OPTION.as_ref();
assert_eq!(REF, Some(&32));
- const REF_FROM: Option<&usize> = Option::from(&OPTION);
- assert_eq!(REF_FROM, Some(&32));
+ // const REF_FROM: Option<&usize> = Option::from(&OPTION);
+ // assert_eq!(REF_FROM, Some(&32));
const IS_SOME: bool = OPTION.is_some();
assert!(IS_SOME);
@@ -474,7 +487,7 @@ const fn option_const_mut() {
None => unreachable!(),
}
}
-
+/* FIXME(const-hack)
{
let as_mut: Option<&mut usize> = Option::from(&mut option);
match as_mut {
@@ -482,6 +495,7 @@ const fn option_const_mut() {
None => unreachable!(),
}
}
+*/
}
#[test]
diff --git a/library/core/tests/time.rs b/library/core/tests/time.rs
index 2975c81f8..872611937 100644
--- a/library/core/tests/time.rs
+++ b/library/core/tests/time.rs
@@ -425,14 +425,16 @@ fn duration_const() {
const SECONDS_F32: f32 = Duration::SECOND.as_secs_f32();
assert_eq!(SECONDS_F32, 1.0);
- const FROM_SECONDS_F32: Duration = Duration::from_secs_f32(1.0);
- assert_eq!(FROM_SECONDS_F32, Duration::SECOND);
+ // FIXME(#110395)
+ // const FROM_SECONDS_F32: Duration = Duration::from_secs_f32(1.0);
+ // assert_eq!(FROM_SECONDS_F32, Duration::SECOND);
const SECONDS_F64: f64 = Duration::SECOND.as_secs_f64();
assert_eq!(SECONDS_F64, 1.0);
- const FROM_SECONDS_F64: Duration = Duration::from_secs_f64(1.0);
- assert_eq!(FROM_SECONDS_F64, Duration::SECOND);
+ // FIXME(#110395)
+ // const FROM_SECONDS_F64: Duration = Duration::from_secs_f64(1.0);
+ // assert_eq!(FROM_SECONDS_F64, Duration::SECOND);
const MILLIS: u128 = Duration::SECOND.as_millis();
assert_eq!(MILLIS, 1_000);
@@ -463,6 +465,7 @@ fn duration_const() {
const CHECKED_MUL: Option<Duration> = Duration::SECOND.checked_mul(1);
assert_eq!(CHECKED_MUL, Some(Duration::SECOND));
+/* FIXME(#110395)
const MUL_F32: Duration = Duration::SECOND.mul_f32(1.0);
assert_eq!(MUL_F32, Duration::SECOND);
@@ -477,6 +480,7 @@ fn duration_const() {
const DIV_F64: Duration = Duration::SECOND.div_f64(1.0);
assert_eq!(DIV_F64, Duration::SECOND);
+*/
const DIV_DURATION_F32: f32 = Duration::SECOND.div_duration_f32(Duration::SECOND);
assert_eq!(DIV_DURATION_F32, 1.0);