Skip to content

Commit 73b88ed

Browse files
committed
[review] allow setting unstable variants with --config
1 parent 0486686 commit 73b88ed

File tree

2 files changed

+69
-20
lines changed

2 files changed

+69
-20
lines changed

src/config/config_type.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,17 @@ macro_rules! create_config {
239239
stringify!($i),
240240
val,
241241
stringify!($ty)));
242-
let option_stable = self.$i.3;
243-
if $crate::config::config_type::is_stable_option_and_value(
244-
stringify!($i), option_stable, &option_value
245-
) {
246-
self.$i.1 = true;
247-
self.$i.2 = option_value;
248-
}
242+
243+
// Users are currently allowed to set unstable
244+
// options/variants via the `--config` options override.
245+
//
246+
// There is ongoing discussion about how to move forward here:
247+
// https://github.com/rust-lang/rustfmt/pull/5379
248+
//
249+
// For now, do not validate whether the option or value is stable,
250+
// just always set it.
251+
self.$i.1 = true;
252+
self.$i.2 = option_value;
249253
}
250254
)+
251255
_ => panic!("Unknown config key in override: {}", key)

src/config/mod.rs

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,61 @@ mod test {
461461
partially_unstable_option: PartiallyUnstableOption, PartiallyUnstableOption::V1, true,
462462
"A partially unstable option";
463463
}
464+
465+
#[cfg(test)]
466+
mod partially_unstable_option {
467+
use super::{Config, PartialConfig, PartiallyUnstableOption};
468+
use rustfmt_config_proc_macro::{nightly_only_test, stable_only_test};
469+
use std::path::Path;
470+
471+
/// From the config file, we can fill with a stable variant
472+
#[test]
473+
fn test_from_toml_stable_value() {
474+
let toml = r#"
475+
partially_unstable_option = "V2"
476+
"#;
477+
let partial_config: PartialConfig = toml::from_str(toml).unwrap();
478+
let config = Config::default();
479+
let config = config.fill_from_parsed_config(partial_config, Path::new(""));
480+
assert_eq!(
481+
config.partially_unstable_option(),
482+
PartiallyUnstableOption::V2
483+
);
484+
}
485+
486+
/// From the config file, we cannot fill with an unstable variant (stable only)
487+
#[stable_only_test]
488+
#[test]
489+
fn test_from_toml_unstable_value_on_stable() {
490+
let toml = r#"
491+
partially_unstable_option = "V3"
492+
"#;
493+
let partial_config: PartialConfig = toml::from_str(toml).unwrap();
494+
let config = Config::default();
495+
let config = config.fill_from_parsed_config(partial_config, Path::new(""));
496+
assert_eq!(
497+
config.partially_unstable_option(),
498+
// default value from config, i.e. fill failed
499+
PartiallyUnstableOption::V1
500+
);
501+
}
502+
503+
/// From the config file, we can fill with an unstable variant (nightly only)
504+
#[nightly_only_test]
505+
#[test]
506+
fn test_from_toml_unstable_value_on_nightly() {
507+
let toml = r#"
508+
partially_unstable_option = "V3"
509+
"#;
510+
let partial_config: PartialConfig = toml::from_str(toml).unwrap();
511+
let config = Config::default();
512+
let config = config.fill_from_parsed_config(partial_config, Path::new(""));
513+
assert_eq!(
514+
config.partially_unstable_option(),
515+
PartiallyUnstableOption::V3
516+
);
517+
}
518+
}
464519
}
465520

466521
#[test]
@@ -939,6 +994,7 @@ make_backup = false
939994
use super::mock::{Config, PartiallyUnstableOption};
940995
use super::*;
941996

997+
/// From the command line, we can override with a stable variant.
942998
#[test]
943999
fn test_override_stable_value() {
9441000
let mut config = Config::default();
@@ -949,20 +1005,9 @@ make_backup = false
9491005
);
9501006
}
9511007

952-
#[stable_only_test]
953-
#[test]
954-
fn test_override_unstable_value_on_stable() {
955-
let mut config = Config::default();
956-
config.override_value("partially_unstable_option", "V3");
957-
assert_eq!(
958-
config.partially_unstable_option(),
959-
PartiallyUnstableOption::V1
960-
);
961-
}
962-
963-
#[nightly_only_test]
1008+
/// From the command line, we can override with an unstable variant.
9641009
#[test]
965-
fn test_override_unstable_value_on_nightly() {
1010+
fn test_override_unstable_value() {
9661011
let mut config = Config::default();
9671012
config.override_value("partially_unstable_option", "V3");
9681013
assert_eq!(

0 commit comments

Comments
 (0)