aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-07-14 12:12:16 +0100
committerJonas Schievink <[email protected]>2020-07-14 12:12:16 +0100
commit0f654b06ab093e7bb057cfd68b27925803b003d8 (patch)
treec3fe1dd48945a139ba59c2e48453d8037efc5fe6 /crates/ra_assists/src/handlers
parent510866b4a1a812414568bd96f1d197587ead78c0 (diff)
missing impl members: remove assoc. type bounds
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r--crates/ra_assists/src/handlers/add_missing_impl_members.rs33
1 files changed, 33 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
194fn 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
191fn add_body(fn_def: ast::FnDef) -> ast::FnDef { 202fn 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#"
704trait Tr {
705 type Ty: Copy + 'static;
706}
707
708impl Tr for ()<|> {
709}"#,
710 r#"
711trait Tr {
712 type Ty: Copy + 'static;
713}
714
715impl Tr for () {
716 $0type Ty;
717}"#,
718 )
719 }
687} 720}