Skip to content

Commit 46865a0

Browse files
committed
add IntoIterator impl for self-contained linking components
1 parent 094451d commit 46865a0

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

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

0 commit comments

Comments
 (0)