Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/make.rs')
| -rw-r--r-- | crates/syntax/src/ast/make.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index f16dcd56e9..e67ac69073 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs @@ -44,6 +44,15 @@ pub mod ext { Some(path) } + pub fn field_from_idents<'a>( + parts: impl std::iter::IntoIterator<Item = &'a str>, + ) -> Option<ast::Expr> { + let mut iter = parts.into_iter(); + let base = expr_path(ext::ident_path(iter.next()?)); + let expr = iter.fold(base, |base, s| expr_field(base, s)); + Some(expr) + } + pub fn expr_unreachable() -> ast::Expr { expr_from_text("unreachable!()") } @@ -124,6 +133,22 @@ pub fn assoc_item_list() -> ast::AssocItemList { ast_from_text("impl C for D {}") } +pub fn impl_( + ty: ast::Path, + params: Option<ast::GenericParamList>, + ty_params: Option<ast::GenericParamList>, +) -> ast::Impl { + let params = match params { + Some(params) => params.to_string(), + None => String::new(), + }; + let ty_params = match ty_params { + Some(params) => params.to_string(), + None => String::new(), + }; + ast_from_text(&format!("impl{} {}{} {{}}", params, ty, ty_params)) +} + pub fn impl_trait(trait_: ast::Path, ty: ast::Path) -> ast::Impl { ast_from_text(&format!("impl {} for {} {{}}", trait_, ty)) } @@ -645,7 +670,7 @@ pub fn fn_( is_async: bool, ) -> ast::Fn { let type_params = match type_params { - Some(type_params) => format!("<{}>", type_params), + Some(type_params) => format!("{}", type_params), None => "".into(), }; let ret_type = match ret_type { |