mirror of
https://gitee.com/openharmony/third_party_rust_memoffset
synced 2024-11-27 01:11:21 +00:00
Add some compile-fail tests. (#68)
Ticket: - https://github.com/Gilnaa/memoffset/issues/23
This commit is contained in:
parent
d4812d6599
commit
af6689589f
@ -39,6 +39,21 @@ macro_rules! _memoffset__addr_of {
|
||||
}
|
||||
|
||||
/// Deref-coercion protection macro.
|
||||
///
|
||||
/// Prevents complilation if the specified field name is not a part of the
|
||||
/// struct definition.
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// use memoffset::_memoffset__field_check;
|
||||
///
|
||||
/// struct Foo {
|
||||
/// foo: i32,
|
||||
/// }
|
||||
///
|
||||
/// type BoxedFoo = Box<Foo>;
|
||||
///
|
||||
/// _memoffset__field_check!(BoxedFoo, foo);
|
||||
/// ```
|
||||
#[cfg(allow_clippy)]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
@ -64,6 +79,14 @@ macro_rules! _memoffset__field_check {
|
||||
}
|
||||
|
||||
/// Deref-coercion protection macro.
|
||||
///
|
||||
/// Prevents complilation if the specified type is not a tuple.
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// use memoffset::_memoffset__field_check_tuple;
|
||||
///
|
||||
/// _memoffset__field_check_tuple!(i32, 0);
|
||||
/// ```
|
||||
#[cfg(allow_clippy)]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
@ -87,6 +110,18 @@ macro_rules! _memoffset__field_check_tuple {
|
||||
/// Deref-coercion protection macro for unions.
|
||||
/// Unfortunately accepts single-field structs as well, which is not ideal,
|
||||
/// but ultimately pretty harmless.
|
||||
///
|
||||
/// ```compile_fail
|
||||
/// use memoffset::_memoffset__field_check_union;
|
||||
///
|
||||
/// union Foo {
|
||||
/// variant_a: i32,
|
||||
/// }
|
||||
///
|
||||
/// type BoxedFoo = Box<Foo>;
|
||||
///
|
||||
/// _memoffset__field_check_union!(BoxedFoo, variant_a);
|
||||
/// ```
|
||||
#[cfg(allow_clippy)]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
|
Loading…
Reference in New Issue
Block a user