Skip to content

Commit 8e74f88

Browse files
committed
feat: make Default conform to strict provenance
Related: #34
1 parent 667a9cd commit 8e74f88

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"crev",
44
"dealloc",
55
"docsrs",
6+
"miri",
67
"powerset",
78
"repr",
89
"Unsafety"

src/bytes.rs

+6
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,13 @@ impl<A: Alignment> Default for AlignedBytes<A> {
261261
// but for `A::size()` alignment.
262262
// The only requirement of new_unchecked is the pointer being not-null, and A::size() must be > 0.
263263
let bytes_ptr = unsafe {
264+
// Use strict pointer functions if enabled.
265+
// See https://github.com/V0ldek/aligners/issues/34
266+
#[cfg(miri)]
267+
let raw_ptr = std::ptr::invalid_mut(A::size());
268+
#[cfg(not(miri))]
264269
let raw_ptr = A::size() as *mut u8;
270+
265271
NonNull::new_unchecked(raw_ptr)
266272
};
267273
Self {

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// Same goes for the revolutionary "link to pointers documentation" feature.
2626
// (https://github.com/rust-lang/rust/issues/80896).
2727
#![cfg_attr(docsrs, feature(intra_doc_pointers))]
28+
#![cfg_attr(miri, feature(strict_provenance))]
2829

2930
//! Structures providing guarantees on byte sequence alignment.
3031
//!

0 commit comments

Comments
 (0)