File tree Expand file tree Collapse file tree 5 files changed +23
-1
lines changed Expand file tree Collapse file tree 5 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ pub fn spin_loop() {
159159/// [`std::convert::identity`]: crate::convert::identity
160160#[ inline]
161161#[ unstable( feature = "bench_black_box" , issue = "64102" ) ]
162- pub fn black_box < T > ( dummy : T ) -> T {
162+ #[ rustc_const_unstable( feature = "const_black_box" , issue = "none" ) ]
163+ pub const fn black_box < T > ( dummy : T ) -> T {
163164 crate :: intrinsics:: black_box ( dummy)
164165}
Original file line number Diff line number Diff line change @@ -1940,6 +1940,7 @@ extern "rust-intrinsic" {
19401940 /// See documentation of [`std::hint::black_box`] for details.
19411941 ///
19421942 /// [`std::hint::black_box`]: crate::hint::black_box
1943+ #[ rustc_const_unstable( feature = "const_black_box" , issue = "none" ) ]
19431944 pub fn black_box < T > ( dummy : T ) -> T ;
19441945}
19451946
Original file line number Diff line number Diff line change 103103#![ feature( const_arguments_as_str) ]
104104#![ feature( const_array_into_iter_constructors) ]
105105#![ feature( const_bigint_helper_methods) ]
106+ #![ feature( const_black_box) ]
106107#![ feature( const_caller_location) ]
107108#![ feature( const_cell_into_inner) ]
108109#![ feature( const_char_convert) ]
Original file line number Diff line number Diff line change @@ -65,3 +65,18 @@ const fn test_write_bytes_in_const_contexts() {
6565 assert ! ( TEST2 [ 1 ] == 16843009 ) ;
6666 assert ! ( TEST2 [ 2 ] == 3 ) ;
6767}
68+
69+ #[ test]
70+ fn test_hints_in_const_contexts ( ) {
71+ use core:: intrinsics:: { likely, unlikely} ;
72+
73+ // In const contexts, they just return their argument.
74+ const {
75+ assert ! ( true == likely( true ) ) ;
76+ assert ! ( false == likely( false ) ) ;
77+ assert ! ( true == unlikely( true ) ) ;
78+ assert ! ( false == unlikely( false ) ) ;
79+ assert ! ( 42u32 == core:: intrinsics:: black_box( 42u32 ) ) ;
80+ assert ! ( 42u32 == core:: hint:: black_box( 42u32 ) ) ;
81+ }
82+ }
Original file line number Diff line number Diff line change 22#![ feature( array_chunks) ]
33#![ feature( array_methods) ]
44#![ feature( array_windows) ]
5+ #![ feature( bench_black_box) ]
56#![ feature( bool_to_option) ]
67#![ feature( box_syntax) ]
78#![ feature( cell_update) ]
89#![ feature( cfg_panic) ]
910#![ feature( cfg_target_has_atomic) ]
1011#![ feature( const_assume) ]
12+ #![ feature( const_black_box) ]
1113#![ feature( const_bool_to_option) ]
1214#![ feature( const_cell_into_inner) ]
1315#![ feature( const_convert) ]
1820#![ feature( const_ptr_write) ]
1921#![ feature( const_ptr_offset) ]
2022#![ feature( const_trait_impl) ]
23+ #![ feature( const_likely) ]
2124#![ feature( core_intrinsics) ]
2225#![ feature( core_private_bignum) ]
2326#![ feature( core_private_diy_float) ]
3538#![ feature( array_from_fn) ]
3639#![ feature( hashmap_internals) ]
3740#![ feature( try_find) ]
41+ #![ feature( inline_const) ]
3842#![ feature( is_sorted) ]
3943#![ feature( pattern) ]
4044#![ feature( sort_internals) ]
You can’t perform that action at this time.
0 commit comments