Do not consider method call receiver as an argument in AST.

This commit is contained in:
Camille GILLOT 2022-08-07 15:21:11 +02:00
parent af72f7a17f
commit 76be14b5ca

View File

@ -145,7 +145,7 @@ fn is_tup_field_access(expr: &ast::Expr) -> bool {
fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
let (kind, span) = match expr.kind {
ast::ExprKind::MethodCall(ref segment, ref expressions, _) => {
ast::ExprKind::MethodCall(ref segment, ref receiver, ref expressions, _) => {
let types = if let Some(ref generic_args) = segment.args {
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
data.args
@ -163,7 +163,7 @@ fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, S
} else {
vec![]
};
let span = mk_sp(expressions[0].span.hi(), expr.span.hi());
let span = mk_sp(receiver.span.hi(), expr.span.hi());
let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone());
(kind, span)
}
@ -253,7 +253,7 @@ fn rewrite_method_call(
format!("::<{}>", type_list.join(", "))
};
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
rewrite_call(context, &callee_str, &args[1..], span, shape)
rewrite_call(context, &callee_str, &args, span, shape)
}
}
@ -400,8 +400,8 @@ fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext<'_>) -> Vec<ast:
// is a try! macro, we'll convert it to shorthand when the option is set.
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
match expr.kind {
ast::ExprKind::MethodCall(_, ref expressions, _) => {
Some(Self::convert_try(&expressions[0], context))
ast::ExprKind::MethodCall(_, ref receiver, _, _) => {
Some(Self::convert_try(&receiver, context))
}
ast::ExprKind::Field(ref subexpr, _)
| ast::ExprKind::Try(ref subexpr)