]> git.lizzy.rs Git - rust.git/commitdiff
:arrow_up: ungrammar
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 21 Aug 2020 17:12:38 +0000 (19:12 +0200)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 21 Aug 2020 17:14:05 +0000 (19:14 +0200)
Cargo.lock
crates/assists/src/handlers/auto_import.rs
crates/assists/src/handlers/replace_unwrap_with_match.rs
crates/hir/src/semantics.rs
crates/hir_def/src/body/lower.rs
crates/ide/src/completion/completion_context.rs
crates/ide/src/syntax_highlighting.rs
crates/ssr/src/matching.rs
crates/ssr/src/replacing.rs
crates/syntax/src/ast/generated/nodes.rs
xtask/src/codegen/gen_syntax.rs

index ad7760d98cfe103b662971a6473623d65758d6d5..f39da81051ba47fd10eb1e395caed058dd3e6f40 100644 (file)
@@ -1688,9 +1688,9 @@ dependencies = [
 
 [[package]]
 name = "ungrammar"
-version = "1.1.1"
+version = "1.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c4e20e58a08ee1bcf8a4695cf74550cf054d6c489105f594beacb2c684210aad"
+checksum = "bab6142ac77be714b1ea78faca6efaed5478c50724786b0fe80d8528d10692b3"
 
 [[package]]
 name = "unicode-bidi"
index b9ec3f10b65e2adefbba3b63265753cc839a7dac..c4770f33611f32012f641dfbcaed18c1b3193914 100644 (file)
@@ -239,7 +239,7 @@ fn for_method_call(
             return None;
         }
         Some(Self::TraitMethod(
-            sema.type_of_expr(&method_call.expr()?)?,
+            sema.type_of_expr(&method_call.receiver()?)?,
             method_call.name_ref()?.syntax().to_string(),
         ))
     }
index 9705f11b76b5c85df3f7a1213ed18f01d14a5d1e..4043c219cde34885e4d93cb9b4727df53a9ae2a4 100644 (file)
@@ -42,7 +42,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext)
     if name.text() != "unwrap" {
         return None;
     }
-    let caller = method_call.expr()?;
+    let caller = method_call.receiver()?;
     let ty = ctx.sema.type_of_expr(&caller)?;
     let happy_variant = TryEnum::from_ty(&ctx.sema, &ty)?.happy_case();
     let target = method_call.syntax().text_range();
index 8c5f2ff98312788fd7fc3530fc7ec862eddf3bc6..1594d4f0ff9937fb00054a2b5769869eb6b7373d 100644 (file)
@@ -573,7 +573,7 @@ fn find_file(&self, node: SyntaxNode) -> InFile<SyntaxNode> {
 
     fn is_unsafe_method_call(&self, method_call_expr: &ast::MethodCallExpr) -> bool {
         method_call_expr
-            .expr()
+            .receiver()
             .and_then(|expr| {
                 let field_expr = match expr {
                     ast::Expr::FieldExpr(field_expr) => field_expr,
index a26251cdeb5bbca48ab42fd71c8fceccc34448b5..30ac12a12e431369112ad294b514db88c393c2f6 100644 (file)
@@ -329,7 +329,7 @@ fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
                 self.alloc_expr(Expr::Call { callee, args }, syntax_ptr)
             }
             ast::Expr::MethodCallExpr(e) => {
-                let receiver = self.collect_expr_opt(e.expr());
+                let receiver = self.collect_expr_opt(e.receiver());
                 let args = if let Some(arg_list) = e.arg_list() {
                     arg_list.args().map(|e| self.collect_expr(e)).collect()
                 } else {
index 85456a66f5e1afbe07b75eb27a1bfd604f395af9..5adac7ebcc1e86f6c0ffa10acdf84b86ac2fa120 100644 (file)
@@ -457,7 +457,7 @@ fn classify_name_ref(
         if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
             // As above
             self.dot_receiver = method_call_expr
-                .expr()
+                .receiver()
                 .map(|e| e.syntax().text_range())
                 .and_then(|r| find_node_with_range(original_file, r));
             self.is_call = true;
index dd8cfe42d2d6cf9b3afab8ddb24b8cbe367b169a..aefc869499a8721f1020859599a47d8cb8679281 100644 (file)
@@ -724,7 +724,8 @@ fn highlight_method_call(
             hir::Access::Shared => (),
             hir::Access::Exclusive => h |= HighlightModifier::Mutable,
             hir::Access::Owned => {
-                if let Some(receiver_ty) = method_call.expr().and_then(|it| sema.type_of_expr(&it))
+                if let Some(receiver_ty) =
+                    method_call.receiver().and_then(|it| sema.type_of_expr(&it))
                 {
                     if !receiver_ty.is_copy(sema.db) {
                         h |= HighlightModifier::Consuming
index 26968c474dd7c6be1038febd8f07b4faec1ce16c..948862a775be0434055573957dc80d78733a3aa2 100644 (file)
@@ -546,10 +546,12 @@ fn attempt_match_ufcs_to_method_call(
         // 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 @@ fn attempt_match_ufcs_to_method_call(
                 }
             }
         } 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();
index 29284e3f1c2dad5e5294de577735ffbb66ff973d..7e7ce37bdc30af7bec076c381b5a778d950fc4e2 100644 (file)
@@ -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 @@ fn render_node_or_token(&mut self, node_or_token: &SyntaxElement) {
     }
 
     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 @@ fn remove_node_ranges(&mut self, node: SyntaxNode) {
 /// 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<SyntaxNode> {
-    use syntax::ast::AstNode;
     if ast::Expr::can_cast(kind) {
         if let Ok(expr) = ast::Expr::parse(code) {
             return Some(expr.syntax().clone());
index 3d49309d1488eb7b66398e6b83f379b6294a1154..6317407c6f0036b403109e39b50c7837df9ffad8 100644 (file)
@@ -66,6 +66,7 @@ pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
     pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
     pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
     pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
+    pub fn pipe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![|]) }
 }
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub struct RetType {
@@ -809,7 +810,7 @@ pub struct MethodCallExpr {
 impl ast::AttrsOwner for MethodCallExpr {}
 impl ast::ArgListOwner for MethodCallExpr {}
 impl MethodCallExpr {
-    pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
+    pub fn receiver(&self) -> Option<Expr> { support::child(&self.syntax) }
     pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
     pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
     pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
index 53ae9f11c9c1adbef15010fad2f7e11fa745aa4e..200e8aa5043dac896a0c603be5f27be020a9141a 100644 (file)
@@ -477,6 +477,7 @@ fn method_name(&self) -> proc_macro2::Ident {
                     "#" => "pound",
                     "?" => "question_mark",
                     "," => "comma",
+                    "|" => "pipe",
                     _ => name,
                 };
                 format_ident!("{}_token", name)