Also return the method spans in utils::method_calls

This commit is contained in:
flip1995 2019-08-28 10:41:06 +02:00
parent 945d4cf69f
commit 832c0830ec
No known key found for this signature in database
GPG key ID: 693086869D506637

View file

@ -339,25 +339,27 @@ pub fn resolve_node(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> Res {
/// Returns the method names and argument list of nested method call expressions that make up /// Returns the method names and argument list of nested method call expressions that make up
/// `expr`. /// `expr`.
pub fn method_calls(expr: &Expr, max_depth: usize) -> (Vec<Symbol>, Vec<&[Expr]>) { pub fn method_calls(expr: &Expr, max_depth: usize) -> (Vec<Symbol>, Vec<&[Expr]>, Vec<Span>) {
let mut method_names = Vec::with_capacity(max_depth); let mut method_names = Vec::with_capacity(max_depth);
let mut arg_lists = Vec::with_capacity(max_depth); let mut arg_lists = Vec::with_capacity(max_depth);
let mut spans = Vec::with_capacity(max_depth);
let mut current = expr; let mut current = expr;
for _ in 0..max_depth { for _ in 0..max_depth {
if let ExprKind::MethodCall(path, _, args) = &current.node { if let ExprKind::MethodCall(path, span, args) = &current.node {
if args.iter().any(|e| e.span.from_expansion()) { if args.iter().any(|e| e.span.from_expansion()) {
break; break;
} }
method_names.push(path.ident.name); method_names.push(path.ident.name);
arg_lists.push(&**args); arg_lists.push(&**args);
spans.push(*span);
current = &args[0]; current = &args[0];
} else { } else {
break; break;
} }
} }
(method_names, arg_lists) (method_names, arg_lists, spans)
} }
/// Matches an `Expr` against a chain of methods, and return the matched `Expr`s. /// Matches an `Expr` against a chain of methods, and return the matched `Expr`s.