File tree 3 files changed +15
-0
lines changed
3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ fn array_from_ref() {
7
7
let value: String = "Hello World!" . into ( ) ;
8
8
let arr: & [ String ; 1 ] = array:: from_ref ( & value) ;
9
9
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 ] ) ) ;
10
15
}
11
16
12
17
#[ test]
Original file line number Diff line number Diff line change 71
71
#![ feature( trusted_random_access) ]
72
72
#![ feature( unsize) ]
73
73
#![ feature( unzip_option) ]
74
+ #![ feature( const_array_from_ref) ]
75
+ #![ feature( const_slice_from_ref) ]
74
76
#![ deny( unsafe_op_in_unsafe_fn) ]
75
77
76
78
extern crate test;
Original file line number Diff line number Diff line change @@ -2146,6 +2146,14 @@ fn test_slice_run_destructors() {
2146
2146
assert_eq ! ( x. get( ) , 1 ) ;
2147
2147
}
2148
2148
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
+
2149
2157
#[ test]
2150
2158
fn test_slice_fill_with_uninit ( ) {
2151
2159
// This should not UB. See #87891
You can’t perform that action at this time.
0 commit comments