diff --git a/src/stmt.rs b/src/stmt.rs index e3fe4ebca11..e032fffe52e 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -95,13 +95,7 @@ impl<'a> Rewrite for Stmt<'a> { } else { ExprType::Statement }; - format_stmt( - context, - shape, - self.as_ast_node(), - expr_type, - self.is_last_expr(), - ) + format_stmt(context, shape, self.as_ast_node(), expr_type, self.is_last) } } @@ -110,14 +104,14 @@ fn format_stmt( shape: Shape, stmt: &ast::Stmt, expr_type: ExprType, - is_last_expr: bool, + is_last: bool, ) -> Option { skip_out_of_file_lines_range!(context, stmt.span()); let result = match stmt.kind { ast::StmtKind::Local(ref local) => local.rewrite(context, shape), ast::StmtKind::Expr(ref ex) | ast::StmtKind::Semi(ref ex) => { - let suffix = if semicolon_for_stmt(context, stmt, is_last_expr) { + let suffix = if semicolon_for_stmt(context, stmt, is_last) { ";" } else { "" diff --git a/tests/source/trailing-semicolon.rs b/tests/source/trailing-semicolon.rs new file mode 100644 index 00000000000..812face95d6 --- /dev/null +++ b/tests/source/trailing-semicolon.rs @@ -0,0 +1,15 @@ +// rustfmt-trailing_semicolon: false + +fn main() { + println!("{}", greet()); +} + +fn greet() -> String { + return "Hello, b!".to_string(); +} + +fn foo() {} +fn main() { + return; + foo() +} diff --git a/tests/target/trailing-semicolon.rs b/tests/target/trailing-semicolon.rs new file mode 100644 index 00000000000..a853f2cedbb --- /dev/null +++ b/tests/target/trailing-semicolon.rs @@ -0,0 +1,15 @@ +// rustfmt-trailing_semicolon: false + +fn main() { + println!("{}", greet()); +} + +fn greet() -> String { + return "Hello, b!".to_string() +} + +fn foo() {} +fn main() { + return; + foo() +}