Skip to content

Commit 9c1738c

Browse files
committed
Add more clauses per feedback
1 parent e795a44 commit 9c1738c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/core/src/ptr/alignment.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl Alignment {
6161
#[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
6262
#[inline]
6363
#[ensures(|result| align.is_power_of_two() == result.is_some())]
64+
#[ensures(|result| result.is_none() || result.unwrap().as_usize() == align)]
6465
pub const fn new(align: usize) -> Option<Self> {
6566
if align.is_power_of_two() {
6667
// SAFETY: Just checked it only has one bit set
@@ -132,6 +133,7 @@ impl Alignment {
132133
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
133134
#[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
134135
#[inline]
136+
#[requires(self.as_usize().is_power_of_two())]
135137
#[ensures(|result| (*result as usize) < mem::size_of::<usize>() * 8)]
136138
pub const fn log2(self) -> u32 {
137139
self.as_nonzero().trailing_zeros()
@@ -164,6 +166,7 @@ impl Alignment {
164166
#[rustc_const_unstable(feature = "ptr_alignment_type", issue = "102070")]
165167
#[inline]
166168
#[ensures(|result| *result > 0)]
169+
#[ensures(|result| *result == !(self.as_usize() -1))]
167170
pub const fn mask(self) -> usize {
168171
// SAFETY: The alignment is always nonzero, and therefore decrementing won't overflow.
169172
!(unsafe { self.as_usize().unchecked_sub(1) })

0 commit comments

Comments
 (0)