From 0f654b06ab093e7bb057cfd68b27925803b003d8 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 14 Jul 2020 13:12:16 +0200 Subject: missing impl members: remove assoc. type bounds --- crates/ra_syntax/src/ast/make.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 192c610f1..42116afbb 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -64,6 +64,19 @@ 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, + ty: Option, +) -> 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::RecordField { return match expr { Some(expr) => from_text(&format!("{}: {}", name, expr)), -- cgit v1.2.3 From 85f5cbc9dc7027f922198f6c2d06cf382aad6970 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 14 Jul 2020 13:33:37 +0200 Subject: Move remove_bounds to edit.rs --- crates/ra_syntax/src/ast/edit.rs | 15 +++++++++++++++ crates/ra_syntax/src/ast/make.rs | 13 ------------- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 940c30c7f..abc7a646c 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 42116afbb..192c610f1 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, - ty: Option, -) -> 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::RecordField { return match expr { Some(expr) => from_text(&format!("{}: {}", name, expr)), -- cgit v1.2.3