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 <jonasschievink@gmail.com>
This commit is contained in:
commit
13da28cc2b
@ -1,7 +1,7 @@
|
|||||||
//! Macro input conditioning.
|
//! Macro input conditioning.
|
||||||
|
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AttrsOwner},
|
ast::{self, make, AttrsOwner},
|
||||||
AstNode, SyntaxNode,
|
AstNode, SyntaxNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,7 +61,9 @@ fn remove_attr_invoc(item: ast::Item, attr_index: usize) -> ast::Item {
|
|||||||
.attrs()
|
.attrs()
|
||||||
.nth(attr_index)
|
.nth(attr_index)
|
||||||
.unwrap_or_else(|| panic!("cannot find attribute #{}", 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
|
item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user