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 --- Cargo.lock | 4 ++-- crates/assists/src/handlers/auto_import.rs | 2 +- crates/assists/src/handlers/replace_unwrap_with_match.rs | 2 +- crates/hir/src/semantics.rs | 2 +- crates/hir_def/src/body/lower.rs | 2 +- crates/ide/src/completion/completion_context.rs | 2 +- crates/ide/src/syntax_highlighting.rs | 3 ++- crates/ssr/src/matching.rs | 8 +++++--- crates/ssr/src/replacing.rs | 7 ++----- crates/syntax/src/ast/generated/nodes.rs | 3 ++- xtask/src/codegen/gen_syntax.rs | 1 + 11 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad7760d98..f39da8105 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" 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 { 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(), )) } 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) 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(); 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> { 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, 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<'_> { 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 { 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> { 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; 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( 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 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()); 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 { pub fn comma_token(&self) -> Option { support::token(&self.syntax, T![,]) } pub fn params(&self) -> AstChildren { support::children(&self.syntax) } pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } + pub fn pipe_token(&self) -> Option { 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 { support::child(&self.syntax) } + pub fn receiver(&self) -> Option { support::child(&self.syntax) } pub fn dot_token(&self) -> Option { support::token(&self.syntax, T![.]) } pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn generic_arg_list(&self) -> Option { support::child(&self.syntax) } diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 53ae9f11c..200e8aa50 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -477,6 +477,7 @@ impl Field { "#" => "pound", "?" => "question_mark", "," => "comma", + "|" => "pipe", _ => name, }; format_ident!("{}_token", name) -- cgit v1.2.3 From 95f33bb5f73a7f9b7922eef14b996c0a489a6404 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Aug 2020 19:14:44 +0200 Subject: :arrow_up: autocfg --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f39da8105..46d9469c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -- cgit v1.2.3