5367: missing impl members: remove assoc. type bounds r=matklad a=jonas-schievink

Previously "Add missing impl members" would paste bounds on associated types into the impl, which is not allowed. This removes them before pasting the item.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
bors[bot] 2020-07-14 11:37:28 +00:00 committed by GitHub
commit 83271f9b99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View file

@ -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(def.remove_bounds())
}
_ => it,
})
.map(|it| edit::remove_attrs_and_docs(&it));
@ -681,6 +684,28 @@ impl Foo<T> for S<T> {
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;
}"#,
)
}

View file

@ -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 {