aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ssr')
-rw-r--r--crates/ssr/Cargo.toml2
-rw-r--r--crates/ssr/src/matching.rs8
-rw-r--r--crates/ssr/src/replacing.rs7
-rw-r--r--crates/ssr/src/tests.rs2
4 files changed, 9 insertions, 10 deletions
diff --git a/crates/ssr/Cargo.toml b/crates/ssr/Cargo.toml
index 7c2090de3..22b6af0fa 100644
--- a/crates/ssr/Cargo.toml
+++ b/crates/ssr/Cargo.toml
@@ -22,4 +22,4 @@ hir = { path = "../hir" }
22test_utils = { path = "../test_utils" } 22test_utils = { path = "../test_utils" }
23 23
24[dev-dependencies] 24[dev-dependencies]
25expect = { path = "../expect" } 25expect-test = "0.1"
diff --git a/crates/ssr/src/matching.rs b/crates/ssr/src/matching.rs
index 26968c474..948862a77 100644
--- a/crates/ssr/src/matching.rs
+++ b/crates/ssr/src/matching.rs
@@ -546,10 +546,12 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
546 // information on the placeholder match about autoderef and autoref. This allows us to use 546 // information on the placeholder match about autoderef and autoref. This allows us to use
547 // the placeholder in a context where autoderef and autoref don't apply. 547 // the placeholder in a context where autoderef and autoref don't apply.
548 if code_resolved_function.self_param(self.sema.db).is_some() { 548 if code_resolved_function.self_param(self.sema.db).is_some() {
549 if let (Some(pattern_type), Some(expr)) = (&pattern_ufcs.qualifier_type, &code.expr()) { 549 if let (Some(pattern_type), Some(expr)) =
550 (&pattern_ufcs.qualifier_type, &code.receiver())
551 {
550 let deref_count = self.check_expr_type(pattern_type, expr)?; 552 let deref_count = self.check_expr_type(pattern_type, expr)?;
551 let pattern_receiver = pattern_args.next(); 553 let pattern_receiver = pattern_args.next();
552 self.attempt_match_opt(phase, pattern_receiver.clone(), code.expr())?; 554 self.attempt_match_opt(phase, pattern_receiver.clone(), code.receiver())?;
553 if let Phase::Second(match_out) = phase { 555 if let Phase::Second(match_out) = phase {
554 if let Some(placeholder_value) = pattern_receiver 556 if let Some(placeholder_value) = pattern_receiver
555 .and_then(|n| self.get_placeholder_for_node(n.syntax())) 557 .and_then(|n| self.get_placeholder_for_node(n.syntax()))
@@ -568,7 +570,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
568 } 570 }
569 } 571 }
570 } else { 572 } else {
571 self.attempt_match_opt(phase, pattern_args.next(), code.expr())?; 573 self.attempt_match_opt(phase, pattern_args.next(), code.receiver())?;
572 } 574 }
573 let mut code_args = 575 let mut code_args =
574 code.arg_list().ok_or_else(|| match_error!("Code method call has no args"))?.args(); 576 code.arg_list().ok_or_else(|| match_error!("Code method call has no args"))?.args();
diff --git a/crates/ssr/src/replacing.rs b/crates/ssr/src/replacing.rs
index 29284e3f1..7e7ce37bd 100644
--- a/crates/ssr/src/replacing.rs
+++ b/crates/ssr/src/replacing.rs
@@ -3,7 +3,7 @@
3use crate::{resolving::ResolvedRule, Match, SsrMatches}; 3use crate::{resolving::ResolvedRule, Match, SsrMatches};
4use itertools::Itertools; 4use itertools::Itertools;
5use rustc_hash::{FxHashMap, FxHashSet}; 5use rustc_hash::{FxHashMap, FxHashSet};
6use syntax::ast::{self, AstToken}; 6use syntax::ast::{self, AstNode, AstToken};
7use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; 7use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize};
8use test_utils::mark; 8use test_utils::mark;
9use text_edit::TextEdit; 9use text_edit::TextEdit;
@@ -93,7 +93,6 @@ impl ReplacementRenderer<'_> {
93 } 93 }
94 94
95 fn render_node(&mut self, node: &SyntaxNode) { 95 fn render_node(&mut self, node: &SyntaxNode) {
96 use syntax::ast::AstNode;
97 if let Some(mod_path) = self.match_info.rendered_template_paths.get(&node) { 96 if let Some(mod_path) = self.match_info.rendered_template_paths.get(&node) {
98 self.out.push_str(&mod_path.to_string()); 97 self.out.push_str(&mod_path.to_string());
99 // Emit everything except for the segment's name-ref, since we already effectively 98 // Emit everything except for the segment's name-ref, since we already effectively
@@ -206,11 +205,10 @@ impl ReplacementRenderer<'_> {
206/// method call doesn't count. e.g. if the token is `$a`, then `$a.foo()` will return true, while 205/// method call doesn't count. e.g. if the token is `$a`, then `$a.foo()` will return true, while
207/// `($a + $b).foo()` or `x.foo($a)` will return false. 206/// `($a + $b).foo()` or `x.foo($a)` will return false.
208fn token_is_method_call_receiver(token: &SyntaxToken) -> bool { 207fn token_is_method_call_receiver(token: &SyntaxToken) -> bool {
209 use syntax::ast::AstNode;
210 // Find the first method call among the ancestors of `token`, then check if the only token 208 // Find the first method call among the ancestors of `token`, then check if the only token
211 // within the receiver is `token`. 209 // within the receiver is `token`.
212 if let Some(receiver) = 210 if let Some(receiver) =
213 token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.expr()) 211 token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.receiver())
214 { 212 {
215 let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| { 213 let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| {
216 match node_or_token { 214 match node_or_token {
@@ -226,7 +224,6 @@ fn token_is_method_call_receiver(token: &SyntaxToken) -> bool {
226} 224}
227 225
228fn parse_as_kind(code: &str, kind: SyntaxKind) -> Option<SyntaxNode> { 226fn parse_as_kind(code: &str, kind: SyntaxKind) -> Option<SyntaxNode> {
229 use syntax::ast::AstNode;
230 if ast::Expr::can_cast(kind) { 227 if ast::Expr::can_cast(kind) {
231 if let Ok(expr) = ast::Expr::parse(code) { 228 if let Ok(expr) = ast::Expr::parse(code) {
232 return Some(expr.syntax().clone()); 229 return Some(expr.syntax().clone());
diff --git a/crates/ssr/src/tests.rs b/crates/ssr/src/tests.rs
index e45c88864..20231a9bc 100644
--- a/crates/ssr/src/tests.rs
+++ b/crates/ssr/src/tests.rs
@@ -1,6 +1,6 @@
1use crate::{MatchFinder, SsrRule}; 1use crate::{MatchFinder, SsrRule};
2use base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt}; 2use base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt};
3use expect::{expect, Expect}; 3use expect_test::{expect, Expect};
4use rustc_hash::FxHashSet; 4use rustc_hash::FxHashSet;
5use std::sync::Arc; 5use std::sync::Arc;
6use test_utils::{mark, RangeOrOffset}; 6use test_utils::{mark, RangeOrOffset};