Skip to content

Commit db12943

Browse files
committed
feat: add FitEntireBody as new match_arm_wrapping option, and rename NoBlockFirstLine to FitFirstLine (rust-lang#4896)
1 parent 1ee0c72 commit db12943

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

Diff for: src/config/config_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ macro_rules! create_config {
435435
self.match_arm_wrapping.2 = if self.match_arm_blocks() {
436436
MatchArmWrapping::Default
437437
} else {
438-
MatchArmWrapping::NoBlockFirstLine
438+
MatchArmWrapping::FitFirstLine
439439
};
440440
}
441441
}

Diff for: src/config/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,7 @@ make_backup = false
745745
match_arm_blocks = false
746746
"#;
747747
let config = Config::from_toml(toml, Path::new("")).unwrap();
748-
assert_eq!(
749-
config.match_arm_wrapping(),
750-
MatchArmWrapping::NoBlockFirstLine
751-
);
748+
assert_eq!(config.match_arm_wrapping(), MatchArmWrapping::FitFirstLine);
752749
}
753750

754751
#[test]
@@ -786,15 +783,12 @@ make_backup = false
786783
}
787784
let toml = r#"
788785
unstable_features = true
789-
match_arm_wrapping = "NoBlockFirstLine"
786+
match_arm_wrapping = "FitFirstLine"
790787
"#;
791788
let mut config = Config::from_toml(toml, Path::new("")).unwrap();
792789
config.override_value("match_arm_blocks", "false");
793790
// no effect: the new option always takes precedence
794-
assert_eq!(
795-
config.match_arm_wrapping(),
796-
MatchArmWrapping::NoBlockFirstLine
797-
);
791+
assert_eq!(config.match_arm_wrapping(), MatchArmWrapping::FitFirstLine);
798792
}
799793
}
800794

Diff for: src/config/options.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,12 @@ pub enum MatchArmWrapping {
450450
Default,
451451
/// Same as Default, except don't block wrap match arms when the opening line of its body
452452
/// can't fit on the same line as the `=>`.
453-
NoBlockFirstLine,
453+
FitFirstLine,
454454
/// Always block wrap match arms
455455
Always,
456456
/// Preserve the block wrapping on match arms
457457
Preserve,
458+
/// Same as Default, except wrap the match arm if the entire body cannot fit on the same line
459+
/// as the `=>`.
460+
FitEntireBody,
458461
}

Diff for: src/matches.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn rewrite_match_body(
420420

421421
let indent_str = shape.indent.to_string_with_newline(context.config);
422422
let (body_prefix, body_suffix) = match context.config.match_arm_wrapping() {
423-
MatchArmWrapping::NoBlockFirstLine => ("", String::from(",")),
423+
MatchArmWrapping::FitFirstLine => ("", String::from(",")),
424424
_ if !context.inside_macro() => {
425425
let comma = if context.config.match_block_trailing_comma() {
426426
","
@@ -501,7 +501,9 @@ fn rewrite_match_body(
501501

502502
match (orig_body, next_line_body) {
503503
(Some(ref orig_str), Some(ref next_line_str))
504-
if prefer_next_line(orig_str, next_line_str, RhsTactics::Default) =>
504+
if prefer_next_line(orig_str, next_line_str, RhsTactics::Default)
505+
|| (context.config.match_arm_wrapping() == MatchArmWrapping::FitEntireBody
506+
&& orig_str.contains('\n')) =>
505507
{
506508
combine_next_line_body(next_line_str)
507509
}

0 commit comments

Comments
 (0)