From 3c40b15d625df192eb17c34f15f7dbc23f5284b9 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 9 Jun 2021 15:02:11 +0200 Subject: Don't descend MacroCall TokenTree delimiters --- crates/hir/src/semantics.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 2d08a7704..c437dbdc6 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -17,7 +17,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use syntax::{ algo::find_node_at_offset, ast::{self, GenericParamsOwner, LoopBodyOwner}, - match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextSize, + match_ast, AstNode, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize, }; use crate::{ @@ -394,7 +394,15 @@ impl<'db> SemanticsImpl<'db> { match node { ast::MacroCall(macro_call) => { let tt = macro_call.token_tree()?; - if !tt.syntax().text_range().contains_range(token.value.text_range()) { + let l_delim = match tt.left_delimiter_token() { + Some(it) => it.text_range().end(), + None => tt.syntax().text_range().start() + }; + let r_delim = match tt.right_delimiter_token() { + Some(it) => it.text_range().start(), + None => tt.syntax().text_range().end() + }; + if !TextRange::new(l_delim, r_delim).contains_range(token.value.text_range()) { return None; } let file_id = sa.expand(self.db, token.with_value(¯o_call))?; -- cgit v1.2.3