Skip to content

Commit f15633b

Browse files
committed
Remove version gating and style editions
1 parent 6f7aeed commit f15633b

File tree

211 files changed

+359
-2953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+359
-2953
lines changed

Configurations.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,17 +2692,6 @@ By default this option is set as a percentage of [`max_width`](#max_width) provi
26922692

26932693
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
26942694

2695-
## `style_edition`
2696-
2697-
Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338])
2698-
2699-
- **Default value**: `"2015"`
2700-
- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant)
2701-
- **Stable**: No
2702-
2703-
[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/
2704-
[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html
2705-
27062695
## `tab_spaces`
27072696

27082697
Number of spaces per tab
@@ -3060,22 +3049,6 @@ fn main() {
30603049
}
30613050
```
30623051

3063-
## `version`
3064-
3065-
This option is deprecated and has been replaced by [`style_edition`](#style_edition).
3066-
`version = "One"` is equivalent to `style_edition = "(2015|2018|2021)"` and
3067-
`version = "Two"` is equivalent to `style_edition = "2024"`
3068-
3069-
- **Default value**: `One`
3070-
- **Possible values**: `One`, `Two`
3071-
- **Stable**: No (tracking issue: [#3383](https://github.com/rust-lang/rustfmt/issues/3383))
3072-
3073-
### Example
3074-
3075-
```toml
3076-
version = "Two"
3077-
```
3078-
30793052
## `where_single_line`
30803053

30813054
Forces the `where` clause to be laid out on a single line.

rustfmt.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
error_on_line_overflow = true
22
error_on_unformatted = true
3-
style_edition = "2024"
3+
# FIXME(new)
4+
# style_edition = "2024"
45
overflow_delimited_expr = false

src/bin/main.rs

Lines changed: 3 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use getopts::{Matches, Options};
1919

2020
use crate::rustfmt::{
2121
CliOptions, Color, Config, Edition, EmitMode, FileLines, FileName,
22-
FormatReportFormatterBuilder, Input, Session, StyleEdition, Verbosity, Version, load_config,
22+
FormatReportFormatterBuilder, Input, Session, Verbosity, Version, load_config,
2323
};
2424

2525
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug";
@@ -536,7 +536,6 @@ struct GetOptsOptions {
536536
backup: bool,
537537
check: bool,
538538
edition: Option<Edition>,
539-
style_edition: Option<StyleEdition>,
540539
color: Option<Color>,
541540
file_lines: FileLines, // Default is all lines in all files.
542541
unstable_features: bool,
@@ -628,8 +627,8 @@ impl GetOptsOptions {
628627
options.edition = Some(edition_from_edition_str(edition_str)?);
629628
}
630629

631-
if let Some(ref edition_str) = matches.opt_str("style-edition") {
632-
options.style_edition = Some(style_edition_from_style_edition_str(edition_str)?);
630+
if let Some(ref _edition_str) = matches.opt_str("style-edition") {
631+
// FIXME(new): removed
633632
}
634633

635634
if matches.opt_present("backup") {
@@ -704,9 +703,6 @@ impl CliOptions for GetOptsOptions {
704703
if let Some(edition) = self.edition {
705704
config.set_cli().edition(edition);
706705
}
707-
if let Some(edition) = self.style_edition {
708-
config.set_cli().style_edition(edition);
709-
}
710706
if self.check {
711707
config.set_cli().emit_mode(EmitMode::Diff);
712708
} else if let Some(emit_mode) = self.emit_mode {
@@ -737,12 +733,6 @@ impl CliOptions for GetOptsOptions {
737733
.map_or(self.edition, |e| Edition::from_str(e).ok())
738734
}
739735

740-
fn style_edition(&self) -> Option<StyleEdition> {
741-
self.inline_config
742-
.get("style_edition")
743-
.map_or(self.style_edition, |se| StyleEdition::from_str(se).ok())
744-
}
745-
746736
fn version(&self) -> Option<Version> {
747737
self.inline_config
748738
.get("version")
@@ -761,17 +751,6 @@ fn edition_from_edition_str(edition_str: &str) -> Result<Edition> {
761751
}
762752
}
763753

764-
fn style_edition_from_style_edition_str(edition_str: &str) -> Result<StyleEdition> {
765-
match edition_str {
766-
"2015" => Ok(StyleEdition::Edition2015),
767-
"2018" => Ok(StyleEdition::Edition2018),
768-
"2021" => Ok(StyleEdition::Edition2021),
769-
"2024" => Ok(StyleEdition::Edition2024),
770-
"2027" => Ok(StyleEdition::Edition2027),
771-
_ => Err(format_err!("Invalid value for `--style-edition`")),
772-
}
773-
}
774-
775754
fn emit_mode_from_emit_str(emit_str: &str) -> Result<EmitMode> {
776755
match emit_str {
777756
"files" => Ok(EmitMode::Files),
@@ -782,185 +761,3 @@ fn emit_mode_from_emit_str(emit_str: &str) -> Result<EmitMode> {
782761
_ => Err(format_err!("Invalid value for `--emit`")),
783762
}
784763
}
785-
786-
#[cfg(test)]
787-
#[allow(dead_code)]
788-
mod test {
789-
use super::*;
790-
use rustfmt_config_proc_macro::nightly_only_test;
791-
792-
fn get_config<O: CliOptions>(path: Option<&Path>, options: Option<O>) -> Config {
793-
load_config(path, options).unwrap().0
794-
}
795-
796-
#[nightly_only_test]
797-
#[test]
798-
fn flag_sets_style_edition_override_correctly() {
799-
let mut options = GetOptsOptions::default();
800-
options.style_edition = Some(StyleEdition::Edition2024);
801-
let config = get_config(None, Some(options));
802-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
803-
}
804-
805-
#[nightly_only_test]
806-
#[test]
807-
fn edition_sets_style_edition_override_correctly() {
808-
let mut options = GetOptsOptions::default();
809-
options.edition = Some(Edition::Edition2024);
810-
let config = get_config(None, Some(options));
811-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
812-
}
813-
814-
#[nightly_only_test]
815-
#[test]
816-
fn version_sets_style_edition_override_correctly() {
817-
let mut options = GetOptsOptions::default();
818-
options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]);
819-
let config = get_config(None, Some(options));
820-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
821-
assert_eq!(config.overflow_delimited_expr(), true);
822-
}
823-
824-
#[nightly_only_test]
825-
#[test]
826-
fn version_config_file_sets_style_edition_override_correctly() {
827-
let options = GetOptsOptions::default();
828-
let config_file = Some(Path::new("tests/config/style-edition/just-version"));
829-
let config = get_config(config_file, Some(options));
830-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
831-
assert_eq!(config.overflow_delimited_expr(), true);
832-
}
833-
834-
#[nightly_only_test]
835-
#[test]
836-
fn style_edition_flag_has_correct_precedence_over_edition() {
837-
let mut options = GetOptsOptions::default();
838-
options.style_edition = Some(StyleEdition::Edition2021);
839-
options.edition = Some(Edition::Edition2024);
840-
let config = get_config(None, Some(options));
841-
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
842-
}
843-
844-
#[nightly_only_test]
845-
#[test]
846-
fn style_edition_flag_has_correct_precedence_over_version() {
847-
let mut options = GetOptsOptions::default();
848-
options.style_edition = Some(StyleEdition::Edition2018);
849-
options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]);
850-
let config = get_config(None, Some(options));
851-
assert_eq!(config.style_edition(), StyleEdition::Edition2018);
852-
}
853-
854-
#[nightly_only_test]
855-
#[test]
856-
fn style_edition_flag_has_correct_precedence_over_edition_version() {
857-
let mut options = GetOptsOptions::default();
858-
options.style_edition = Some(StyleEdition::Edition2021);
859-
options.edition = Some(Edition::Edition2018);
860-
options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]);
861-
let config = get_config(None, Some(options));
862-
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
863-
}
864-
865-
#[nightly_only_test]
866-
#[test]
867-
fn style_edition_inline_has_correct_precedence_over_edition_version() {
868-
let mut options = GetOptsOptions::default();
869-
options.edition = Some(Edition::Edition2018);
870-
options.inline_config = HashMap::from([
871-
("version".to_owned(), "One".to_owned()),
872-
("style_edition".to_owned(), "2024".to_owned()),
873-
]);
874-
let config = get_config(None, Some(options));
875-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
876-
assert_eq!(config.overflow_delimited_expr(), true);
877-
}
878-
879-
#[nightly_only_test]
880-
#[test]
881-
fn style_edition_config_file_trumps_edition_flag_version_inline() {
882-
let mut options = GetOptsOptions::default();
883-
let config_file = Some(Path::new("tests/config/style-edition/just-style-edition"));
884-
options.edition = Some(Edition::Edition2018);
885-
options.inline_config = HashMap::from([("version".to_owned(), "One".to_owned())]);
886-
let config = get_config(config_file, Some(options));
887-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
888-
}
889-
890-
#[nightly_only_test]
891-
#[test]
892-
fn style_edition_config_file_trumps_edition_config_and_version_inline() {
893-
let mut options = GetOptsOptions::default();
894-
let config_file = Some(Path::new(
895-
"tests/config/style-edition/style-edition-and-edition",
896-
));
897-
options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]);
898-
let config = get_config(config_file, Some(options));
899-
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
900-
assert_eq!(config.edition(), Edition::Edition2024);
901-
}
902-
903-
#[nightly_only_test]
904-
#[test]
905-
fn version_config_trumps_edition_config_and_flag() {
906-
let mut options = GetOptsOptions::default();
907-
let config_file = Some(Path::new("tests/config/style-edition/version-edition"));
908-
options.edition = Some(Edition::Edition2018);
909-
let config = get_config(config_file, Some(options));
910-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
911-
}
912-
913-
#[nightly_only_test]
914-
#[test]
915-
fn style_edition_config_file_trumps_version_config() {
916-
let options = GetOptsOptions::default();
917-
let config_file = Some(Path::new(
918-
"tests/config/style-edition/version-style-edition",
919-
));
920-
let config = get_config(config_file, Some(options));
921-
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
922-
}
923-
924-
#[nightly_only_test]
925-
#[test]
926-
fn style_edition_config_file_trumps_edition_version_config() {
927-
let options = GetOptsOptions::default();
928-
let config_file = Some(Path::new(
929-
"tests/config/style-edition/version-style-edition-and-edition",
930-
));
931-
let config = get_config(config_file, Some(options));
932-
assert_eq!(config.style_edition(), StyleEdition::Edition2021);
933-
}
934-
935-
#[nightly_only_test]
936-
#[test]
937-
fn correct_defaults_for_style_edition_loaded() {
938-
let mut options = GetOptsOptions::default();
939-
options.style_edition = Some(StyleEdition::Edition2024);
940-
let config = get_config(None, Some(options));
941-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
942-
assert_eq!(config.overflow_delimited_expr(), true);
943-
}
944-
945-
#[nightly_only_test]
946-
#[test]
947-
fn style_edition_defaults_overridden_from_config() {
948-
let options = GetOptsOptions::default();
949-
let config_file = Some(Path::new("tests/config/style-edition/overrides"));
950-
let config = get_config(config_file, Some(options));
951-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
952-
assert_eq!(config.overflow_delimited_expr(), false);
953-
}
954-
955-
#[nightly_only_test]
956-
#[test]
957-
fn style_edition_defaults_overridden_from_cli() {
958-
let mut options = GetOptsOptions::default();
959-
let config_file = Some(Path::new("tests/config/style-edition/just-style-edition"));
960-
options.inline_config =
961-
HashMap::from([("overflow_delimited_expr".to_owned(), "false".to_owned())]);
962-
let config = get_config(config_file, Some(options));
963-
assert_eq!(config.style_edition(), StyleEdition::Edition2024);
964-
assert_eq!(config.overflow_delimited_expr(), false);
965-
}
966-
}

src/chains.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use rustc_span::{BytePos, Span, symbol};
6363
use tracing::debug;
6464

6565
use crate::comment::{CharClasses, FullCodeCharKind, RichChar, rewrite_comment};
66-
use crate::config::{IndentStyle, StyleEdition};
66+
use crate::config::IndentStyle;
6767
use crate::expr::rewrite_call;
6868
use crate::lists::extract_pre_comment;
6969
use crate::macros::convert_try_mac;
@@ -297,15 +297,10 @@ impl Rewrite for ChainItem {
297297
Self::rewrite_method_call(segment.ident, types, exprs, self.span, context, shape)?
298298
}
299299
ChainItemKind::StructField(ident) => format!(".{}", rewrite_ident(context, ident)),
300-
ChainItemKind::TupleField(ident, nested) => format!(
301-
"{}.{}",
302-
if nested && context.config.style_edition() <= StyleEdition::Edition2021 {
303-
" "
304-
} else {
305-
""
306-
},
307-
rewrite_ident(context, ident)
308-
),
300+
// FIXME(new): why is `nested` unused here?
301+
ChainItemKind::TupleField(ident, _nested) => {
302+
format!(".{}", rewrite_ident(context, ident))
303+
}
309304
ChainItemKind::Await => ".await".to_owned(),
310305
ChainItemKind::Comment(ref comment, _) => {
311306
rewrite_comment(comment, false, shape, context.config)?

src/closures.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use thin_vec::thin_vec;
44
use tracing::debug;
55

66
use crate::attr::get_attrs_from_stmt;
7-
use crate::config::StyleEdition;
87
use crate::config::lists::*;
98
use crate::expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond};
109
use crate::items::{span_hi_for_param, span_lo_for_param};
@@ -447,18 +446,20 @@ fn is_block_closure_forced(context: &RewriteContext<'_>, expr: &ast::Expr) -> bo
447446
if context.inside_macro() {
448447
false
449448
} else {
450-
is_block_closure_forced_inner(expr, context.config.style_edition())
449+
is_block_closure_forced_inner(expr)
451450
}
452451
}
453452

454-
fn is_block_closure_forced_inner(expr: &ast::Expr, style_edition: StyleEdition) -> bool {
453+
fn is_block_closure_forced_inner(expr: &ast::Expr) -> bool {
455454
match expr.kind {
456-
ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop { .. } => true,
457-
ast::ExprKind::Loop(..) if style_edition >= StyleEdition::Edition2024 => true,
455+
ast::ExprKind::If(..)
456+
| ast::ExprKind::While(..)
457+
| ast::ExprKind::ForLoop { .. }
458+
| ast::ExprKind::Loop(..) => true,
458459
ast::ExprKind::AddrOf(_, _, ref expr)
459460
| ast::ExprKind::Try(ref expr)
460461
| ast::ExprKind::Unary(_, ref expr)
461-
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, style_edition),
462+
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr),
462463
_ => false,
463464
}
464465
}

0 commit comments

Comments
 (0)