Use the Align
type when parsing alignment attributes
This commit is contained in:
parent
2f090c30dd
commit
6e5f1dacf3
12 changed files with 74 additions and 26 deletions
|
@ -698,6 +698,7 @@ impl fmt::Display for AlignFromBytesError {
|
|||
|
||||
impl Align {
|
||||
pub const ONE: Align = Align { pow2: 0 };
|
||||
pub const EIGHT: Align = Align { pow2: 3 };
|
||||
// LLVM has a maximal supported alignment of 2^29, we inherit that.
|
||||
pub const MAX: Align = Align { pow2: 29 };
|
||||
|
||||
|
@ -707,19 +708,19 @@ impl Align {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
|
||||
pub const fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
|
||||
// Treat an alignment of 0 bytes like 1-byte alignment.
|
||||
if align == 0 {
|
||||
return Ok(Align::ONE);
|
||||
}
|
||||
|
||||
#[cold]
|
||||
fn not_power_of_2(align: u64) -> AlignFromBytesError {
|
||||
const fn not_power_of_2(align: u64) -> AlignFromBytesError {
|
||||
AlignFromBytesError::NotPowerOfTwo(align)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
fn too_large(align: u64) -> AlignFromBytesError {
|
||||
const fn too_large(align: u64) -> AlignFromBytesError {
|
||||
AlignFromBytesError::TooLarge(align)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue