Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
y86-dev committed Jun 24, 2023
1 parent 3403ff7 commit 891e28b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,9 +1104,9 @@ macro_rules! __init_internal {
// error when fields are missing (since they will be zeroed). We also have to
// check that the type actually implements `Zeroable`.
$(
fn is_zeroable<T: Zeroable>(ptr: *mut T) {}
fn assert_zeroable<T: Zeroable>(ptr: *mut T) {}
// Ensure that the struct is indeed `Zeroable`.
is_zeroable(slot);
assert_zeroable(slot);
// SAFETY: The type implements `Zeroable` by the check above.
unsafe { ::core::ptr::write_bytes(slot, 0, 1) };
$init_zeroed // this will be `()` if set.
Expand All @@ -1124,19 +1124,15 @@ macro_rules! __init_internal {
// We use unreachable code to ensure that all fields have been mentioned exactly
// once, this struct initializer will still be type-checked and complain with a
// very natural error message if a field is forgotten/mentioned more than once.
#[allow(unreachable_code,
clippy::diverging_sub_expression,
clippy::redundant_closure_call)]
if false {
(|| {
$crate::__init_internal!(make_initializer:
@slot(slot),
@type_name($t),
@munch_fields($($fields)*,),
@acc(),
);
})();
}
#[allow(unreachable_code, clippy::diverging_sub_expression)]
let _ = || {
$crate::__init_internal!(make_initializer:
@slot(slot),
@type_name($t),
@munch_fields($($fields)*,),
@acc(),
);
};
}
Ok(__InitOk)
}
Expand Down Expand Up @@ -1258,7 +1254,7 @@ macro_rules! __init_internal {
// get the correct type inference here:
unsafe {
let mut zeroed = ::core::mem::zeroed();
// We have to use type inference her to make zeroed have the correct type. This does
// We have to use type inference here to make zeroed have the correct type. This does
// not get executed, so it has no effect.
::core::ptr::write($slot, zeroed);
zeroed = ::core::mem::zeroed();
Expand Down

0 comments on commit 891e28b

Please sign in to comment.