Skip to content
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
4 changes: 1 addition & 3 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,7 @@ impl UseTree {
style_edition,
});
}
UseTreeKind::Nested {
items: ref list, ..
} => {
UseTreeKind::Nested { items: ref list, .. } => {
// Extract comments between nested use items.
// This needs to be done before sorting use items.
let items = itemize_list(
Expand Down
16 changes: 15 additions & 1 deletion src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,22 @@ fn rewrite_struct_pat(
fields_str.push_str("..");
}

// one_line_width was reduced by ellipsis_str.len() via struct_lit_shape,
// but fields_str now includes those chars after the ellipsis block above.
let adjusted_one_line_width = if ellipsis {
one_line_width + ellipsis_str.len()
} else {
one_line_width
};
// ast::Pat doesn't have attrs so use &[]
let fields_str = wrap_struct_field(context, &[], &fields_str, shape, v_shape, one_line_width)?;
let fields_str = wrap_struct_field(
context,
&[],
&fields_str,
shape,
v_shape,
adjusted_one_line_width,
)?;
Ok(format!("{path_str} {{{fields_str}}}"))
}

Expand Down
8 changes: 1 addition & 7 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
let indent = self.block_indent;
let block;
let rewrite = match fk {
visit::FnKind::Fn(
_,
_,
ast::Fn {
body: Some(ref b), ..
},
) => {
visit::FnKind::Fn(_, _, ast::Fn { body: Some(ref b), .. }) => {
block = b;
self.rewrite_fn_before_block(
indent,
Expand Down
13 changes: 13 additions & 0 deletions tests/source/issue-6827.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
// case 1: fits on one line
x = X { field1, field2, xx };
let X { field1, field2, .. } = x;

// case 2: literal is too wide (vertical), pattern should be single-line
x = X { field1, field2x, xx };
let X { field1, field2x, .. } = x;

// case 3: both literal and pattern are too wide — both vertical
x = X { field1, field2, field3, xx };
let X { field1, field2, field3, .. } = x;
}
8 changes: 1 addition & 7 deletions tests/target/configs/single_line_let_else_max_width/100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ fn main() {
return Ok(None);
};

let Stmt::Expr(
Expr::Call(ExprCall {
args: some_args, ..
}),
_,
) = last_stmt
else {
let Stmt::Expr(Expr::Call(ExprCall { args: some_args, .. }), _) = last_stmt else {
return Err(Error::new(
last_stmt.span(),
"expected last expression to be `Some(match (..) { .. })`",
Expand Down
8 changes: 1 addition & 7 deletions tests/target/configs/single_line_let_else_max_width/50.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ fn main() {
return Ok(None);
};

let Stmt::Expr(
Expr::Call(ExprCall {
args: some_args, ..
}),
_,
) = last_stmt
else {
let Stmt::Expr(Expr::Call(ExprCall { args: some_args, .. }), _) = last_stmt else {
return Err(Error::new(
last_stmt.span(),
"expected last expression to be `Some(match (..) { .. })`",
Expand Down
8 changes: 1 addition & 7 deletions tests/target/configs/single_line_let_else_max_width/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ fn main() {
return Ok(None);
};

let Stmt::Expr(
Expr::Call(ExprCall {
args: some_args, ..
}),
_,
) = last_stmt
else {
let Stmt::Expr(Expr::Call(ExprCall { args: some_args, .. }), _) = last_stmt else {
return Err(Error::new(
last_stmt.span(),
"expected last expression to be `Some(match (..) { .. })`",
Expand Down
27 changes: 27 additions & 0 deletions tests/target/issue-6827.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fn main() {
// case 1: fits on one line
x = X { field1, field2, xx };
let X { field1, field2, .. } = x;

// case 2: literal is too wide (vertical), pattern should be single-line
x = X {
field1,
field2x,
xx,
};
let X { field1, field2x, .. } = x;

// case 3: both literal and pattern are too wide — both vertical
x = X {
field1,
field2,
field3,
xx,
};
let X {
field1,
field2,
field3,
..
} = x;
}
6 changes: 3 additions & 3 deletions tests/target/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,9 @@ fn issue_3030() {

fn issue_3005() {
match *token {
Token::Dimension {
value, ref unit, ..
} if num_context.is_ok(context.parsing_mode, value) => {
Token::Dimension { value, ref unit, .. }
if num_context.is_ok(context.parsing_mode, value) =>
{
return NoCalcLength::parse_dimension(context, value, unit)
.map(LengthOrPercentage::Length)
.map_err(|()| location.new_unexpected_token_error(token.clone()));
Expand Down
Loading