mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
missing impl members: remove assoc. type bounds
This commit is contained in:
parent
510866b4a1
commit
0f654b06ab
2 changed files with 46 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(remove_bounds(def))
|
||||||
|
}
|
||||||
_ => it,
|
_ => it,
|
||||||
})
|
})
|
||||||
.map(|it| edit::remove_attrs_and_docs(&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 {
|
fn add_body(fn_def: ast::FnDef) -> ast::FnDef {
|
||||||
if fn_def.body().is_some() {
|
if fn_def.body().is_some() {
|
||||||
return fn_def;
|
return fn_def;
|
||||||
|
@ -681,6 +692,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;
|
||||||
}"#,
|
}"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,19 @@ pub fn use_item(use_tree: ast::UseTree) -> ast::UseItem {
|
||||||
ast_from_text(&format!("use {};", use_tree))
|
ast_from_text(&format!("use {};", use_tree))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn type_alias_def(
|
||||||
|
name: ast::Name,
|
||||||
|
bounds: Option<ast::TypeBoundList>,
|
||||||
|
ty: Option<ast::TypeRef>,
|
||||||
|
) -> ast::TypeAliasDef {
|
||||||
|
match (bounds, ty) {
|
||||||
|
(None, None) => ast_from_text(&format!("type {};", name)),
|
||||||
|
(None, Some(ty)) => ast_from_text(&format!("type {} = {};", name, ty)),
|
||||||
|
(Some(bounds), None) => ast_from_text(&format!("type {}: {};", name, bounds)),
|
||||||
|
(Some(bounds), Some(ty)) => ast_from_text(&format!("type {}: {} = {};", name, bounds, ty)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField {
|
pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField {
|
||||||
return match expr {
|
return match expr {
|
||||||
Some(expr) => from_text(&format!("{}: {}", name, expr)),
|
Some(expr) => from_text(&format!("{}: {}", name, expr)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue