mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Merge #5367
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:
commit
83271f9b99
2 changed files with 40 additions and 0 deletions
|
@ -158,6 +158,9 @@ fn add_missing_impl_members_inner(
|
||||||
.map(|it| ast_transform::apply(&*ast_transform, it))
|
.map(|it| ast_transform::apply(&*ast_transform, it))
|
||||||
.map(|it| match it {
|
.map(|it| match it {
|
||||||
ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)),
|
ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)),
|
||||||
|
ast::AssocItem::TypeAliasDef(def) => {
|
||||||
|
ast::AssocItem::TypeAliasDef(def.remove_bounds())
|
||||||
|
}
|
||||||
_ => it,
|
_ => it,
|
||||||
})
|
})
|
||||||
.map(|it| edit::remove_attrs_and_docs(&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) {
|
fn bar(&self, this: &T, that: &Self) {
|
||||||
${0:todo!()}
|
${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;
|
||||||
}"#,
|
}"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
impl ast::TypeParam {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn remove_bounds(&self) -> ast::TypeParam {
|
pub fn remove_bounds(&self) -> ast::TypeParam {
|
||||||
|
|
Loading…
Reference in a new issue