From 6acd602daa707e3e1caf4a6539a51b968a9574bf Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Wed, 13 May 2026 12:26:52 +1000 Subject: [PATCH] macho: simplify SectionFlags construction in const expressions --- src/macho.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/macho.rs b/src/macho.rs index e467fad..bb8983c 100644 --- a/src/macho.rs +++ b/src/macho.rs @@ -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 for SectionFlags { fn from(typ: SectionType) -> Self { SectionFlags(u32::from(typ.0))