mirror of
https://github.com/openharmony/third_party_rust_memoffset.git
synced 2026-07-19 22:44:17 -04:00
no need to use NonNull
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
sudo: false
|
||||
language: rust
|
||||
rust:
|
||||
- 1.25.0 # Oldest supported (to make doc-comment not ICE)
|
||||
- 1.20.0 # Oldest supported
|
||||
- 1.36.0 # Oldest supported with MaybeUninit
|
||||
- stable
|
||||
- beta
|
||||
|
||||
@@ -18,7 +18,7 @@ Add the following dependency to your `Cargo.toml`:
|
||||
memoffset = "0.5"
|
||||
```
|
||||
|
||||
These versions will compile fine with rustc versions greater or equal to 1.25.
|
||||
These versions will compile fine with rustc versions greater or equal to 1.20.
|
||||
|
||||
Add the following lines at the top of your `main.rs` or `lib.rs` files.
|
||||
|
||||
|
||||
+3
-4
@@ -39,10 +39,9 @@ macro_rules! _memoffset__let_base_ptr {
|
||||
#[doc(hidden)]
|
||||
macro_rules! _memoffset__let_base_ptr {
|
||||
($name:ident, $type:tt) => {
|
||||
// No UB right here, but we will later offset into a field
|
||||
// of this pointer, and that is UB when the pointer is dangling.
|
||||
let non_null = $crate::ptr::NonNull::<$type>::dangling();
|
||||
let $name = non_null.as_ptr() as *const $type;
|
||||
// No UB right here, but we will later dereference this pointer to
|
||||
// offset into a field, and that is UB when the pointer is dangling.
|
||||
let $name = $crate::mem::align_of::<$type>() as *const $type;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user