Repository navigation
Commit 935c979
Use addr_eq in NonNull contracts to support wide pointers (#626)
Several postconditions in `NonNull` compared raw pointers with `==` or
`core::ptr::eq`: `as_ptr`, `new`, `new_unchecked`, the slice
`as_mut_ptr`, and — via `ptr::eq` — `as_ref`, `as_mut`, `as_uninit_ref`
and `as_uninit_mut`. For wide pointers (`T: ?Sized` with `dyn` metadata)
such comparisons also compare vtable pointers, whose identity is
unspecified in Rust; Kani rejects them with "Reached unstable vtable
comparison 'Eq'". With dependency contracts asserted (the Kani default
since model-checking/kani#3802), any harness whose call graph evaluates
these clauses on a trait-object `NonNull` fails, e.g.
`ptr::non_null::verify::non_null_check_from_raw_part_trait` (the
comparison surfaces in `ptr::eq::<dyn SampleTrait>`, reached from
`as_ref`'s postcondition).
This PR compares with `core::ptr::addr_eq` instead, which is
well-defined for any pointer types. All these functions produce their
result directly from `self`, so metadata is preserved by construction,
and the accompanying comments already described the intent as address
preservation. The casts in the `as_uninit_*` clauses need explicit
turbofish types now that the comparison no longer constrains their type
parameter.
Verified with Kani 152c6a8c + CBMC 6.10.0:
`non_null_check_from_raw_part_trait` now passes with contracts asserted
— this was the **last remaining verdict difference** on a 125-harness
sample between runs with and without `--no-assert-contracts`. The
`non_null_check_{as_ref,as_mut,as_uninit*,from_raw_part*,as_ptr,new}`
harnesses pass in both configurations, with one exception:
`non_null_check_as_uninit_slice_mut` fails with contracts asserted both
with and without this change (a pre-existing dereference/alignment issue
reached via asserted contracts, tracked separately).
Part of the `--no-assert-contracts` removal effort (#622, #623, #624,
#625, model-checking/kani#4709, model-checking/kani#4710).
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
---------
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Co-authored-by: Felipe R. Monteiro <rms.felipe@gmail.com>1 parent 82ab358 commit 935c979
1 file changed
Lines changed: 25 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
| 247 | + | |
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
| |||
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
284 | | - | |
| 285 | + | |
| 286 | + | |
285 | 287 | | |
286 | 288 | | |
287 | 289 | | |
| |||
420 | 422 | | |
421 | 423 | | |
422 | 424 | | |
423 | | - | |
424 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
425 | 432 | | |
426 | 433 | | |
427 | 434 | | |
| |||
461 | 468 | | |
462 | 469 | | |
463 | 470 | | |
464 | | - | |
465 | | - | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
466 | 479 | | |
467 | 480 | | |
468 | 481 | | |
| |||
503 | 516 | | |
504 | 517 | | |
505 | 518 | | |
506 | | - | |
| 519 | + | |
| 520 | + | |
507 | 521 | | |
508 | 522 | | |
509 | 523 | | |
| |||
1718 | 1732 | | |
1719 | 1733 | | |
1720 | 1734 | | |
1721 | | - | |
1722 | | - | |
| 1735 | + | |
| 1736 | + | |
1723 | 1737 | | |
1724 | 1738 | | |
1725 | 1739 | | |
| |||
0 commit comments