From 1d5c60ff548c082a59eebda4bbaede99cec3cc4d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 6 Jun 2021 15:51:49 +0200 Subject: Replace attribute with equivalent whitespace This is needed to that the `TokenMap` we create contains offsets that match the source. --- crates/hir_expand/src/input.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'crates/hir_expand') diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs index 40116a479..82dc7f326 100644 --- a/crates/hir_expand/src/input.rs +++ b/crates/hir_expand/src/input.rs @@ -1,7 +1,7 @@ //! Macro input conditioning. use syntax::{ - ast::{self, AttrsOwner}, + ast::{self, make, AttrsOwner}, AstNode, SyntaxNode, }; @@ -61,7 +61,9 @@ fn remove_attr_invoc(item: ast::Item, attr_index: usize) -> ast::Item { .attrs() .nth(attr_index) .unwrap_or_else(|| panic!("cannot find attribute #{}", attr_index)); - attr.syntax().detach(); + let syntax_index = attr.syntax().index(); + let ws = make::tokens::whitespace(&" ".repeat(u32::from(attr.syntax().text().len()) as usize)); + item.syntax().splice_children(syntax_index..syntax_index + 1, vec![ws.into()]); item } -- cgit v1.2.3