make ast::UseTree::wrap_in_tree_list more robust

This commit is contained in:
davidsemakula 2024-01-20 18:33:44 +03:00
parent 7219414e81
commit da798bccf7

View file

@ -538,9 +538,13 @@ impl ast::UseTree {
/// `foo::bar` -> `{foo::bar}`
///
/// `{foo::bar}` -> `{foo::bar}`
pub fn wrap_in_tree_list(&self) {
if self.path().is_none() {
return;
pub fn wrap_in_tree_list(&self) -> Option<()> {
if self.use_tree_list().is_some()
&& self.path().is_none()
&& self.star_token().is_none()
&& self.rename().is_none()
{
return None;
}
let subtree = self.clone_subtree().clone_for_update();
ted::remove_all_iter(self.syntax().children_with_tokens());
@ -548,6 +552,7 @@ impl ast::UseTree {
self.syntax(),
make::use_tree_list(once(subtree)).clone_for_update().syntax(),
);
Some(())
}
}