From 93373ca9dc8506d674a07d15e08c36199a345d48 Mon Sep 17 00:00:00 2001 From: Radim Date: Fri, 7 Feb 2025 00:05:34 +0100 Subject: [PATCH] Fix All system_tests pass now! --- src/expr.rs | 2 +- src/test/mod.rs | 64 +++++++++---------- src/vertical.rs | 4 -- ...ply_nested_struct_with_long_field_names.rs | 2 +- .../struct_with_long_field_names.rs | 2 +- ...ply_nested_struct_with_long_field_names.rs | 2 +- .../struct_with_long_field_names.rs | 2 +- 7 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index f7d06a15198..07336518ab1 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1656,7 +1656,7 @@ fn rewrite_struct_lit<'a>( let one_line_width = h_shape.map_or(0, |shape| shape.width); let body_lo = context.snippet_provider.span_after(span, "{"); - let fields_str = if context.config.struct_field_align_threshold() > 0 { + let fields_str = if !fields.is_empty() && context.config.struct_field_align_threshold() > 0 { rewrite_with_alignment( fields, context, diff --git a/src/test/mod.rs b/src/test/mod.rs index 924dd93d72e..b1991bc746f 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -181,12 +181,12 @@ fn system_tests() { init_log(); run_test_with(&TestSetting::default(), || { // Get all files in the tests/source directory. - // let files = get_test_files(Path::new("tests/source"), true); - let files = vec![ - // PathBuf::from("tests/source/issue_6096.rs"), - // PathBuf::from("tests/source/issue_6080.rs") - PathBuf::from("tests/source/configs/struct_field_align_threshold/20.rs") - ]; + let files = get_test_files(Path::new("tests/source"), true); + // let files = vec![ + // PathBuf::from("tests/source/issue_6096.rs"), + // PathBuf::from("tests/source/issue_6080.rs"), + // PathBuf::from("tests/source/issue-4926/deeply_nested_struct_with_long_field_names.rs"), + // ]; // dbg!(&files); let (_reports, count, fails) = check_files(files, &None); @@ -270,21 +270,18 @@ fn modified_test() { }); } - assert_eq!( - chunks, - vec![ - ModifiedChunk { - line_number_orig: 4, - lines_removed: 4, - lines: vec!["fn blah() {}".into()], - }, - ModifiedChunk { - line_number_orig: 9, - lines_removed: 6, - lines: vec!["#[cfg(a, b)]".into(), "fn main() {}".into()], - }, - ], - ); + assert_eq!(chunks, vec![ + ModifiedChunk { + line_number_orig: 4, + lines_removed: 4, + lines: vec!["fn blah() {}".into()], + }, + ModifiedChunk { + line_number_orig: 9, + lines_removed: 6, + lines: vec!["#[cfg(a, b)]".into(), "fn main() {}".into()], + }, + ],); } // Helper function for comparing the results of rustfmt @@ -950,20 +947,17 @@ fn get_target(file_name: &Path, target: Option<&str>) -> PathBuf { fn rustfmt_diff_make_diff_tests() { init_log(); let diff = make_diff("a\nb\nc\nd", "a\ne\nc\nd", 3); - assert_eq!( - diff, - vec![Mismatch { - line_number: 1, - line_number_orig: 1, - lines: vec![ - DiffLine::Context("a".into()), - DiffLine::Resulting("b".into()), - DiffLine::Expected("e".into()), - DiffLine::Context("c".into()), - DiffLine::Context("d".into()), - ], - }] - ); + assert_eq!(diff, vec![Mismatch { + line_number: 1, + line_number_orig: 1, + lines: vec![ + DiffLine::Context("a".into()), + DiffLine::Resulting("b".into()), + DiffLine::Expected("e".into()), + DiffLine::Context("c".into()), + DiffLine::Context("d".into()), + ], + }]); } #[test] diff --git a/src/vertical.rs b/src/vertical.rs index 9840a592106..a40298900b5 100644 --- a/src/vertical.rs +++ b/src/vertical.rs @@ -235,10 +235,6 @@ fn rewrite_aligned_items_inner( let has_base_or_rest = match struct_rest { Some(rest) => match rest { - // ast::StructRest::None if fields.is_empty() => return format!("{path_str} {{}}"), - // ast::StructRest::Rest(_) if fields.is_empty() => { - // return Ok(format!("{path_str} {{ .. }}")); - // } ast::StructRest::Rest(_) | ast::StructRest::Base(_) => true, _ => false, }, diff --git a/tests/source/issue-4926/deeply_nested_struct_with_long_field_names.rs b/tests/source/issue-4926/deeply_nested_struct_with_long_field_names.rs index 516699fa2b8..40b0e2ffc84 100644 --- a/tests/source/issue-4926/deeply_nested_struct_with_long_field_names.rs +++ b/tests/source/issue-4926/deeply_nested_struct_with_long_field_names.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_field_align_threshold: 30 +// rustfmt-struct_field_align_threshold: 27 struct X { really_really_long_field_a: i32, diff --git a/tests/source/issue-4926/struct_with_long_field_names.rs b/tests/source/issue-4926/struct_with_long_field_names.rs index b8a37f0714e..27db3f62798 100644 --- a/tests/source/issue-4926/struct_with_long_field_names.rs +++ b/tests/source/issue-4926/struct_with_long_field_names.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_field_align_threshold: 30 +// rustfmt-struct_field_align_threshold: 27 struct X { really_really_long_field_a: i32, diff --git a/tests/target/issue-4926/deeply_nested_struct_with_long_field_names.rs b/tests/target/issue-4926/deeply_nested_struct_with_long_field_names.rs index c7bc7f7296d..958e92bdc1a 100644 --- a/tests/target/issue-4926/deeply_nested_struct_with_long_field_names.rs +++ b/tests/target/issue-4926/deeply_nested_struct_with_long_field_names.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_field_align_threshold: 30 +// rustfmt-struct_field_align_threshold: 27 struct X { really_really_long_field_a: i32, diff --git a/tests/target/issue-4926/struct_with_long_field_names.rs b/tests/target/issue-4926/struct_with_long_field_names.rs index ac4674ab5d5..eabb8ff0040 100644 --- a/tests/target/issue-4926/struct_with_long_field_names.rs +++ b/tests/target/issue-4926/struct_with_long_field_names.rs @@ -1,4 +1,4 @@ -// rustfmt-struct_field_align_threshold: 30 +// rustfmt-struct_field_align_threshold: 27 struct X { really_really_long_field_a: i32,