Skip to content

Commit e8908e5

Browse files
committed
Add helper methods for unstable options
One method is used to determine if any unstable options were used on nightly. The other method provides us with easy access to the underlying Vec where all the unstable options were set.
1 parent bbbf6ad commit e8908e5

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/config/config_type.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ macro_rules! create_config {
147147
ConfigWasSet(self)
148148
}
149149

150+
/// Returns None if using nightly or if no unstable options were set.
151+
/// Otherwise, return all unstable options set by the user.
152+
#[allow(unreachable_pub)]
153+
pub fn unstable_options_set_on_stable_channel(&self) -> Option<&Vec<String>> {
154+
if crate::is_nightly_channel!() {
155+
None
156+
} else {
157+
self.configured_unstable_options.as_ref()
158+
}
159+
}
160+
161+
/// Returns true if any unstable options were set while on the stable channel
162+
#[allow(unreachable_pub)]
163+
pub fn using_unstable_options_on_stable_channel(&self) -> bool {
164+
self.configured_unstable_options.is_some()
165+
}
150166
fn fill_from_parsed_config(mut self, parsed: PartialConfig, dir: &Path) -> Config {
151167
let mut unstable_options = vec![];
152168
$(

src/config/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,35 @@ mod test {
549549
assert!(config.license_template.is_none());
550550
}
551551

552+
#[test]
553+
fn test_on_stable_get_all_unstable_options_set_in_toml() {
554+
if crate::is_nightly_channel!() {
555+
// This test requires non-nightly
556+
return;
557+
}
558+
let toml = r#"
559+
reorder_impl_items = true
560+
"#;
561+
let config = Config::from_toml(toml, Path::new("")).unwrap();
562+
assert_eq!(
563+
config.unstable_options_set_on_stable_channel().unwrap(),
564+
&vec!["reorder_impl_items = true"]
565+
)
566+
}
567+
568+
#[test]
569+
fn test_on_stable_are_any_unstable_options_set_in_toml() {
570+
if crate::is_nightly_channel!() {
571+
// This test requires non-nightly
572+
return;
573+
}
574+
let toml = r#"
575+
reorder_impl_items = true
576+
"#;
577+
let config = Config::from_toml(toml, Path::new("")).unwrap();
578+
assert!(config.using_unstable_options_on_stable_channel())
579+
}
580+
552581
#[test]
553582
fn test_dump_default_config() {
554583
let default_config = format!(

0 commit comments

Comments
 (0)