Add with_use_tree

This commit is contained in:
Aleksey Kladov 2020-03-05 18:38:52 +01:00
parent fc4d0a7768
commit 381ace587e

View File

@ -249,6 +249,16 @@ impl ast::PathSegment {
}
}
impl ast::UseItem {
#[must_use]
pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem {
if let Some(old) = self.use_tree() {
return replace_descendants(self, iter::once((old, use_tree)));
}
self.clone()
}
}
#[must_use]
pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N {
N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()