diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 5db0352107a..08134322439 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -435,7 +435,7 @@ macro_rules! create_config { self.match_arm_wrapping.2 = if self.match_arm_blocks() { MatchArmWrapping::Default } else { - MatchArmWrapping::NoBlockFirstLine + MatchArmWrapping::FitFirstLine }; } } diff --git a/src/config/mod.rs b/src/config/mod.rs index fd3c27237ca..96469bd6d56 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -745,10 +745,7 @@ make_backup = false match_arm_blocks = false "#; let config = Config::from_toml(toml, Path::new("")).unwrap(); - assert_eq!( - config.match_arm_wrapping(), - MatchArmWrapping::NoBlockFirstLine - ); + assert_eq!(config.match_arm_wrapping(), MatchArmWrapping::FitFirstLine); } #[test] @@ -786,15 +783,12 @@ make_backup = false } let toml = r#" unstable_features = true - match_arm_wrapping = "NoBlockFirstLine" + match_arm_wrapping = "FitFirstLine" "#; let mut config = Config::from_toml(toml, Path::new("")).unwrap(); config.override_value("match_arm_blocks", "false"); // no effect: the new option always takes precedence - assert_eq!( - config.match_arm_wrapping(), - MatchArmWrapping::NoBlockFirstLine - ); + assert_eq!(config.match_arm_wrapping(), MatchArmWrapping::FitFirstLine); } } diff --git a/src/config/options.rs b/src/config/options.rs index d58c8ed0f3b..ca80834c19a 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -450,9 +450,12 @@ pub enum MatchArmWrapping { Default, /// Same as Default, except don't block wrap match arms when the opening line of its body /// can't fit on the same line as the `=>`. - NoBlockFirstLine, + FitFirstLine, /// Always block wrap match arms Always, /// Preserve the block wrapping on match arms Preserve, + /// Same as Default, except wrap the match arm if the entire body cannot fit on the same line + /// as the `=>`. + FitEntireBody, } diff --git a/src/matches.rs b/src/matches.rs index f9f2b5b0b07..5a994f353d1 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -420,7 +420,7 @@ fn rewrite_match_body( let indent_str = shape.indent.to_string_with_newline(context.config); let (body_prefix, body_suffix) = match context.config.match_arm_wrapping() { - MatchArmWrapping::NoBlockFirstLine => ("", String::from(",")), + MatchArmWrapping::FitFirstLine => ("", String::from(",")), _ if !context.inside_macro() => { let comma = if context.config.match_block_trailing_comma() { "," @@ -501,7 +501,9 @@ fn rewrite_match_body( match (orig_body, next_line_body) { (Some(ref orig_str), Some(ref next_line_str)) - if prefer_next_line(orig_str, next_line_str, RhsTactics::Default) => + if prefer_next_line(orig_str, next_line_str, RhsTactics::Default) + || (context.config.match_arm_wrapping() == MatchArmWrapping::FitEntireBody + && orig_str.contains('\n')) => { combine_next_line_body(next_line_str) }