diff options
| author | James Miller <james@aatch.net> | 2015-01-09 18:06:45 +1300 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-03-03 12:10:19 +0100 |
| commit | 280dea743b5227d0d162217cbb89db881242c94e (patch) | |
| tree | fb4892b0e233f4ec6ba5a646e2451d0597a5bd04 | |
| parent | 1246d4067fdc034d064dfb78f88c2c3c079c3f4f (diff) | |
| download | rust-280dea743b5227d0d162217cbb89db881242c94e.tar.gz rust-280dea743b5227d0d162217cbb89db881242c94e.zip | |
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.
| -rw-r--r-- | src/librustc/session/config.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 53c1f4e4a40..536caece21f 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -348,7 +348,8 @@ macro_rules! options { #[allow(non_upper_case_globals, dead_code)] mod $mod_desc { pub const parse_bool: Option<&'static str> = None; - pub const parse_opt_bool: Option<&'static str> = None; + pub const parse_opt_bool: Option<&'static str> = + Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`"); pub const parse_string: Option<&'static str> = Some("a string"); pub const parse_opt_string: Option<&'static str> = Some("a string"); pub const parse_list: Option<&'static str> = Some("a space-separated list of strings"); @@ -379,7 +380,19 @@ macro_rules! options { fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool { match v { - Some(..) => false, + Some(s) => { + match s { + "n" | "no" | "off" => { + *slot = Some(false); + } + "y" | "yes" | "on" => { + *slot = Some(true); + } + _ => { return false; } + } + + true + }, None => { *slot = Some(true); true } } } |
