Skip to content

Commit c33042a

Browse files
committed
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
1 parent 8dd09bf commit c33042a

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,21 @@ pub struct LinkSelfContained {
240240
impl LinkSelfContained {
241241
/// Incorporates an enabled or disabled component as specified on the CLI, if possible.
242242
/// For example: `+linker`, and `-crto`.
243-
pub(crate) fn handle_cli_component(&mut self, component: &str) -> Result<(), ()> {
243+
pub(crate) fn handle_cli_component(&mut self, component: &str) -> Option<()> {
244244
// Note that for example `-Cself-contained=y -Cself-contained=-linker` is not an explicit
245245
// set of all values like `y` or `n` used to be. Therefore, if this flag had previously been
246246
// set in bulk with its historical values, then manually setting a component clears that
247247
// `explicitly_set` state.
248248
if let Some(component_to_enable) = component.strip_prefix('+') {
249249
self.explicitly_set = None;
250-
self.components.insert(component_to_enable.parse()?);
251-
Ok(())
250+
self.components.insert(LinkSelfContainedComponents::from_str(component_to_enable)?);
251+
Some(())
252252
} else if let Some(component_to_disable) = component.strip_prefix('-') {
253253
self.explicitly_set = None;
254-
self.components.remove(component_to_disable.parse()?);
255-
Ok(())
254+
self.components.remove(LinkSelfContainedComponents::from_str(component_to_disable)?);
255+
Some(())
256256
} else {
257-
Err(())
257+
None
258258
}
259259
}
260260

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ mod parse {
11651165

11661166
// 2. Parse a list of enabled and disabled components.
11671167
for comp in s.split(',') {
1168-
if slot.handle_cli_component(comp).is_err() {
1168+
if slot.handle_cli_component(comp).is_none() {
11691169
return false;
11701170
}
11711171
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,18 +552,17 @@ bitflags::bitflags! {
552552
}
553553
}
554554

555-
impl FromStr for LinkSelfContainedComponents {
556-
type Err = ();
557-
558-
fn from_str(s: &str) -> Result<Self, Self::Err> {
559-
Ok(match s {
555+
impl LinkSelfContainedComponents {
556+
/// Parses a single `-Clink-self-contained` well-known component, not a set of flags.
557+
pub fn from_str(s: &str) -> Option<LinkSelfContainedComponents> {
558+
Some(match s {
560559
"crto" => LinkSelfContainedComponents::CRT_OBJECTS,
561560
"libc" => LinkSelfContainedComponents::LIBC,
562561
"unwind" => LinkSelfContainedComponents::UNWIND,
563562
"linker" => LinkSelfContainedComponents::LINKER,
564563
"sanitizers" => LinkSelfContainedComponents::SANITIZERS,
565564
"mingw" => LinkSelfContainedComponents::MINGW,
566-
_ => return Err(()),
565+
_ => return None,
567566
})
568567
}
569568
}

0 commit comments

Comments
 (0)