File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
src/librustc/mir/interpret Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 11use std:: fmt:: { self , Display } ;
2+ use std:: convert:: TryFrom ;
23
34use crate :: mir;
45use crate :: ty:: layout:: { self , HasDataLayout , Size } ;
@@ -40,6 +41,18 @@ pub trait PointerArithmetic: layout::HasDataLayout {
4041 self . data_layout ( ) . pointer_size
4142 }
4243
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+
4356 /// Helper function: truncate given value-"overflowed flag" pair to pointer size and
4457 /// update "overflowed flag" if there was an overflow.
4558 /// This should be called by all the other methods before returning!
You can’t perform that action at this time.
0 commit comments