diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2021-10-23 22:51:22 +0300 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2021-10-23 22:51:22 +0300 |
| commit | 5f390cfb722cf95b0df81f9563bf97b1663cff9e (patch) | |
| tree | def8b2963423180644bbdad113cfe525e9e0539b | |
| parent | 27d69611347142cc5f103df0923b46d670e75739 (diff) | |
| download | rust-5f390cfb722cf95b0df81f9563bf97b1663cff9e.tar.gz rust-5f390cfb722cf95b0df81f9563bf97b1663cff9e.zip | |
Add tests for `const_slice_from_ref` and `const_array_from_ref`
| -rw-r--r-- | library/core/tests/array.rs | 5 | ||||
| -rw-r--r-- | library/core/tests/lib.rs | 2 | ||||
| -rw-r--r-- | library/core/tests/slice.rs | 8 |
3 files changed, 15 insertions, 0 deletions
diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index b3af1328c90..d10bb4bce3c 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -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] diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index cf669163d3e..665ec756db1 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -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; diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index b6a326f3d73..f1691c4f057 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -2147,6 +2147,14 @@ fn test_slice_run_destructors() { } #[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 let mut a = [MaybeUninit::<u8>::uninit(); 10]; |
