macho: simplify SectionFlags construction in const expressions

This commit is contained in:
Philip Craig
2026-05-13 12:26:52 +10:00
parent b36ef44ec6
commit 6acd602daa
+9 -2
View File
@@ -1590,8 +1590,8 @@ impl SectionFlags {
}
/// Set the section type field.
pub fn with_type(self, typ: SectionType) -> SectionFlags {
SectionFlags(self.0 & !SECTION_TYPE | u32::from(typ.0))
pub const fn with_type(self, typ: SectionType) -> SectionFlags {
SectionFlags(self.0 & !SECTION_TYPE | typ.0 as u32)
}
}
@@ -1600,6 +1600,13 @@ newtype!(
struct SectionType(u8);
);
impl SectionType {
/// Convert to a `SectionFlags` with no attributes, for use in const expressions.
pub const fn to_flags(self) -> SectionFlags {
SectionFlags(self.0 as u32)
}
}
impl From<SectionType> for SectionFlags {
fn from(typ: SectionType) -> Self {
SectionFlags(u32::from(typ.0))