about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/add_missing_impl_members.rs10
-rw-r--r--crates/ra_syntax/src/ast/edit.rs15
-rw-r--r--crates/ra_syntax/src/ast/make.rs13
3 files changed, 16 insertions, 22 deletions
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
index 124cead6c39..f185e61e595 100644
--- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
@@ -159,7 +159,7 @@ fn add_missing_impl_members_inner(
             .map(|it| match it {
                 ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)),
                 ast::AssocItem::TypeAliasDef(def) => {
-                    ast::AssocItem::TypeAliasDef(remove_bounds(def))
+                    ast::AssocItem::TypeAliasDef(def.remove_bounds())
                 }
                 _ => it,
             })
@@ -191,14 +191,6 @@ fn add_missing_impl_members_inner(
     })
 }
 
-fn remove_bounds(ty_def: ast::TypeAliasDef) -> ast::TypeAliasDef {
-    if let Some(name) = ty_def.name() {
-        make::type_alias_def(name, None, ty_def.type_ref())
-    } else {
-        ty_def
-    }
-}
-
 fn add_body(fn_def: ast::FnDef) -> ast::FnDef {
     if fn_def.body().is_some() {
         return fn_def;
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 940c30c7fb9..abc7a646c2c 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -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 {
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 42116afbbbb..192c610f1c5 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -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)),