Skip to content

Commit a2f25f7

Browse files
committed
add IntoIterator impl for self-contained linking components
1 parent 755bc0b commit a2f25f7

File tree

1 file changed

+40
-0
lines changed
  • compiler/rustc_target/src/spec

1 file changed

+40
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

+40
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,46 @@ impl LinkSelfContainedComponents {
563563
_ => return None,
564564
})
565565
}
566+
567+
/// Return the component's name.
568+
///
569+
/// Returns `None` if the bitflags aren't a singular component (but a mix of multiple flags).
570+
pub fn as_str(self) -> Option<&'static str> {
571+
Some(match self {
572+
LinkSelfContainedComponents::CRT_OBJECTS => "crto",
573+
LinkSelfContainedComponents::LIBC => "libc",
574+
LinkSelfContainedComponents::UNWIND => "unwind",
575+
LinkSelfContainedComponents::LINKER => "linker",
576+
LinkSelfContainedComponents::SANITIZERS => "sanitizers",
577+
LinkSelfContainedComponents::MINGW => "mingw",
578+
_ => return None,
579+
})
580+
}
581+
582+
/// Returns an array of all the components.
583+
fn all_components() -> [LinkSelfContainedComponents; 6] {
584+
[
585+
LinkSelfContainedComponents::CRT_OBJECTS,
586+
LinkSelfContainedComponents::LIBC,
587+
LinkSelfContainedComponents::UNWIND,
588+
LinkSelfContainedComponents::LINKER,
589+
LinkSelfContainedComponents::SANITIZERS,
590+
LinkSelfContainedComponents::MINGW,
591+
]
592+
}
593+
}
594+
595+
impl IntoIterator for LinkSelfContainedComponents {
596+
type Item = LinkSelfContainedComponents;
597+
type IntoIter = std::vec::IntoIter<LinkSelfContainedComponents>;
598+
599+
fn into_iter(self) -> Self::IntoIter {
600+
LinkSelfContainedComponents::all_components()
601+
.into_iter()
602+
.filter(|&s| self.contains(s))
603+
.collect::<Vec<_>>()
604+
.into_iter()
605+
}
566606
}
567607

568608
#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)]

0 commit comments

Comments
 (0)