Skip to content

Commit

Permalink
Put initializer checks into closures to avoid stack allocations in de…
Browse files Browse the repository at this point in the history
…bug builds
  • Loading branch information
y86-dev committed May 5, 2023
1 parent e794dbb commit 1f506ed
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,16 @@ macro_rules! try_pin_init {
// 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)]
#[allow(unreachable_code, clippy::diverging_sub_expression, unused_must_use)]
if false {
$crate::try_pin_init!(make_initializer:
@slot(slot),
@type_name($t),
@munch_fields($($fields)*,),
@acc(),
);
(|| {
$crate::try_pin_init!(make_initializer:
@slot(slot),
@type_name($t),
@munch_fields($($fields)*,),
@acc(),
);
})();
}
}
Ok(__InitOk)
Expand Down Expand Up @@ -1129,12 +1131,14 @@ macro_rules! try_init {
// very natural error message if a field is forgotten/mentioned more than once.
#[allow(unreachable_code, clippy::diverging_sub_expression)]
if false {
$crate::try_init!(make_initializer:
@slot(slot),
@type_name($t),
@munch_fields($($fields)*,),
@acc(),
);
(|| {
$crate::try_init!(make_initializer:
@slot(slot),
@type_name($t),
@munch_fields($($fields)*,),
@acc(),
);
})();
}
}
Ok(__InitOk)
Expand Down

0 comments on commit 1f506ed

Please sign in to comment.