mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 04:39:16 +00:00
Fallout from removing TupField
This commit is contained in:
parent
aa7fc4cdc5
commit
01c1f99e39
@ -393,7 +393,6 @@ fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext) -> Option<ast::Exp
|
|||||||
ast::ExprKind::MethodCall(_, ref expressions) => {
|
ast::ExprKind::MethodCall(_, ref expressions) => {
|
||||||
Some(convert_try(&expressions[0], context))
|
Some(convert_try(&expressions[0], context))
|
||||||
}
|
}
|
||||||
ast::ExprKind::TupField(ref subexpr, _)
|
|
||||||
| ast::ExprKind::Field(ref subexpr, _)
|
| ast::ExprKind::Field(ref subexpr, _)
|
||||||
| ast::ExprKind::Try(ref subexpr) => Some(convert_try(subexpr, context)),
|
| ast::ExprKind::Try(ref subexpr) => Some(convert_try(subexpr, context)),
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -440,19 +439,28 @@ fn rewrite_chain_subexpr(
|
|||||||
};
|
};
|
||||||
rewrite_method_call(segment.ident, types, expressions, span, context, shape)
|
rewrite_method_call(segment.ident, types, expressions, span, context, shape)
|
||||||
}
|
}
|
||||||
ast::ExprKind::Field(_, ref field) => rewrite_element(format!(".{}", field.name)),
|
ast::ExprKind::Field(ref nested, ref field) => {
|
||||||
ast::ExprKind::TupField(ref expr, ref field) => {
|
let space = if is_tup_field_access(expr) && is_tup_field_access(nested) {
|
||||||
let space = match expr.node {
|
" "
|
||||||
ast::ExprKind::TupField(..) => " ",
|
} else {
|
||||||
_ => "",
|
""
|
||||||
};
|
};
|
||||||
rewrite_element(format!("{}.{}", space, field.node))
|
rewrite_element(format!("{}.{}", space, field.name))
|
||||||
}
|
}
|
||||||
ast::ExprKind::Try(_) => rewrite_element(String::from("?")),
|
ast::ExprKind::Try(_) => rewrite_element(String::from("?")),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_tup_field_access(expr: &ast::Expr) -> bool {
|
||||||
|
match expr.node {
|
||||||
|
ast::ExprKind::Field(_, ref field) => {
|
||||||
|
field.name.to_string().chars().all(|c| c.is_digit(10))
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Determines if we can continue formatting a given expression on the same line.
|
// Determines if we can continue formatting a given expression on the same line.
|
||||||
fn is_continuable(expr: &ast::Expr) -> bool {
|
fn is_continuable(expr: &ast::Expr) -> bool {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
|
@ -178,7 +178,6 @@ pub fn format_expr(
|
|||||||
}
|
}
|
||||||
ast::ExprKind::Try(..)
|
ast::ExprKind::Try(..)
|
||||||
| ast::ExprKind::Field(..)
|
| ast::ExprKind::Field(..)
|
||||||
| ast::ExprKind::TupField(..)
|
|
||||||
| ast::ExprKind::MethodCall(..) => rewrite_chain(expr, context, shape),
|
| ast::ExprKind::MethodCall(..) => rewrite_chain(expr, context, shape),
|
||||||
ast::ExprKind::Mac(ref mac) => {
|
ast::ExprKind::Mac(ref mac) => {
|
||||||
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
|
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
|
||||||
@ -1349,7 +1348,6 @@ fn is_simple_expr(expr: &ast::Expr) -> bool {
|
|||||||
| ast::ExprKind::Cast(ref expr, _)
|
| ast::ExprKind::Cast(ref expr, _)
|
||||||
| ast::ExprKind::Field(ref expr, _)
|
| ast::ExprKind::Field(ref expr, _)
|
||||||
| ast::ExprKind::Try(ref expr)
|
| ast::ExprKind::Try(ref expr)
|
||||||
| ast::ExprKind::TupField(ref expr, _)
|
|
||||||
| ast::ExprKind::Unary(_, ref expr) => is_simple_expr(expr),
|
| ast::ExprKind::Unary(_, ref expr) => is_simple_expr(expr),
|
||||||
ast::ExprKind::Index(ref lhs, ref rhs) | ast::ExprKind::Repeat(ref lhs, ref rhs) => {
|
ast::ExprKind::Index(ref lhs, ref rhs) | ast::ExprKind::Repeat(ref lhs, ref rhs) => {
|
||||||
is_simple_expr(lhs) && is_simple_expr(rhs)
|
is_simple_expr(lhs) && is_simple_expr(rhs)
|
||||||
|
@ -365,7 +365,6 @@ pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
|
|||||||
| ast::ExprKind::Assign(ref e, _)
|
| ast::ExprKind::Assign(ref e, _)
|
||||||
| ast::ExprKind::AssignOp(_, ref e, _)
|
| ast::ExprKind::AssignOp(_, ref e, _)
|
||||||
| ast::ExprKind::Field(ref e, _)
|
| ast::ExprKind::Field(ref e, _)
|
||||||
| ast::ExprKind::TupField(ref e, _)
|
|
||||||
| ast::ExprKind::Index(ref e, _)
|
| ast::ExprKind::Index(ref e, _)
|
||||||
| ast::ExprKind::Range(Some(ref e), _, _)
|
| ast::ExprKind::Range(Some(ref e), _, _)
|
||||||
| ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
|
| ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
|
||||||
|
Loading…
Reference in New Issue
Block a user