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 --- .../src/handlers/add_missing_impl_members.rs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'crates/ra_assists') 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( .map(|it| ast_transform::apply(&*ast_transform, it)) .map(|it| match it { ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), + ast::AssocItem::TypeAliasDef(def) => { + ast::AssocItem::TypeAliasDef(remove_bounds(def)) + } _ => it, }) .map(|it| edit::remove_attrs_and_docs(&it)); @@ -188,6 +191,14 @@ 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; @@ -681,6 +692,28 @@ impl Foo for S { fn bar(&self, this: &T, that: &Self) { ${0:todo!()} } +}"#, + ) + } + + #[test] + fn test_assoc_type_bounds_are_removed() { + check_assist( + add_missing_impl_members, + r#" +trait Tr { + type Ty: Copy + 'static; +} + +impl Tr for ()<|> { +}"#, + r#" +trait Tr { + type Ty: Copy + 'static; +} + +impl Tr for () { + $0type Ty; }"#, ) } -- 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_assists/src/handlers/add_missing_impl_members.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'crates/ra_assists') 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 124cead6c..f185e61e5 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; -- cgit v1.2.3