File tree 3 files changed +17
-17
lines changed
src/test/ui/consts/const-eval
3 files changed +17
-17
lines changed Original file line number Diff line number Diff line change 1
1
use core:: any:: TypeId ;
2
+ use core:: intrinsics:: assume;
2
3
3
4
#[ test]
4
5
fn test_typeid_sized_types ( ) {
@@ -20,3 +21,17 @@ fn test_typeid_unsized_types() {
20
21
assert_eq ! ( TypeId :: of:: <Y >( ) , TypeId :: of:: <Y >( ) ) ;
21
22
assert ! ( TypeId :: of:: <X >( ) != TypeId :: of:: <Y >( ) ) ;
22
23
}
24
+
25
+ // Check that `const_assume` feature allow `assume` intrinsic
26
+ // to be used in const contexts.
27
+ #[ test]
28
+ fn test_assume_can_be_in_const_contexts ( ) {
29
+ const unsafe fn foo ( x : usize , y : usize ) -> usize {
30
+ // SAFETY: the entire function is not safe,
31
+ // but it is just an example not used elsewhere.
32
+ unsafe { assume ( y != 0 ) } ;
33
+ x / y
34
+ }
35
+ let rs = unsafe { foo ( 42 , 97 ) } ;
36
+ assert_eq ! ( rs, 0 ) ;
37
+ }
Original file line number Diff line number Diff line change 7
7
#![ feature( bound_cloned) ]
8
8
#![ feature( box_syntax) ]
9
9
#![ feature( cell_update) ]
10
+ #![ feature( const_assume) ]
11
+ #![ feature( core_intrinsics) ]
10
12
#![ feature( core_private_bignum) ]
11
13
#![ feature( core_private_diy_float) ]
12
14
#![ feature( debug_non_exhaustive) ]
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments