Skip to content

Commit 280dea7

Browse files
Aatchpnkfelix
authored andcommitted
Implement parse_opt_bool better
During my clean-up of rebase errors, I took the opportunity to implement parse_opt_bool so that it isn't identical to parse_bool wrapped in `Some`. parse_opt_bool considers no value to be true, a value of 'y', 'yes' or 'on' to be true and 'n', 'no' or 'off' to be false. All other values are an error.
1 parent 1246d40 commit 280dea7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/librustc/session/config.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ macro_rules! options {
348348
#[allow(non_upper_case_globals, dead_code)]
349349
mod $mod_desc {
350350
pub const parse_bool: Option<&'static str> = None;
351-
pub const parse_opt_bool: Option<&'static str> = None;
351+
pub const parse_opt_bool: Option<&'static str> =
352+
Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`");
352353
pub const parse_string: Option<&'static str> = Some("a string");
353354
pub const parse_opt_string: Option<&'static str> = Some("a string");
354355
pub const parse_list: Option<&'static str> = Some("a space-separated list of strings");
@@ -379,7 +380,19 @@ macro_rules! options {
379380

380381
fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
381382
match v {
382-
Some(..) => false,
383+
Some(s) => {
384+
match s {
385+
"n" | "no" | "off" => {
386+
*slot = Some(false);
387+
}
388+
"y" | "yes" | "on" => {
389+
*slot = Some(true);
390+
}
391+
_ => { return false; }
392+
}
393+
394+
true
395+
},
383396
None => { *slot = Some(true); true }
384397
}
385398
}

0 commit comments

Comments
 (0)