diff options
author | Jonas Schievink <[email protected]> | 2020-07-14 12:12:16 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-07-14 12:12:16 +0100 |
commit | 0f654b06ab093e7bb057cfd68b27925803b003d8 (patch) | |
tree | c3fe1dd48945a139ba59c2e48453d8037efc5fe6 | |
parent | 510866b4a1a812414568bd96f1d197587ead78c0 (diff) |
missing impl members: remove assoc. type bounds
-rw-r--r-- | crates/ra_assists/src/handlers/add_missing_impl_members.rs | 33 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 13 |
2 files changed, 46 insertions, 0 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 d6aaf53f1..124cead6c 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -158,6 +158,9 @@ fn add_missing_impl_members_inner( | |||
158 | .map(|it| ast_transform::apply(&*ast_transform, it)) | 158 | .map(|it| ast_transform::apply(&*ast_transform, it)) |
159 | .map(|it| match it { | 159 | .map(|it| match it { |
160 | ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), | 160 | ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), |
161 | ast::AssocItem::TypeAliasDef(def) => { | ||
162 | ast::AssocItem::TypeAliasDef(remove_bounds(def)) | ||
163 | } | ||
161 | _ => it, | 164 | _ => it, |
162 | }) | 165 | }) |
163 | .map(|it| edit::remove_attrs_and_docs(&it)); | 166 | .map(|it| edit::remove_attrs_and_docs(&it)); |
@@ -188,6 +191,14 @@ fn add_missing_impl_members_inner( | |||
188 | }) | 191 | }) |
189 | } | 192 | } |
190 | 193 | ||
194 | fn remove_bounds(ty_def: ast::TypeAliasDef) -> ast::TypeAliasDef { | ||
195 | if let Some(name) = ty_def.name() { | ||
196 | make::type_alias_def(name, None, ty_def.type_ref()) | ||
197 | } else { | ||
198 | ty_def | ||
199 | } | ||
200 | } | ||
201 | |||
191 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { | 202 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { |
192 | if fn_def.body().is_some() { | 203 | if fn_def.body().is_some() { |
193 | return fn_def; | 204 | return fn_def; |
@@ -684,4 +695,26 @@ impl Foo<T> for S<T> { | |||
684 | }"#, | 695 | }"#, |
685 | ) | 696 | ) |
686 | } | 697 | } |
698 | |||
699 | #[test] | ||
700 | fn test_assoc_type_bounds_are_removed() { | ||
701 | check_assist( | ||
702 | add_missing_impl_members, | ||
703 | r#" | ||
704 | trait Tr { | ||
705 | type Ty: Copy + 'static; | ||
706 | } | ||
707 | |||
708 | impl Tr for ()<|> { | ||
709 | }"#, | ||
710 | r#" | ||
711 | trait Tr { | ||
712 | type Ty: Copy + 'static; | ||
713 | } | ||
714 | |||
715 | impl Tr for () { | ||
716 | $0type Ty; | ||
717 | }"#, | ||
718 | ) | ||
719 | } | ||
687 | } | 720 | } |
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 { | |||
64 | ast_from_text(&format!("use {};", use_tree)) | 64 | ast_from_text(&format!("use {};", use_tree)) |
65 | } | 65 | } |
66 | 66 | ||
67 | pub fn type_alias_def( | ||
68 | name: ast::Name, | ||
69 | bounds: Option<ast::TypeBoundList>, | ||
70 | ty: Option<ast::TypeRef>, | ||
71 | ) -> ast::TypeAliasDef { | ||
72 | match (bounds, ty) { | ||
73 | (None, None) => ast_from_text(&format!("type {};", name)), | ||
74 | (None, Some(ty)) => ast_from_text(&format!("type {} = {};", name, ty)), | ||
75 | (Some(bounds), None) => ast_from_text(&format!("type {}: {};", name, bounds)), | ||
76 | (Some(bounds), Some(ty)) => ast_from_text(&format!("type {}: {} = {};", name, bounds, ty)), | ||
77 | } | ||
78 | } | ||
79 | |||
67 | pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField { | 80 | pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField { |
68 | return match expr { | 81 | return match expr { |
69 | Some(expr) => from_text(&format!("{}: {}", name, expr)), | 82 | Some(expr) => from_text(&format!("{}: {}", name, expr)), |