File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
tests/kani/Intrinsics/Forget Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -338,7 +338,7 @@ floorf64 | No | |
338338fmaf32 | Yes | |
339339fmaf64 | Yes | |
340340fmul_fast | Partial | [ #809 ] ( https://github.com/model-checking/kani/issues/809 ) |
341- forget | Partial | Generates ` SKIP ` statement |
341+ forget | Yes | |
342342frem_fast | No | |
343343fsub_fast | Yes | |
344344likely | Yes | |
Original file line number Diff line number Diff line change 1+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3+ // kani-check-fail
4+
5+ // Checks that `forget` produces a compilation error if the value is referenced
6+ // after "forgetting" it
7+
8+ // This test is a modified version of the code found in
9+ // https://doc.rust-lang.org/std/mem/fn.forget.html#relationship-with-manuallydrop
10+ #![ feature( core_intrinsics) ]
11+
12+ #[ kani:: proof]
13+ fn main ( ) {
14+ let mut v = vec ! [ 65 , 122 ] ;
15+ // Build a `String` using the contents of `v`
16+ let s = unsafe { String :: from_raw_parts ( v. as_mut_ptr ( ) , v. len ( ) , v. capacity ( ) ) } ;
17+ // leak `v` because its memory is now managed by `s`
18+ std:: intrinsics:: forget ( v) ; // v is now invalid and must not be passed to a function
19+ assert ! ( v[ 0 ] == 65 ) ; // Error: v is referenced after `forget`
20+ assert_eq ! ( s, "Az" ) ;
21+ // `s` is implicitly dropped and its memory deallocated.
22+ }
Original file line number Diff line number Diff line change 1+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+ // Checks that `forget` does not cause a compilation error if the value is not
5+ // referenced after "forgetting" it
6+
7+ // This test is a modified version of the code found in
8+ // https://doc.rust-lang.org/std/mem/fn.forget.html#relationship-with-manuallydrop
9+ #![ feature( core_intrinsics) ]
10+
11+ #[ kani:: proof]
12+ fn main ( ) {
13+ let mut v = vec ! [ 65 , 122 ] ;
14+ // Build a `String` using the contents of `v`
15+ let s = unsafe { String :: from_raw_parts ( v. as_mut_ptr ( ) , v. len ( ) , v. capacity ( ) ) } ;
16+ // leak `v` because its memory is now managed by `s`
17+ std:: intrinsics:: forget ( v) ; // v is now invalid and must not be passed to a function
18+ assert_eq ! ( s, "Az" ) ;
19+ // `s` is implicitly dropped and its memory deallocated.
20+ }
You can’t perform that action at this time.
0 commit comments