Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 996d5e8

Browse files
authored
Fix shape when formatting return or break expr on statement position (rust-lang#3259)
1 parent 09c9cd4 commit 996d5e8

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ matrix:
3737
allow_failures:
3838
# Doesn't build - seems to be because of an option
3939
- env: INTEGRATION=packed_simd
40-
# Test failure
41-
- env: INTEGRATION=rust-clippy
40+
# Doesn't build - a temporal build failure due to breaking changes in the nightly compilre
41+
- env: INTEGRATION=rust-semverver
4242

4343
script:
4444
- |

src/expr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use types::{rewrite_path, PathContext};
4141
use utils::{
4242
colon_spaces, contains_skip, count_newlines, first_line_ends_with, inner_attributes,
4343
last_line_extendable, last_line_width, mk_sp, outer_attributes, ptr_vec_to_ref_vec,
44-
semicolon_for_stmt, wrap_str,
44+
semicolon_for_expr, semicolon_for_stmt, wrap_str,
4545
};
4646
use vertical::rewrite_with_alignment;
4747
use visitor::FmtVisitor;
@@ -69,6 +69,11 @@ pub fn format_expr(
6969
if contains_skip(&*expr.attrs) {
7070
return Some(context.snippet(expr.span()).to_owned());
7171
}
72+
let shape = if expr_type == ExprType::Statement && semicolon_for_expr(context, expr) {
73+
shape.sub_width(1)?
74+
} else {
75+
shape
76+
};
7277

7378
let expr_rw = match expr.node {
7479
ast::ExprKind::Array(ref expr_vec) => rewrite_array(

tests/source/expr.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,20 @@ fn issue_3003() {
462462
.iter()
463463
.collect();
464464
}
465+
466+
fn issue3226() {
467+
{
468+
{
469+
{
470+
return Err(ErrorKind::ManagementInterfaceError("Server exited unexpectedly").into())
471+
}
472+
}
473+
}
474+
{
475+
{
476+
{
477+
break Err(ErrorKind::ManagementInterfaceError("Server exited unexpectedlyy").into())
478+
}
479+
}
480+
}
481+
}

tests/target/expr.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,3 +541,24 @@ fn issue_3003() {
541541
.iter()
542542
.collect();
543543
}
544+
545+
fn issue3226() {
546+
{
547+
{
548+
{
549+
return Err(
550+
ErrorKind::ManagementInterfaceError("Server exited unexpectedly").into(),
551+
);
552+
}
553+
}
554+
}
555+
{
556+
{
557+
{
558+
break Err(
559+
ErrorKind::ManagementInterfaceError("Server exited unexpectedlyy").into(),
560+
);
561+
}
562+
}
563+
}
564+
}

0 commit comments

Comments
 (0)