Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/node_ext.rs')
-rw-r--r--crates/syntax/src/ast/node_ext.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 1c6157de55..ce01ee1c35 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -53,6 +53,12 @@ fn text_of_first_token(node: &SyntaxNode) -> TokenText<'_> {
}
}
+impl ast::Abi {
+ pub fn abi_string(&self) -> Option<ast::String> {
+ support::token(&self.syntax, SyntaxKind::STRING).and_then(ast::String::cast)
+ }
+}
+
impl ast::HasModuleItem for ast::StmtList {}
impl ast::BlockExpr {
@@ -327,6 +333,14 @@ impl ast::UseTree {
pub fn parent_use_tree_list(&self) -> Option<ast::UseTreeList> {
self.syntax().parent().and_then(ast::UseTreeList::cast)
}
+
+ pub fn top_use_tree(&self) -> ast::UseTree {
+ let mut this = self.clone();
+ while let Some(use_tree_list) = this.parent_use_tree_list() {
+ this = use_tree_list.parent_use_tree();
+ }
+ this
+ }
}
impl ast::UseTreeList {
@@ -356,8 +370,12 @@ impl ast::UseTreeList {
let remove_brace_in_use_tree_list = |u: &ast::UseTreeList| {
let use_tree_count = u.use_trees().count();
if use_tree_count == 1 {
- u.l_curly_token().map(ted::remove);
- u.r_curly_token().map(ted::remove);
+ if let Some(a) = u.l_curly_token() {
+ ted::remove(a)
+ }
+ if let Some(a) = u.r_curly_token() {
+ ted::remove(a)
+ }
u.comma().for_each(ted::remove);
}
};
@@ -440,6 +458,12 @@ impl ast::Struct {
}
}
+impl ast::Union {
+ pub fn kind(&self) -> StructKind {
+ StructKind::from_node(self)
+ }
+}
+
impl ast::RecordExprField {
pub fn for_field_name(field_name: &ast::NameRef) -> Option<ast::RecordExprField> {
let candidate = Self::for_name_ref(field_name)?;