From 863b1fb731e797f02daeac87a94d40a34222a062 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Aug 2020 19:12:38 +0200 Subject: :arrow_up: ungrammar --- crates/ssr/src/matching.rs | 8 +++++--- crates/ssr/src/replacing.rs | 7 ++----- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'crates/ssr') 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> { // information on the placeholder match about autoderef and autoref. This allows us to use // the placeholder in a context where autoderef and autoref don't apply. if code_resolved_function.self_param(self.sema.db).is_some() { - if let (Some(pattern_type), Some(expr)) = (&pattern_ufcs.qualifier_type, &code.expr()) { + if let (Some(pattern_type), Some(expr)) = + (&pattern_ufcs.qualifier_type, &code.receiver()) + { let deref_count = self.check_expr_type(pattern_type, expr)?; let pattern_receiver = pattern_args.next(); - self.attempt_match_opt(phase, pattern_receiver.clone(), code.expr())?; + self.attempt_match_opt(phase, pattern_receiver.clone(), code.receiver())?; if let Phase::Second(match_out) = phase { if let Some(placeholder_value) = pattern_receiver .and_then(|n| self.get_placeholder_for_node(n.syntax())) @@ -568,7 +570,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { } } } else { - self.attempt_match_opt(phase, pattern_args.next(), code.expr())?; + self.attempt_match_opt(phase, pattern_args.next(), code.receiver())?; } let mut code_args = 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 @@ use crate::{resolving::ResolvedRule, Match, SsrMatches}; use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; -use syntax::ast::{self, AstToken}; +use syntax::ast::{self, AstNode, AstToken}; use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; use test_utils::mark; use text_edit::TextEdit; @@ -93,7 +93,6 @@ impl ReplacementRenderer<'_> { } fn render_node(&mut self, node: &SyntaxNode) { - use syntax::ast::AstNode; if let Some(mod_path) = self.match_info.rendered_template_paths.get(&node) { self.out.push_str(&mod_path.to_string()); // Emit everything except for the segment's name-ref, since we already effectively @@ -206,11 +205,10 @@ impl ReplacementRenderer<'_> { /// method call doesn't count. e.g. if the token is `$a`, then `$a.foo()` will return true, while /// `($a + $b).foo()` or `x.foo($a)` will return false. fn token_is_method_call_receiver(token: &SyntaxToken) -> bool { - use syntax::ast::AstNode; // Find the first method call among the ancestors of `token`, then check if the only token // within the receiver is `token`. if let Some(receiver) = - token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.expr()) + token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.receiver()) { let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| { match node_or_token { @@ -226,7 +224,6 @@ fn token_is_method_call_receiver(token: &SyntaxToken) -> bool { } fn parse_as_kind(code: &str, kind: SyntaxKind) -> Option { - use syntax::ast::AstNode; if ast::Expr::can_cast(kind) { if let Ok(expr) = ast::Expr::parse(code) { return Some(expr.syntax().clone()); -- cgit v1.2.3