Skip to content

Commit 13da28c

Browse files
Merge #9155
9155: internal: replace attribute with equivalent whitespace r=jonas-schievink a=jonas-schievink This is needed to that the `TokenMap` we create contains offsets that match the source. Currently the offsets don't match because the attribute is removed, shifting all subsequent token offsets by the attribute's text length. Currently this fix has no visible effect because we don't remap tokens in attribute macros. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents d616a6a + 1d5c60f commit 13da28c

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)