Skip to content

Commit 01c1f99

Browse files
committed
Fallout from removing TupField
1 parent aa7fc4c commit 01c1f99

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/chains.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext) -> Option<ast::Exp
393393
ast::ExprKind::MethodCall(_, ref expressions) => {
394394
Some(convert_try(&expressions[0], context))
395395
}
396-
ast::ExprKind::TupField(ref subexpr, _)
397396
| ast::ExprKind::Field(ref subexpr, _)
398397
| ast::ExprKind::Try(ref subexpr) => Some(convert_try(subexpr, context)),
399398
_ => None,
@@ -440,19 +439,28 @@ fn rewrite_chain_subexpr(
440439
};
441440
rewrite_method_call(segment.ident, types, expressions, span, context, shape)
442441
}
443-
ast::ExprKind::Field(_, ref field) => rewrite_element(format!(".{}", field.name)),
444-
ast::ExprKind::TupField(ref expr, ref field) => {
445-
let space = match expr.node {
446-
ast::ExprKind::TupField(..) => " ",
447-
_ => "",
442+
ast::ExprKind::Field(ref nested, ref field) => {
443+
let space = if is_tup_field_access(expr) && is_tup_field_access(nested) {
444+
" "
445+
} else {
446+
""
448447
};
449-
rewrite_element(format!("{}.{}", space, field.node))
448+
rewrite_element(format!("{}.{}", space, field.name))
450449
}
451450
ast::ExprKind::Try(_) => rewrite_element(String::from("?")),
452451
_ => unreachable!(),
453452
}
454453
}
455454

455+
fn is_tup_field_access(expr: &ast::Expr) -> bool {
456+
match expr.node {
457+
ast::ExprKind::Field(_, ref field) => {
458+
field.name.to_string().chars().all(|c| c.is_digit(10))
459+
}
460+
_ => false,
461+
}
462+
}
463+
456464
// Determines if we can continue formatting a given expression on the same line.
457465
fn is_continuable(expr: &ast::Expr) -> bool {
458466
match expr.node {

src/expr.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ pub fn format_expr(
178178
}
179179
ast::ExprKind::Try(..)
180180
| ast::ExprKind::Field(..)
181-
| ast::ExprKind::TupField(..)
182181
| ast::ExprKind::MethodCall(..) => rewrite_chain(expr, context, shape),
183182
ast::ExprKind::Mac(ref mac) => {
184183
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
@@ -1349,7 +1348,6 @@ fn is_simple_expr(expr: &ast::Expr) -> bool {
13491348
| ast::ExprKind::Cast(ref expr, _)
13501349
| ast::ExprKind::Field(ref expr, _)
13511350
| ast::ExprKind::Try(ref expr)
1352-
| ast::ExprKind::TupField(ref expr, _)
13531351
| ast::ExprKind::Unary(_, ref expr) => is_simple_expr(expr),
13541352
ast::ExprKind::Index(ref lhs, ref rhs) | ast::ExprKind::Repeat(ref lhs, ref rhs) => {
13551353
is_simple_expr(lhs) && is_simple_expr(rhs)

src/utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
365365
| ast::ExprKind::Assign(ref e, _)
366366
| ast::ExprKind::AssignOp(_, ref e, _)
367367
| ast::ExprKind::Field(ref e, _)
368-
| ast::ExprKind::TupField(ref e, _)
369368
| ast::ExprKind::Index(ref e, _)
370369
| ast::ExprKind::Range(Some(ref e), _, _)
371370
| ast::ExprKind::Try(ref e) => left_most_sub_expr(e),

0 commit comments

Comments
 (0)