Skip to content

Commit 6f54cbf

Browse files
committed
add IntoIterator impl for self-contained linking components
1 parent 5b9aa26 commit 6f54cbf

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
@@ -552,6 +552,46 @@ impl LinkSelfContainedComponents {
552552
_ => return None,
553553
})
554554
}
555+
556+
/// Return the component's name.
557+
///
558+
/// Returns `None` if the bitflags aren't a singular component (but a mix of multiple flags).
559+
pub fn as_str(self) -> Option<&'static str> {
560+
Some(match self {
561+
LinkSelfContainedComponents::CRT_OBJECTS => "crto",
562+
LinkSelfContainedComponents::LIBC => "libc",
563+
LinkSelfContainedComponents::UNWIND => "unwind",
564+
LinkSelfContainedComponents::LINKER => "linker",
565+
LinkSelfContainedComponents::SANITIZERS => "sanitizers",
566+
LinkSelfContainedComponents::MINGW => "mingw",
567+
_ => return None,
568+
})
569+
}
570+
571+
/// Returns an array of all the components.
572+
fn all_components() -> [LinkSelfContainedComponents; 6] {
573+
[
574+
LinkSelfContainedComponents::CRT_OBJECTS,
575+
LinkSelfContainedComponents::LIBC,
576+
LinkSelfContainedComponents::UNWIND,
577+
LinkSelfContainedComponents::LINKER,
578+
LinkSelfContainedComponents::SANITIZERS,
579+
LinkSelfContainedComponents::MINGW,
580+
]
581+
}
582+
}
583+
584+
impl IntoIterator for LinkSelfContainedComponents {
585+
type Item = LinkSelfContainedComponents;
586+
type IntoIter = std::vec::IntoIter<LinkSelfContainedComponents>;
587+
588+
fn into_iter(self) -> Self::IntoIter {
589+
LinkSelfContainedComponents::all_components()
590+
.into_iter()
591+
.filter(|&s| self.contains(s))
592+
.collect::<Vec<_>>()
593+
.into_iter()
594+
}
555595
}
556596

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

0 commit comments

Comments
 (0)