Skip to content

Commit 386d38a

Browse files
feat: allow unstable opts on stable via opt-in
1 parent 9549c3b commit 386d38a

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/config.rs

Lines changed: 7 additions & 2 deletions
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";

src/config/config_type.rs

Lines changed: 16 additions & 5 deletions
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)

0 commit comments

Comments
 (0)