about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2023-09-20 20:09:06 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2023-10-08 21:57:39 +0000
commit2ce46f8e8c2efd76973bfa3a068cf67b7b525d48 (patch)
treefc6d116f85baede84ff5169ac4920b4d6ed88c29
parentacc3b61c5e998b8ae170ed7f7b0b37aeecaf01a9 (diff)
downloadrust-2ce46f8e8c2efd76973bfa3a068cf67b7b525d48.tar.gz
rust-2ce46f8e8c2efd76973bfa3a068cf67b7b525d48.zip
move single component parsing to dedicated function
this will prevent parsing when expecting more than a single component
to be parsed, and prepare for the symetric variant-to-name function to
be added
-rw-r--r--compiler/rustc_session/src/config.rs12
-rw-r--r--compiler/rustc_session/src/options.rs2
-rw-r--r--compiler/rustc_target/src/spec/mod.rs11
3 files changed, 12 insertions, 13 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index 5e46a86f1ff..e3e29669ec5 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -240,21 +240,21 @@ pub struct LinkSelfContained {
 impl LinkSelfContained {
     /// Incorporates an enabled or disabled component as specified on the CLI, if possible.
     /// For example: `+linker`, and `-crto`.
-    pub(crate) fn handle_cli_component(&mut self, component: &str) -> Result<(), ()> {
+    pub(crate) fn handle_cli_component(&mut self, component: &str) -> Option<()> {
         // Note that for example `-Cself-contained=y -Cself-contained=-linker` is not an explicit
         // set of all values like `y` or `n` used to be. Therefore, if this flag had previously been
         // set in bulk with its historical values, then manually setting a component clears that
         // `explicitly_set` state.
         if let Some(component_to_enable) = component.strip_prefix('+') {
             self.explicitly_set = None;
-            self.components.insert(component_to_enable.parse()?);
-            Ok(())
+            self.components.insert(LinkSelfContainedComponents::from_str(component_to_enable)?);
+            Some(())
         } else if let Some(component_to_disable) = component.strip_prefix('-') {
             self.explicitly_set = None;
-            self.components.remove(component_to_disable.parse()?);
-            Ok(())
+            self.components.remove(LinkSelfContainedComponents::from_str(component_to_disable)?);
+            Some(())
         } else {
-            Err(())
+            None
         }
     }
 
diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs
index f7c000c8bd6..e8f3123b99e 100644
--- a/compiler/rustc_session/src/options.rs
+++ b/compiler/rustc_session/src/options.rs
@@ -1165,7 +1165,7 @@ mod parse {
 
         // 2. Parse a list of enabled and disabled components.
         for comp in s.split(',') {
-            if slot.handle_cli_component(comp).is_err() {
+            if slot.handle_cli_component(comp).is_none() {
                 return false;
             }
         }
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index 40d92bd5387..5c31c856be4 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -539,18 +539,17 @@ bitflags::bitflags! {
     }
 }
 
-impl FromStr for LinkSelfContainedComponents {
-    type Err = ();
-
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
-        Ok(match s {
+impl LinkSelfContainedComponents {
+    /// Parses a single `-Clink-self-contained` well-known component, not a set of flags.
+    pub fn from_str(s: &str) -> Option<LinkSelfContainedComponents> {
+        Some(match s {
             "crto" => LinkSelfContainedComponents::CRT_OBJECTS,
             "libc" => LinkSelfContainedComponents::LIBC,
             "unwind" => LinkSelfContainedComponents::UNWIND,
             "linker" => LinkSelfContainedComponents::LINKER,
             "sanitizers" => LinkSelfContainedComponents::SANITIZERS,
             "mingw" => LinkSelfContainedComponents::MINGW,
-            _ => return Err(()),
+            _ => return None,
         })
     }
 }