diff options
| author | davidsemakula <hello@davidsemakula.com> | 2024-01-20 18:33:44 +0300 |
|---|---|---|
| committer | davidsemakula <hello@davidsemakula.com> | 2024-01-27 14:22:16 +0300 |
| commit | da798bccf71db9db6e778d023c25dd2077f15181 (patch) | |
| tree | 3cb403c6b0e33bc51383cf4f256e74202e985d11 | |
| parent | 7219414e81810fd4d967136c4a0650523892c157 (diff) | |
| download | rust-da798bccf71db9db6e778d023c25dd2077f15181.tar.gz rust-da798bccf71db9db6e778d023c25dd2077f15181.zip | |
make `ast::UseTree::wrap_in_tree_list` more robust
| -rw-r--r-- | crates/syntax/src/ast/edit_in_place.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index 247dfe0b459..18cda7dde73 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs @@ -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(()) } } |
