File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -373,7 +373,7 @@ impl<T: ?Sized> NonNull<T> {
373
373
#[ rustc_const_stable( feature = "const_nonnull_as_ref" , since = "1.73.0" ) ]
374
374
#[ must_use]
375
375
#[ inline( always) ]
376
- #[ requires( ub_checks:: can_dereference( self ) ) ] // Ensure pointer is valid for shared reference
376
+ #[ requires( ub_checks:: can_dereference( self ) == true ) ] // Ensure pointer is valid for shared reference
377
377
#[ ensures( |result: &&T | core:: ptr:: eq( * result, self . as_ptr( ) ) ) ] // Ensure returned reference matches pointer
378
378
pub const unsafe fn as_ref < ' a > ( & self ) -> & ' a T {
379
379
// SAFETY: the caller must guarantee that `self` meets all the
@@ -1903,4 +1903,19 @@ mod verify {
1903
1903
let _ = ptr. as_uninit_slice_mut ( ) ;
1904
1904
}
1905
1905
}
1906
+
1907
+ #[ kani:: proof_for_contract( NonNull :: get_unchecked_mut) ]
1908
+ pub fn non_null_check_get_unchecked_mut ( ) {
1909
+ const ARR_SIZE : usize = 100000 ;
1910
+ let mut arr: [ i32 ; ARR_SIZE ] = kani:: any ( ) ;
1911
+ let raw_ptr = arr. as_mut_ptr ( ) ;
1912
+ let ptr = NonNull :: slice_from_raw_parts (
1913
+ NonNull :: new ( raw_ptr) . unwrap ( ) ,
1914
+ ARR_SIZE ,
1915
+ ) ;
1916
+ let index = kani:: any_where ( |x| * x < ARR_SIZE - 1 ) ;
1917
+ unsafe {
1918
+ let _ = ptr. get_unchecked_mut ( index..index + 1 ) ;
1919
+ }
1920
+ }
1906
1921
}
You can’t perform that action at this time.
0 commit comments