Move remove_bounds to edit.rs

This commit is contained in:
Jonas Schievink 2020-07-14 13:33:37 +02:00
parent 0f654b06ab
commit 85f5cbc9dc
3 changed files with 16 additions and 22 deletions

View file

@ -189,6 +189,21 @@ impl ast::RecordFieldList {
}
}
impl ast::TypeAliasDef {
#[must_use]
pub fn remove_bounds(&self) -> ast::TypeAliasDef {
let colon = match self.colon_token() {
Some(it) => it,
None => return self.clone(),
};
let end = match self.type_bound_list() {
Some(it) => it.syntax().clone().into(),
None => colon.clone().into(),
};
self.replace_children(colon.into()..=end, iter::empty())
}
}
impl ast::TypeParam {
#[must_use]
pub fn remove_bounds(&self) -> ast::TypeParam {

View file

@ -64,19 +64,6 @@ pub fn use_item(use_tree: ast::UseTree) -> ast::UseItem {
ast_from_text(&format!("use {};", use_tree))
}
pub fn type_alias_def(
name: ast::Name,
bounds: Option<ast::TypeBoundList>,
ty: Option<ast::TypeRef>,
) -> ast::TypeAliasDef {
match (bounds, ty) {
(None, None) => ast_from_text(&format!("type {};", name)),
(None, Some(ty)) => ast_from_text(&format!("type {} = {};", name, ty)),
(Some(bounds), None) => ast_from_text(&format!("type {}: {};", name, bounds)),
(Some(bounds), Some(ty)) => ast_from_text(&format!("type {}: {} = {};", name, bounds, ty)),
}
}
pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField {
return match expr {
Some(expr) => from_text(&format!("{}: {}", name, expr)),