Skip to content

Commit 5f390cf

Browse files
committed
Add tests for const_slice_from_ref and const_array_from_ref
1 parent 27d6961 commit 5f390cf

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

library/core/tests/array.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ fn array_from_ref() {
77
let value: String = "Hello World!".into();
88
let arr: &[String; 1] = array::from_ref(&value);
99
assert_eq!(&[value.clone()], arr);
10+
11+
const VALUE: &&str = &"Hello World!";
12+
const ARR: &[&str; 1] = array::from_ref(VALUE);
13+
assert_eq!(&[*VALUE], ARR);
14+
assert!(core::ptr::eq(VALUE, &ARR[0]));
1015
}
1116

1217
#[test]

library/core/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#![feature(trusted_random_access)]
7272
#![feature(unsize)]
7373
#![feature(unzip_option)]
74+
#![feature(const_array_from_ref)]
75+
#![feature(const_slice_from_ref)]
7476
#![deny(unsafe_op_in_unsafe_fn)]
7577

7678
extern crate test;

library/core/tests/slice.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,14 @@ fn test_slice_run_destructors() {
21462146
assert_eq!(x.get(), 1);
21472147
}
21482148

2149+
#[test]
2150+
fn test_const_from_ref() {
2151+
const VALUE: &i32 = &1;
2152+
const SLICE: &[i32] = core::slice::from_ref(VALUE);
2153+
2154+
assert!(core::ptr::eq(VALUE, &SLICE[0]))
2155+
}
2156+
21492157
#[test]
21502158
fn test_slice_fill_with_uninit() {
21512159
// This should not UB. See #87891

0 commit comments

Comments
 (0)