Skip to content

Commit

Permalink
fix library and rustdoc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Apr 16, 2023
1 parent 147e850 commit 4c6ddc0
Show file tree
Hide file tree
Showing 108 changed files with 839 additions and 442 deletions.
19 changes: 11 additions & 8 deletions library/alloc/tests/const_fns.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Test const functions in the library

pub const MY_VEC: Vec<usize> = Vec::new();
pub const MY_VEC2: Vec<usize> = Default::default();

// FIXME(#110395)
// pub const MY_VEC2: Vec<usize> = Default::default();

pub const MY_STRING: String = String::new();
pub const MY_STRING2: String = Default::default();

pub const MY_BOXED_SLICE: Box<[usize]> = Default::default();
pub const MY_BOXED_STR: Box<str> = Default::default();
// pub const MY_STRING2: String = Default::default();

// pub const MY_BOXED_SLICE: Box<[usize]> = Default::default();
// pub const MY_BOXED_STR: Box<str> = Default::default();

use std::collections::{BTreeMap, BTreeSet};

Expand All @@ -23,11 +26,11 @@ pub const SET_IS_EMPTY: bool = SET.is_empty();

#[test]
fn test_const() {
assert_eq!(MY_VEC, MY_VEC2);
assert_eq!(MY_STRING, MY_STRING2);
assert_eq!(MY_VEC, /* MY_VEC */ vec![]);
assert_eq!(MY_STRING, /* MY_STRING2 */ String::default());

assert_eq!(MY_VEC, *MY_BOXED_SLICE);
assert_eq!(MY_STRING, *MY_BOXED_STR);
// assert_eq!(MY_VEC, *MY_BOXED_SLICE);
// assert_eq!(MY_STRING, *MY_BOXED_STR);

assert_eq!(MAP_LEN, 0);
assert_eq!(SET_LEN, 0);
Expand Down
2 changes: 0 additions & 2 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![feature(assert_matches)]
#![feature(btree_drain_filter)]
#![feature(cow_is_borrowed)]
#![feature(const_convert)]
#![feature(const_cow_is_borrowed)]
#![feature(const_heap)]
#![feature(const_mut_refs)]
Expand Down Expand Up @@ -33,7 +32,6 @@
#![feature(slice_partition_dedup)]
#![feature(string_remove_matches)]
#![feature(const_btree_len)]
#![feature(const_default_impls)]
#![feature(const_trait_impl)]
#![feature(const_str_from_utf8)]
#![feature(panic_update_hook)]
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
*/
2 changes: 2 additions & 0 deletions library/core/tests/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -102,4 +103,5 @@ fn test_bool_to_option() {
assert_eq!(B, Some(0));
assert_eq!(C, None);
assert_eq!(D, Some(0));
*/
}
2 changes: 2 additions & 0 deletions library/core/tests/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -476,4 +477,5 @@ fn const_cells() {
const CELL_FROM: Cell<i32> = Cell::from(3);
const _: i32 = CELL.into_inner();
*/
}
2 changes: 2 additions & 0 deletions library/core/tests/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ fn cmp_default() {
assert_eq!(Fool(false), Fool(true));
}

/* FIXME(#110395)
mod const_cmp {
use super::*;
Expand Down Expand Up @@ -248,3 +249,4 @@ mod const_cmp {
const _: () = assert!(S(0) < S(1));
const _: () = assert!(S(1) > S(0));
}
*/
2 changes: 2 additions & 0 deletions library/core/tests/convert.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* FIXME(#110395)
#[test]
fn convert() {
const fn from(x: i32) -> i32 {
Expand All @@ -14,3 +15,4 @@ fn convert() {
const BAR: Vec<String> = into(Vec::new());
assert_eq!(BAR, Vec::<String>::new());
}
*/
12 changes: 7 additions & 5 deletions library/core/tests/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ impl Hasher for MyHasher {

#[test]
fn test_writer_hasher() {
const fn hash<T: 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);
Expand All @@ -52,7 +53,7 @@ fn test_writer_hasher() {
let s: &str = "a";
assert!(hash(&s) == 97 + 0xFF);
};
}; */

assert_eq!(hash(&()), 0);

Expand Down Expand Up @@ -139,15 +140,16 @@ impl Hash for Custom {

#[test]
fn test_custom_state() {
const fn hash<T: 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()
}

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.
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn hash<T: Hash>(x: &T) -> u64 {
hash_with(SipHasher::new(), x)
}

/* FIXME(#110395)
#[test]
const fn test_const_sip() {
let val1 = 0x45;
Expand All @@ -36,6 +37,7 @@ const fn test_const_sip() {
assert!(const_hash(&(val1)) != const_hash(&(val2)));
}
*/

#[test]
#[allow(unused_must_use)]
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 0 additions & 3 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
#![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)]
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/num/const_from.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* FIXME(#110395)
#[test]
fn from() {
use core::convert::TryFrom;
Expand All @@ -23,3 +24,4 @@ fn from() {
const I16_FROM_U16: Result<i16, TryFromIntError> = i16::try_from(1u16);
assert_eq!(I16_FROM_U16, Ok(1i16));
}
*/
24 changes: 19 additions & 5 deletions library/core/tests/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -99,6 +100,7 @@ fn test_and() {
const D: Option<isize> = BAR.and(None);
assert_eq!(C, None);
assert_eq!(D, None);
*/
}

#[test]
Expand All @@ -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);
Expand All @@ -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]
Expand All @@ -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);
Expand All @@ -153,6 +158,7 @@ fn test_or() {
const D: Option<isize> = BAR.or(None);
assert_eq!(C, Some(2));
assert_eq!(D, None);
*/
}

#[test]
Expand All @@ -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);
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -474,14 +487,15 @@ const fn option_const_mut() {
None => unreachable!(),
}
}

/* FIXME(const-hack)
{
let as_mut: Option<&mut usize> = Option::from(&mut option);
match as_mut {
Some(v) => *v = 42,
None => unreachable!(),
}
}
*/
}

#[test]
Expand Down
Loading

0 comments on commit 4c6ddc0

Please sign in to comment.