diff options
| author | Rémy Rakic <remy.rakic+github@gmail.com> | 2023-09-21 13:26:41 +0000 |
|---|---|---|
| committer | Rémy Rakic <remy.rakic+github@gmail.com> | 2023-10-08 21:57:39 +0000 |
| commit | 6f54cbf754d7183280d89b29627791ddaadd87a9 (patch) | |
| tree | 1a88bb2dffa0634cbc8be68a9a17d2259e537a4a /compiler/rustc_target/src/spec | |
| parent | 5b9aa26401f13e9023bcc0e480694462f4cf031f (diff) | |
| download | rust-6f54cbf754d7183280d89b29627791ddaadd87a9.tar.gz rust-6f54cbf754d7183280d89b29627791ddaadd87a9.zip | |
add `IntoIterator` impl for self-contained linking components
Diffstat (limited to 'compiler/rustc_target/src/spec')
| -rw-r--r-- | compiler/rustc_target/src/spec/mod.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 5c31c856be4..16f70cf43b3 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -552,6 +552,46 @@ impl LinkSelfContainedComponents { _ => return None, }) } + + /// Return the component's name. + /// + /// Returns `None` if the bitflags aren't a singular component (but a mix of multiple flags). + pub fn as_str(self) -> Option<&'static str> { + Some(match self { + LinkSelfContainedComponents::CRT_OBJECTS => "crto", + LinkSelfContainedComponents::LIBC => "libc", + LinkSelfContainedComponents::UNWIND => "unwind", + LinkSelfContainedComponents::LINKER => "linker", + LinkSelfContainedComponents::SANITIZERS => "sanitizers", + LinkSelfContainedComponents::MINGW => "mingw", + _ => return None, + }) + } + + /// Returns an array of all the components. + fn all_components() -> [LinkSelfContainedComponents; 6] { + [ + LinkSelfContainedComponents::CRT_OBJECTS, + LinkSelfContainedComponents::LIBC, + LinkSelfContainedComponents::UNWIND, + LinkSelfContainedComponents::LINKER, + LinkSelfContainedComponents::SANITIZERS, + LinkSelfContainedComponents::MINGW, + ] + } +} + +impl IntoIterator for LinkSelfContainedComponents { + type Item = LinkSelfContainedComponents; + type IntoIter = std::vec::IntoIter<LinkSelfContainedComponents>; + + fn into_iter(self) -> Self::IntoIter { + LinkSelfContainedComponents::all_components() + .into_iter() + .filter(|&s| self.contains(s)) + .collect::<Vec<_>>() + .into_iter() + } } #[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)] |
