aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-21 18:12:38 +0100
committerAleksey Kladov <[email protected]>2020-08-21 18:14:05 +0100
commit863b1fb731e797f02daeac87a94d40a34222a062 (patch)
tree7a3ae3553ad1c97ad4ac70d8b7126ee0ec5343ad /crates
parentdf54561a689a9eb7b1962b69a397a1221200c116 (diff)
:arrow_up: ungrammar
Diffstat (limited to 'crates')
-rw-r--r--crates/assists/src/handlers/auto_import.rs2
-rw-r--r--crates/assists/src/handlers/replace_unwrap_with_match.rs2
-rw-r--r--crates/hir/src/semantics.rs2
-rw-r--r--crates/hir_def/src/body/lower.rs2
-rw-r--r--crates/ide/src/completion/completion_context.rs2
-rw-r--r--crates/ide/src/syntax_highlighting.rs3
-rw-r--r--crates/ssr/src/matching.rs8
-rw-r--r--crates/ssr/src/replacing.rs7
-rw-r--r--crates/syntax/src/ast/generated/nodes.rs3
9 files changed, 16 insertions, 15 deletions
diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs
index b9ec3f10b..c4770f336 100644
--- a/crates/assists/src/handlers/auto_import.rs
+++ b/crates/assists/src/handlers/auto_import.rs
@@ -239,7 +239,7 @@ impl ImportCandidate {
239 return None; 239 return None;
240 } 240 }
241 Some(Self::TraitMethod( 241 Some(Self::TraitMethod(
242 sema.type_of_expr(&method_call.expr()?)?, 242 sema.type_of_expr(&method_call.receiver()?)?,
243 method_call.name_ref()?.syntax().to_string(), 243 method_call.name_ref()?.syntax().to_string(),
244 )) 244 ))
245 } 245 }
diff --git a/crates/assists/src/handlers/replace_unwrap_with_match.rs b/crates/assists/src/handlers/replace_unwrap_with_match.rs
index 9705f11b7..4043c219c 100644
--- a/crates/assists/src/handlers/replace_unwrap_with_match.rs
+++ b/crates/assists/src/handlers/replace_unwrap_with_match.rs
@@ -42,7 +42,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
42 if name.text() != "unwrap" { 42 if name.text() != "unwrap" {
43 return None; 43 return None;
44 } 44 }
45 let caller = method_call.expr()?; 45 let caller = method_call.receiver()?;
46 let ty = ctx.sema.type_of_expr(&caller)?; 46 let ty = ctx.sema.type_of_expr(&caller)?;
47 let happy_variant = TryEnum::from_ty(&ctx.sema, &ty)?.happy_case(); 47 let happy_variant = TryEnum::from_ty(&ctx.sema, &ty)?.happy_case();
48 let target = method_call.syntax().text_range(); 48 let target = method_call.syntax().text_range();
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 8c5f2ff98..1594d4f0f 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -573,7 +573,7 @@ impl<'db> SemanticsImpl<'db> {
573 573
574 fn is_unsafe_method_call(&self, method_call_expr: &ast::MethodCallExpr) -> bool { 574 fn is_unsafe_method_call(&self, method_call_expr: &ast::MethodCallExpr) -> bool {
575 method_call_expr 575 method_call_expr
576 .expr() 576 .receiver()
577 .and_then(|expr| { 577 .and_then(|expr| {
578 let field_expr = match expr { 578 let field_expr = match expr {
579 ast::Expr::FieldExpr(field_expr) => field_expr, 579 ast::Expr::FieldExpr(field_expr) => field_expr,
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index a26251cde..30ac12a12 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -329,7 +329,7 @@ impl ExprCollector<'_> {
329 self.alloc_expr(Expr::Call { callee, args }, syntax_ptr) 329 self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
330 } 330 }
331 ast::Expr::MethodCallExpr(e) => { 331 ast::Expr::MethodCallExpr(e) => {
332 let receiver = self.collect_expr_opt(e.expr()); 332 let receiver = self.collect_expr_opt(e.receiver());
333 let args = if let Some(arg_list) = e.arg_list() { 333 let args = if let Some(arg_list) = e.arg_list() {
334 arg_list.args().map(|e| self.collect_expr(e)).collect() 334 arg_list.args().map(|e| self.collect_expr(e)).collect()
335 } else { 335 } else {
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index 85456a66f..5adac7ebc 100644
--- a/crates/ide/src/completion/completion_context.rs
+++ b/crates/ide/src/completion/completion_context.rs
@@ -457,7 +457,7 @@ impl<'a> CompletionContext<'a> {
457 if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { 457 if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
458 // As above 458 // As above
459 self.dot_receiver = method_call_expr 459 self.dot_receiver = method_call_expr
460 .expr() 460 .receiver()
461 .map(|e| e.syntax().text_range()) 461 .map(|e| e.syntax().text_range())
462 .and_then(|r| find_node_with_range(original_file, r)); 462 .and_then(|r| find_node_with_range(original_file, r));
463 self.is_call = true; 463 self.is_call = true;
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index dd8cfe42d..aefc86949 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -724,7 +724,8 @@ fn highlight_method_call(
724 hir::Access::Shared => (), 724 hir::Access::Shared => (),
725 hir::Access::Exclusive => h |= HighlightModifier::Mutable, 725 hir::Access::Exclusive => h |= HighlightModifier::Mutable,
726 hir::Access::Owned => { 726 hir::Access::Owned => {
727 if let Some(receiver_ty) = method_call.expr().and_then(|it| sema.type_of_expr(&it)) 727 if let Some(receiver_ty) =
728 method_call.receiver().and_then(|it| sema.type_of_expr(&it))
728 { 729 {
729 if !receiver_ty.is_copy(sema.db) { 730 if !receiver_ty.is_copy(sema.db) {
730 h |= HighlightModifier::Consuming 731 h |= HighlightModifier::Consuming
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/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs
index 3d49309d1..6317407c6 100644
--- a/crates/syntax/src/ast/generated/nodes.rs
+++ b/crates/syntax/src/ast/generated/nodes.rs
@@ -66,6 +66,7 @@ impl ParamList {
66 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) } 66 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
67 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } 67 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
68 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 68 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
69 pub fn pipe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![|]) }
69} 70}
70#[derive(Debug, Clone, PartialEq, Eq, Hash)] 71#[derive(Debug, Clone, PartialEq, Eq, Hash)]
71pub struct RetType { 72pub struct RetType {
@@ -809,7 +810,7 @@ pub struct MethodCallExpr {
809impl ast::AttrsOwner for MethodCallExpr {} 810impl ast::AttrsOwner for MethodCallExpr {}
810impl ast::ArgListOwner for MethodCallExpr {} 811impl ast::ArgListOwner for MethodCallExpr {}
811impl MethodCallExpr { 812impl MethodCallExpr {
812 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 813 pub fn receiver(&self) -> Option<Expr> { support::child(&self.syntax) }
813 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 814 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
814 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 815 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
815 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) } 816 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }