Skip to content

Commit d5d008d

Browse files
authored
Drop trailing semicolons on item statements (#4232)
1 parent 44462b1 commit d5d008d

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/formatting/visitor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
144144
match stmt.as_ast_node().kind {
145145
ast::StmtKind::Item(ref item) => {
146146
self.visit_item(item);
147-
// Handle potential `;` after the item.
148-
self.format_missing(stmt.span().hi());
147+
// If the item requires a trailing ";" (like `struct Foo;`), we should have already
148+
// handled it. Otherwise there still may be a trailing ";", but it is unnecessary.
149+
// Drop it by fast-forwarding the visitor to the end of the item.
150+
self.last_pos = stmt.span().hi();
149151
}
150152
ast::StmtKind::Local(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Semi(..) => {
151153
let attrs = get_attrs_from_stmt(stmt.as_ast_node());

tests/source/issue-4222.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn first_function() {
2+
struct inner_item {
3+
field: u32,
4+
};
5+
struct Foo;
6+
}

tests/target/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn foo() -> bool {
9494
const fn get(&self) -> usize {
9595
5
9696
}
97-
};
97+
}
9898
Foo.get()
9999
}];
100100
}

tests/target/issue-4222.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn first_function() {
2+
struct inner_item {
3+
field: u32,
4+
}
5+
struct Foo;
6+
}

0 commit comments

Comments
 (0)