Skip to content

Commit a40d292

Browse files
author
Tarin Mahmood
committed
Checking unstable options from toml files
1 parent 7ea6493 commit a40d292

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/config.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,7 @@ macro_rules! create_config {
263263
impl<'a> ConfigSetter<'a> {
264264
$(
265265
pub fn $i(&mut self, value: $ty) {
266-
// we check if we are using nightly channel
267-
let unstable = is_nightly_channel!();
268-
if !(self.0).$i.3 {
269-
(self.0).$i.2 = value;
270-
} else {
271-
if unstable {
272-
(self.0).$i.2 = value;
273-
}
274-
}
266+
(self.0).$i.2 = value;
275267
}
276268
)+
277269
}
@@ -308,8 +300,18 @@ macro_rules! create_config {
308300
fn fill_from_parsed_config(mut self, parsed: PartialConfig) -> Config {
309301
$(
310302
if let Some(val) = parsed.$i {
311-
self.$i.1 = true;
312-
self.$i.2 = val;
303+
if !self.$i.3 {
304+
self.$i.1 = true;
305+
self.$i.2 = val;
306+
} else {
307+
if is_nightly_channel!() {
308+
self.$i.1 = true;
309+
self.$i.2 = val;
310+
} else {
311+
println!("Warning: can't set some features as unstable \
312+
features are only available in nightly channel.");
313+
}
314+
}
313315
}
314316
)+
315317
self
@@ -707,4 +709,17 @@ mod test {
707709
assert_eq!(config.unstable_features(), true);
708710
::std::env::set_var("CFG_RELEASE_CHANNEL", v);
709711
}
712+
713+
#[test]
714+
fn test_unstable_from_toml() {
715+
let mut config = Config::from_toml("unstable_features = true").unwrap();
716+
assert_eq!(config.was_set().unstable_features(), false);
717+
let v = ::std::env::var("CFG_RELEASE_CHANNEL").unwrap_or(String::from(""));
718+
::std::env::set_var("CFG_RELEASE_CHANNEL", "nightly");
719+
config = Config::from_toml("unstable_features = true").unwrap();
720+
assert_eq!(config.was_set().unstable_features(), true);
721+
assert_eq!(config.unstable_features(), true);
722+
::std::env::set_var("CFG_RELEASE_CHANNEL", v);
723+
}
724+
710725
}

0 commit comments

Comments
 (0)