Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect trailing semicolon setting for last statements #6182

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -110,14 +104,14 @@ fn format_stmt(
shape: Shape,
stmt: &ast::Stmt,
expr_type: ExprType,
is_last_expr: bool,
is_last: bool,
) -> Option<String> {
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 {
""
Expand Down
15 changes: 15 additions & 0 deletions tests/source/trailing-semicolon.rs
Original file line number Diff line number Diff line change
@@ -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()
}
15 changes: 15 additions & 0 deletions tests/target/trailing-semicolon.rs
Original file line number Diff line number Diff line change
@@ -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()
}
Loading