Skip to content

Commit 1d5c60f

Browse files
Replace attribute with equivalent whitespace
This is needed to that the `TokenMap` we create contains offsets that match the source.
1 parent d616a6a commit 1d5c60f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/hir_expand/src/input.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Macro input conditioning.
22
33
use syntax::{
4-
ast::{self, AttrsOwner},
4+
ast::{self, make, AttrsOwner},
55
AstNode, SyntaxNode,
66
};
77

@@ -61,7 +61,9 @@ fn remove_attr_invoc(item: ast::Item, attr_index: usize) -> ast::Item {
6161
.attrs()
6262
.nth(attr_index)
6363
.unwrap_or_else(|| panic!("cannot find attribute #{}", attr_index));
64-
attr.syntax().detach();
64+
let syntax_index = attr.syntax().index();
65+
let ws = make::tokens::whitespace(&" ".repeat(u32::from(attr.syntax().text().len()) as usize));
66+
item.syntax().splice_children(syntax_index..syntax_index + 1, vec![ws.into()]);
6567
item
6668
}
6769

0 commit comments

Comments
 (0)