File tree 1 file changed +13
-0
lines changed
src/librustc/mir/interpret
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1
1
use std:: fmt:: { self , Display } ;
2
+ use std:: convert:: TryFrom ;
2
3
3
4
use crate :: mir;
4
5
use crate :: ty:: layout:: { self , HasDataLayout , Size } ;
@@ -40,6 +41,18 @@ pub trait PointerArithmetic: layout::HasDataLayout {
40
41
self . data_layout ( ) . pointer_size
41
42
}
42
43
44
+ #[ inline]
45
+ fn usize_max ( & self ) -> u64 {
46
+ let max_usize_plus_1 = 1u128 << self . pointer_size ( ) . bits ( ) ;
47
+ u64:: try_from ( max_usize_plus_1-1 ) . unwrap ( )
48
+ }
49
+
50
+ #[ inline]
51
+ fn isize_max ( & self ) -> i64 {
52
+ let max_isize_plus_1 = 1u128 << ( self . pointer_size ( ) . bits ( ) -1 ) ;
53
+ i64:: try_from ( max_isize_plus_1-1 ) . unwrap ( )
54
+ }
55
+
43
56
/// Helper function: truncate given value-"overflowed flag" pair to pointer size and
44
57
/// update "overflowed flag" if there was an overflow.
45
58
/// This should be called by all the other methods before returning!
You can’t perform that action at this time.
0 commit comments