Skip to content

Commit 3126770

Browse files
Apply review comments
1 parent 8f944d0 commit 3126770

File tree

10 files changed

+33
-17
lines changed

10 files changed

+33
-17
lines changed

Configurations.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -2780,32 +2780,31 @@ See also: [`match_block_trailing_comma`](#match_block_trailing_comma).
27802780

27812781
Add trailing semicolon after break, continue and return
27822782

2783-
- **Default value**: `preserve`
2784-
- **Possible values**: `always`, `never`, `preserve`
2783+
- **Default value**: `Preserve`
2784+
- **Possible values**: `Preserve`, `Always`, `Never`
27852785
- **Stable**: No (tracking issue: [#3378](https://github.com/rust-lang/rustfmt/issues/3378))
27862786

2787-
#### `always` (default):
2787+
#### `Preserve` (default):
27882788
```rust
27892789
fn foo() -> usize {
27902790
return 0;
27912791
}
2792-
```
27932792

2794-
#### `never`:
2795-
```rust
2796-
fn foo() -> usize {
2793+
fn bar() -> usize {
27972794
return 0
27982795
}
27992796
```
28002797

2801-
2802-
#### `preserve`:
2798+
#### `Always`:
28032799
```rust
28042800
fn foo() -> usize {
28052801
return 0;
28062802
}
2803+
```
28072804

2808-
fn bar() -> usize {
2805+
#### `Never`:
2806+
```rust
2807+
fn foo() -> usize {
28092808
return 0
28102809
}
28112810
```

src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) fn format_expr(
6464
if contains_skip(&*expr.attrs) {
6565
return Some(context.snippet(expr.span()).to_owned());
6666
}
67-
let shape = if expr_type == ExprType::Statement
67+
let shape = if context.config.version() == Version::One && expr_type == ExprType::Statement
6868
&& semicolon_for_expr_extra_hacky_double_counted_spacing(context, expr)
6969
{
7070
shape.sub_width(1)?

src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ pub(crate) fn semicolon_for_expr(context: &RewriteContext<'_>, expr: &ast::Expr)
290290
}
291291
}
292292

293-
/// Previously, we used to have `trailing_semicolon = always` enabled, and due to
293+
/// Previously, we used to have `trailing_semicolon = Always` enabled, and due to
294294
/// a bug between `format_stmt` and `format_expr`, we used to subtract the size of
295295
/// `;` *TWICE* from the shape. This means that an expr that would fit onto a line
296296
/// of, e.g. 99 (limit 100) after subtracting one for the semicolon would still be
297297
/// wrapped.
298298
///
299299
/// This function reimplements the old heuristic of double counting the "phantom"
300300
/// semicolon that should have already been accounted for, to not break existing
301-
/// formatting with the `trailing_semicolon = preserve` behavior.
301+
/// formatting with the `trailing_semicolon = Preserve` behavior for Version = One.
302302
#[inline]
303303
pub(crate) fn semicolon_for_expr_extra_hacky_double_counted_spacing(
304304
context: &RewriteContext<'_>,
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rustfmt-version: One
2+
3+
fn main() {
4+
return hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(arg);
5+
}

tests/target/configs/trailing_semicolon/always.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-trailing_semicolon: always
1+
// rustfmt-trailing_semicolon: Always
22

33
#![feature(loop_break_value)]
44

tests/target/configs/trailing_semicolon/never.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-trailing_semicolon: never
1+
// rustfmt-trailing_semicolon: Never
22

33
#![feature(loop_break_value)]
44

tests/target/configs/trailing_semicolon/preserve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-trailing_semicolon: never
1+
// rustfmt-trailing_semicolon: Never
22

33
#![feature(loop_break_value)]
44

tests/target/issue-5797/retain_trailing_semicolon.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-trailing_semicolon: never
1+
// rustfmt-trailing_semicolon: Never
22

33
fn foo() {}
44
fn main() {
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rustfmt-version: One
2+
3+
fn main() {
4+
return hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(
5+
arg,
6+
);
7+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rustfmt-version: Two
2+
3+
fn main() {
4+
return hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(arg);
5+
}

0 commit comments

Comments
 (0)