Skip to content

Commit

Permalink
Add tests for const_slice_from_ref and const_array_from_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Oct 23, 2021
1 parent 27d6961 commit 5f390cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/core/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ fn array_from_ref() {
let value: String = "Hello World!".into();
let arr: &[String; 1] = array::from_ref(&value);
assert_eq!(&[value.clone()], arr);

const VALUE: &&str = &"Hello World!";
const ARR: &[&str; 1] = array::from_ref(VALUE);
assert_eq!(&[*VALUE], ARR);
assert!(core::ptr::eq(VALUE, &ARR[0]));
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
#![feature(trusted_random_access)]
#![feature(unsize)]
#![feature(unzip_option)]
#![feature(const_array_from_ref)]
#![feature(const_slice_from_ref)]
#![deny(unsafe_op_in_unsafe_fn)]

extern crate test;
Expand Down
8 changes: 8 additions & 0 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,14 @@ fn test_slice_run_destructors() {
assert_eq!(x.get(), 1);
}

#[test]
fn test_const_from_ref() {
const VALUE: &i32 = &1;
const SLICE: &[i32] = core::slice::from_ref(VALUE);

assert!(core::ptr::eq(VALUE, &SLICE[0]))
}

#[test]
fn test_slice_fill_with_uninit() {
// This should not UB. See #87891
Expand Down

0 comments on commit 5f390cf

Please sign in to comment.