diff options
author | David Lattimore <[email protected]> | 2020-08-18 11:39:55 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-08-18 11:39:55 +0100 |
commit | 29e6238cb7330f7d29f33ff03a4ccc0a0cec9f4d (patch) | |
tree | a3d0a6811d85697b3d12b9975df318f742531f45 /crates/ssr/src/replacing.rs | |
parent | a4a504e1328111c184603ddc0b2c113ad5a5c555 (diff) |
SSR: A few small refactorings
Diffstat (limited to 'crates/ssr/src/replacing.rs')
-rw-r--r-- | crates/ssr/src/replacing.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/ssr/src/replacing.rs b/crates/ssr/src/replacing.rs index 21d0aa8a8..29284e3f1 100644 --- a/crates/ssr/src/replacing.rs +++ b/crates/ssr/src/replacing.rs | |||
@@ -1,9 +1,11 @@ | |||
1 | //! Code for applying replacement templates for matches that have previously been found. | 1 | //! Code for applying replacement templates for matches that have previously been found. |
2 | 2 | ||
3 | use crate::{resolving::ResolvedRule, Match, SsrMatches}; | 3 | use crate::{resolving::ResolvedRule, Match, SsrMatches}; |
4 | use itertools::Itertools; | ||
4 | use rustc_hash::{FxHashMap, FxHashSet}; | 5 | use rustc_hash::{FxHashMap, FxHashSet}; |
5 | use syntax::ast::{self, AstToken}; | 6 | use syntax::ast::{self, AstToken}; |
6 | use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; | 7 | use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; |
8 | use test_utils::mark; | ||
7 | use text_edit::TextEdit; | 9 | use text_edit::TextEdit; |
8 | 10 | ||
9 | /// Returns a text edit that will replace each match in `matches` with its corresponding replacement | 11 | /// Returns a text edit that will replace each match in `matches` with its corresponding replacement |
@@ -127,6 +129,7 @@ impl ReplacementRenderer<'_> { | |||
127 | && (placeholder_value.autoderef_count > 0 | 129 | && (placeholder_value.autoderef_count > 0 |
128 | || placeholder_value.autoref_kind != ast::SelfParamKind::Owned) | 130 | || placeholder_value.autoref_kind != ast::SelfParamKind::Owned) |
129 | { | 131 | { |
132 | mark::hit!(replace_autoref_autoderef_capture); | ||
130 | let ref_kind = match placeholder_value.autoref_kind { | 133 | let ref_kind = match placeholder_value.autoref_kind { |
131 | ast::SelfParamKind::Owned => "", | 134 | ast::SelfParamKind::Owned => "", |
132 | ast::SelfParamKind::Ref => "&", | 135 | ast::SelfParamKind::Ref => "&", |
@@ -206,18 +209,16 @@ fn token_is_method_call_receiver(token: &SyntaxToken) -> bool { | |||
206 | use syntax::ast::AstNode; | 209 | use syntax::ast::AstNode; |
207 | // Find the first method call among the ancestors of `token`, then check if the only token | 210 | // Find the first method call among the ancestors of `token`, then check if the only token |
208 | // within the receiver is `token`. | 211 | // within the receiver is `token`. |
209 | if let Some(receiver) = token | 212 | if let Some(receiver) = |
210 | .ancestors() | 213 | token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.expr()) |
211 | .find(|node| node.kind() == SyntaxKind::METHOD_CALL_EXPR) | ||
212 | .and_then(|node| ast::MethodCallExpr::cast(node).unwrap().expr()) | ||
213 | { | 214 | { |
214 | let mut tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| { | 215 | let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| { |
215 | match node_or_token { | 216 | match node_or_token { |
216 | SyntaxElement::Token(t) => Some(t), | 217 | SyntaxElement::Token(t) => Some(t), |
217 | _ => None, | 218 | _ => None, |
218 | } | 219 | } |
219 | }); | 220 | }); |
220 | if let (Some(only_token), None) = (tokens.next(), tokens.next()) { | 221 | if let Some((only_token,)) = tokens.collect_tuple() { |
221 | return only_token == *token; | 222 | return only_token == *token; |
222 | } | 223 | } |
223 | } | 224 | } |