Skip to content

Commit

Permalink
Auto merge of rust-lang#102315 - RalfJung:assert_unsafe_precondition,…
Browse files Browse the repository at this point in the history
… r=thomcc

add a few more assert_unsafe_precondition

Add debug-assertion checking for `ptr.read()`, `ptr.write(_)`, and `unreachable_unchecked.`

This is quite useful for [cargo-careful](https://github.com/RalfJung/cargo-careful).
  • Loading branch information
bors committed Oct 8, 2022
2 parents 4490fbc + 69c341e commit bd78f3b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/fail/unaligned_pointers/unaligned_ptr1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

fn main() {
// Try many times as this might work by chance.
for _ in 0..10 {
for _ in 0..20 {
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
let x = &x[0] as *const _ as *const u32;
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/unaligned_pointers/unaligned_ptr_addr_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ptr;

fn main() {
// Try many times as this might work by chance.
for _ in 0..10 {
for _ in 0..20 {
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
let x = &x[0] as *const _ as *const u32;
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
Expand Down

0 comments on commit bd78f3b

Please sign in to comment.