mirror of
https://github.com/openharmony/third_party_rust_memoffset.git
synced 2026-07-18 12:25:36 -04:00
fix allow_clippy
This commit is contained in:
+2
-2
@@ -56,7 +56,7 @@ macro_rules! _memoffset_offset_from {
|
||||
// Compute offset, with unstable `offset_from` for const-compatibility.
|
||||
// (Requires the pointers to not dangle, but we already need that for `raw_field!` anyway.)
|
||||
unsafe { ($field as *const u8).offset_from($base as *const u8) as usize }
|
||||
}
|
||||
};
|
||||
}
|
||||
#[cfg(not(feature = "unstable_const"))]
|
||||
#[macro_export]
|
||||
@@ -65,7 +65,7 @@ macro_rules! _memoffset_offset_from {
|
||||
($field:expr, $base:expr) => {
|
||||
// Compute offset.
|
||||
($field as usize) - ($base as usize)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Calculates the offset of the specified field from the start of the struct.
|
||||
|
||||
+26
-5
@@ -38,6 +38,31 @@ macro_rules! _memoffset__raw_const {
|
||||
}};
|
||||
}
|
||||
|
||||
/// Deref-coercion protection macro.
|
||||
#[cfg(allow_clippy)]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! _memoffset__field_check {
|
||||
($type:path, $field:tt) => {
|
||||
// Make sure the field actually exists. This line ensures that a
|
||||
// compile-time error is generated if $field is accessed through a
|
||||
// Deref impl.
|
||||
#[allow(clippy::unneeded_field_pattern)]
|
||||
let $type { $field: _, .. };
|
||||
};
|
||||
}
|
||||
#[cfg(not(allow_clippy))]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! _memoffset__field_check {
|
||||
($type:path, $field:tt) => {
|
||||
// Make sure the field actually exists. This line ensures that a
|
||||
// compile-time error is generated if $field is accessed through a
|
||||
// Deref impl.
|
||||
let $type { $field: _, .. };
|
||||
};
|
||||
}
|
||||
|
||||
/// Computes a const raw pointer to the given field of the given base pointer
|
||||
/// to the given parent type.
|
||||
///
|
||||
@@ -46,11 +71,7 @@ macro_rules! _memoffset__raw_const {
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! raw_field {
|
||||
($base:expr, $parent:path, $field:tt) => {{
|
||||
// Make sure the field actually exists. This line ensures that a
|
||||
// compile-time error is generated if $field is accessed through a
|
||||
// Deref impl.
|
||||
#[cfg_attr(allow_clippy, allow(clippy::unneeded_field_pattern))]
|
||||
let $parent { $field: _, .. };
|
||||
_memoffset__field_check!($parent, $field);
|
||||
|
||||
// Get the field address.
|
||||
// Crucially, we know that this will not trigger a deref coercion because
|
||||
|
||||
Reference in New Issue
Block a user