Skip to content

Commit b4830f7

Browse files
feat: conditionally allow unstable opts on stable/beta (rust-lang#4228)
1 parent e9b039e commit b4830f7

File tree

8 files changed

+80
-18
lines changed

8 files changed

+80
-18
lines changed

.github/workflows/integration.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ jobs:
1515
matrix:
1616
integration: [
1717
bitflags,
18-
chalk,
19-
crater,
2018
error-chain,
21-
glob,
2219
log,
2320
mdbook,
2421
packed_simd,
@@ -37,6 +34,15 @@ jobs:
3734
# Instead, leverage `continue-on-error`
3835
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error
3936
#
37+
# Failing due to breaking changes in rustfmt 2.0 where empty
38+
# match blocks have trailing commas removed
39+
# https://github.com/rust-lang/rustfmt/pull/4226
40+
- integration: chalk
41+
allow-failure: true
42+
- integration: crater
43+
allow-failure: true
44+
- integration: glob
45+
allow-failure: true
4046
# Using old rustfmt configuration option
4147
- integration: rand
4248
allow-failure: true

.travis.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ matrix:
1818
- env: CFG_RELEASE_CHANNEL=beta
1919
- os: osx
2020
- env: INTEGRATION=bitflags
21-
- env: INTEGRATION=chalk
22-
- env: INTEGRATION=crater
2321
- env: INTEGRATION=error-chain
24-
- env: INTEGRATION=glob
2522
- env: INTEGRATION=log
2623
- env: INTEGRATION=mdbook
2724
- env: INTEGRATION=packed_simd
@@ -30,6 +27,12 @@ matrix:
3027
- env: INTEGRATION=tempdir
3128
- env: INTEGRATION=futures-rs
3229
allow_failures:
30+
# Failing due to breaking changes in rustfmt 2.0 where empty
31+
# match blocks have trailing commas removed
32+
# https://github.com/rust-lang/rustfmt/pull/4226
33+
- env: INTEGRATION=chalk
34+
- env: INTEGRATION=crater
35+
- env: INTEGRATION=glob
3336
# Using old configuration option
3437
- env: INTEGRATION=rand
3538
# Doesn't build - keep this in allow_failures as it's fragile to breaking changes of rustc.

Configurations.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -2395,11 +2395,18 @@ fn lorem<Ipsum: Dolor+Sit=Amet>() {
23952395

23962396
## `unstable_features`
23972397

2398-
Enable unstable features on the unstable channel.
2398+
Enable unstable features on stable and beta channels (unstable features are available by default on nightly).
23992399

24002400
- **Default value**: `false`
24012401
- **Possible values**: `true`, `false`
2402-
- **Stable**: No (tracking issue: [#3387](https://github.com/rust-lang/rustfmt/issues/3387))
2402+
- **Stable**: Yes
2403+
2404+
**Note** - if you are setting unstable configuration options via the CLI instead of the configuration file, then you should include a `unstable_features=true` item before any of the unstable items.
2405+
2406+
For example:
2407+
```bash
2408+
rustfmt src/lib.rs --config unstable_features=true merge_imports=true
2409+
```
24032410

24042411
## `use_field_init_shorthand`
24052412

src/config.rs

+32-5
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ create_config! {
142142
// Control options (changes the operation of rustfmt, rather than the formatting)
143143
required_version: String, env!("CARGO_PKG_VERSION").to_owned(), false,
144144
"Require a specific version of rustfmt";
145-
unstable_features: bool, false, false,
146-
"Enables unstable features. Only available on nightly channel";
145+
unstable_features: bool, false, true,
146+
"Enables unstable features on stable and beta channels (unstable features are enabled \
147+
by default on nightly channel)";
147148
hide_parse_errors: bool, false, false, "Hide errors from the parser";
148149
error_on_line_overflow: bool, false, false, "Error if unable to get all lines within max_width";
149150
error_on_unformatted: bool, false, false,
@@ -437,6 +438,10 @@ mod test {
437438
single_line_if_else_max_width: usize, 50, true, "Maximum line length for single \
438439
line if-else expressions. A value of zero means always break if-else expressions.";
439440

441+
unstable_features: bool, false, true,
442+
"Enables unstable features on stable and beta channels (unstable features are enabled \
443+
by default on nightly channel)";
444+
440445
// Options that are used by the tests
441446
stable_option: bool, false, true, "A stable option";
442447
unstable_option: bool, false, false, "An unstable option";
@@ -693,13 +698,31 @@ ignore = []
693698
}
694699

695700
#[test]
696-
fn test_from_toml_not_nightly() {
701+
fn test_from_toml_not_nightly_unstable_set() {
697702
if is_nightly_channel!() {
698703
// This test requires non-nightly
699704
return;
700705
}
701-
let config = Config::from_toml("unstable_features = true", Path::new("")).unwrap();
702-
assert_eq!(config.was_set().unstable_features(), false);
706+
let toml = r#"
707+
unstable_features = true
708+
merge_imports = true
709+
"#;
710+
let config = Config::from_toml(toml, Path::new("")).unwrap();
711+
assert_eq!(config.was_set().unstable_features(), true);
712+
assert_eq!(config.was_set().merge_imports(), true);
713+
assert_eq!(config.unstable_features(), true);
714+
assert_eq!(config.merge_imports(), true);
715+
}
716+
717+
#[test]
718+
fn test_from_toml_not_nightly_unstable_not_set() {
719+
if is_nightly_channel!() {
720+
// This test requires non-nightly
721+
return;
722+
}
723+
let config = Config::from_toml("merge_imports = true", Path::new("")).unwrap();
724+
assert_eq!(config.was_set().merge_imports(), false);
725+
assert_eq!(config.merge_imports(), false);
703726
}
704727

705728
#[test]
@@ -744,8 +767,12 @@ ignore = []
744767
}
745768
let mut config = Config::default();
746769
assert_eq!(config.unstable_features(), false);
770+
config.override_value("merge_imports", "true");
771+
assert_eq!(config.merge_imports(), false);
747772
config.override_value("unstable_features", "true");
748773
assert_eq!(config.unstable_features(), true);
774+
config.override_value("merge_imports", "true");
775+
assert_eq!(config.merge_imports(), true);
749776
}
750777

751778
#[test]

src/config/config_type.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,14 @@ macro_rules! create_config {
167167
if self.$i.3 {
168168
update_config!(self, $i = val, dir);
169169
} else {
170-
if is_nightly_channel!() {
170+
if parsed.unstable_features == Some(true) || is_nightly_channel!() {
171171
update_config!(self, $i = val, dir);
172172
} else {
173-
eprintln!("Warning: can't set `{} = {:?}`, unstable features are only \
174-
available in nightly channel.", stringify!($i), val);
173+
eprintln!(
174+
"Warning: can't set `{} = {:?}`, unstable features can only \
175+
be used on stable or beta when `unstable_features` is also enabled.",
176+
stringify!($i), val
177+
);
175178
}
176179
}
177180
}
@@ -237,12 +240,20 @@ macro_rules! create_config {
237240
match key {
238241
$(
239242
stringify!($i) => {
240-
self.$i.1 = true;
241-
self.$i.2 = val.parse::<$Ty>()
243+
if self.$i.3 || self.unstable_features() || is_nightly_channel!() {
244+
self.$i.1 = true;
245+
self.$i.2 = val.parse::<$Ty>()
242246
.expect(&format!("Failed to parse override for {} (\"{}\") as a {}",
243247
stringify!($i),
244248
val,
245249
stringify!($Ty)));
250+
} else {
251+
return eprintln!(
252+
"Warning: can't set `{} = {:?}`, unstable features can only \
253+
be used on stable or beta when `unstable_features` is also enabled.",
254+
stringify!($i), val
255+
);
256+
}
246257
}
247258
)+
248259
_ => panic!("Unknown config key in override: {}", key)

src/test/configuration_snippet.rs

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ impl ConfigCodeBlock {
9696

9797
fn get_block_config(&self) -> Config {
9898
let mut config = Config::default();
99+
if !crate::is_nightly_channel!() {
100+
config.override_value("unstable_features", "true");
101+
}
99102
if self.config_name.is_some() && self.config_value.is_some() {
100103
config.override_value(
101104
self.config_name.as_ref().unwrap(),

src/test/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ fn read_config(filename: &Path) -> (Config, OperationSetting, EmitterConfig) {
629629
get_config(filename.with_extension("toml").file_name().map(Path::new))
630630
};
631631

632+
if !config.was_set().unstable_features() && !is_nightly_channel!() {
633+
config.override_value("unstable_features", "true");
634+
}
635+
632636
let mut operation_setting = OperationSetting::default();
633637
let mut emitter_config = EmitterConfig::default();
634638
for (key, val) in &sig_comments {

tests/config/small_tabs.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
unstable_features = true
12
max_width = 100
23
comment_width = 80
34
tab_spaces = 2

0 commit comments

Comments
 (0)