diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c07e15f4c8..fcaf454dc55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,16 @@ ## [Unreleased] -## [1.4.22] 2020-10-30 +## [1.4.24] 2020-11-05 + +### Changed + +- Block wrapped match arm bodies containing a single macro call expression are no longer flattened ([#4496](https://github.com/rust-lang/rustfmt/pull/4496)). This allows programmer discretion so that the block wrapping can be preserved in cases where needed to prevent issues in expansion, such as with trailing semicolons, and aligns with updated [Style Guide guidance](https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/expressions.md#macro-call-expressions) for such scenarios. + +### Fixed +- Remove useless `deprecated` attribute on a trait impl block in the rustfmt lib, as these now trigger errors ([rust-lang/rust/#78626](https://github.com/rust-lang/rust/pull/78626)) + +## [1.4.23] 2020-10-30 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 7f3536cbe3a..d7a586aacee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1237,7 +1237,7 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "1.4.23" +version = "1.4.24" dependencies = [ "annotate-snippets 0.6.1", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index c22e1b3d12c..23df8f28c16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustfmt-nightly" -version = "1.4.23" +version = "1.4.24" authors = ["Nicholas Cameron ", "The Rustfmt developers"] description = "Tool to find and fix Rust formatting issues" repository = "https://github.com/rust-lang/rustfmt" diff --git a/src/lib.rs b/src/lib.rs index 2ba476466ab..c6a9654d4d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,7 +273,9 @@ impl FormatReport { } } -#[deprecated(note = "Use FormatReportFormatter instead")] +/// Deprecated - Use FormatReportFormatter instead +// https://github.com/rust-lang/rust/issues/78625 +// https://github.com/rust-lang/rust/issues/39935 impl fmt::Display for FormatReport { // Prints all the formatting errors. fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { diff --git a/src/matches.rs b/src/matches.rs index 7b691bf6100..a43aed09ef5 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -284,6 +284,15 @@ fn rewrite_match_arm( ) } +fn stmt_is_expr_mac(stmt: &ast::Stmt) -> bool { + if let ast::StmtKind::Expr(expr) = &stmt.kind { + if let ast::ExprKind::MacCall(_) = &expr.kind { + return true; + } + } + false +} + fn block_can_be_flattened<'a>( context: &RewriteContext<'_>, expr: &'a ast::Expr, @@ -292,7 +301,8 @@ fn block_can_be_flattened<'a>( ast::ExprKind::Block(ref block, _) if !is_unsafe_block(block) && !context.inside_macro() - && is_simple_block(context, block, Some(&expr.attrs)) => + && is_simple_block(context, block, Some(&expr.attrs)) + && !stmt_is_expr_mac(&block.stmts[0]) => { Some(&*block) } diff --git a/tests/target/configs/match_arm_blocks/false.rs b/tests/target/configs/match_arm_blocks/false.rs index 4d53a96a7b7..7a9834168c7 100644 --- a/tests/target/configs/match_arm_blocks/false.rs +++ b/tests/target/configs/match_arm_blocks/false.rs @@ -5,6 +5,8 @@ fn main() { match lorem { true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), - false => println!("{}", sit), + false => { + println!("{}", sit) + } } } diff --git a/tests/target/configs/match_arm_blocks/true.rs b/tests/target/configs/match_arm_blocks/true.rs index d75ef03397a..eb9e34059c7 100644 --- a/tests/target/configs/match_arm_blocks/true.rs +++ b/tests/target/configs/match_arm_blocks/true.rs @@ -6,6 +6,8 @@ fn main() { true => { foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x) } - false => println!("{}", sit), + false => { + println!("{}", sit) + } } } diff --git a/tests/target/issue-2936.rs b/tests/target/issue-2936.rs index 3d5207597c4..1d6eb6d6052 100644 --- a/tests/target/issue-2936.rs +++ b/tests/target/issue-2936.rs @@ -11,7 +11,9 @@ impl Something for AStruct { let err: &CStr = match err.kind { ParseErrorKind::Custom(StyleParseErrorKind::MediaQueryExpectedFeatureName( .., - )) => cstr!("PEMQExpectedFeatureName"), + )) => { + cstr!("PEMQExpectedFeatureName") + } }; } }; diff --git a/tests/target/match.rs b/tests/target/match.rs index 92abda9752e..123c4c55f6a 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -166,9 +166,15 @@ fn issue355() { a => println!("a", b), b => vec![1, 2], c => vec![3; 4], - d => println!("a", b), - e => vec![1, 2], - f => vec![3; 4], + d => { + println!("a", b) + } + e => { + vec![1, 2] + } + f => { + vec![3; 4] + } h => println!("a", b), // h comment i => vec![1, 2], // i comment j => vec![3; 4], // j comment