aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr/src/replacing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ssr/src/replacing.rs')
-rw-r--r--crates/ssr/src/replacing.rs13
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
3use crate::{resolving::ResolvedRule, Match, SsrMatches}; 3use crate::{resolving::ResolvedRule, Match, SsrMatches};
4use itertools::Itertools;
4use rustc_hash::{FxHashMap, FxHashSet}; 5use rustc_hash::{FxHashMap, FxHashSet};
5use syntax::ast::{self, AstToken}; 6use syntax::ast::{self, AstToken};
6use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; 7use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize};
8use test_utils::mark;
7use text_edit::TextEdit; 9use 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 }