mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Ignore unnamed trait fns and add more tests
This commit is contained in:
parent
406343492c
commit
0e47c371fd
1 changed files with 70 additions and 2 deletions
|
@ -69,6 +69,7 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) ->
|
||||||
|
|
||||||
let missing_fns: Vec<_> = trait_fns
|
let missing_fns: Vec<_> = trait_fns
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.filter(|t| def_name(t).is_some())
|
||||||
.filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t)))
|
.filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t)))
|
||||||
.collect();
|
.collect();
|
||||||
if missing_fns.is_empty() {
|
if missing_fns.is_empty() {
|
||||||
|
@ -89,8 +90,7 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) ->
|
||||||
.unwrap_or_else(|| impl_block_indent().to_owned() + DEFAULT_INDENT)
|
.unwrap_or_else(|| impl_block_indent().to_owned() + DEFAULT_INDENT)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut func_bodies = missing_fns.into_iter().map(build_func_body);
|
let func_bodies = missing_fns.into_iter().map(build_func_body).join("\n");
|
||||||
let func_bodies = func_bodies.join("\n");
|
|
||||||
let func_bodies = String::from("\n") + &func_bodies;
|
let func_bodies = String::from("\n") + &func_bodies;
|
||||||
let func_bodies = reindent(&func_bodies, &indent) + "\n";
|
let func_bodies = reindent(&func_bodies, &indent) + "\n";
|
||||||
|
|
||||||
|
@ -152,6 +152,40 @@ impl Foo for S {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_copied_overriden_members() {
|
||||||
|
check_assist(
|
||||||
|
add_missing_impl_members,
|
||||||
|
"
|
||||||
|
trait Foo {
|
||||||
|
fn foo(&self);
|
||||||
|
fn bar(&self) -> bool { true }
|
||||||
|
fn baz(&self) -> u32 { 42 }
|
||||||
|
}
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl Foo for S {
|
||||||
|
fn bar(&self) {}
|
||||||
|
<|>
|
||||||
|
}",
|
||||||
|
"
|
||||||
|
trait Foo {
|
||||||
|
fn foo(&self);
|
||||||
|
fn bar(&self) -> bool { true }
|
||||||
|
fn baz(&self) -> u32 { 42 }
|
||||||
|
}
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl Foo for S {
|
||||||
|
fn bar(&self) {}
|
||||||
|
fn foo(&self) { unimplemented!() }
|
||||||
|
fn baz(&self) -> u32 { 42 }<|>
|
||||||
|
}",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_empty_impl_block() {
|
fn test_empty_impl_block() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
@ -179,4 +213,38 @@ struct S;
|
||||||
impl Foo for S {}<|>",
|
impl Foo for S {}<|>",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_empty_trait() {
|
||||||
|
check_assist_not_applicable(
|
||||||
|
add_missing_impl_members,
|
||||||
|
"
|
||||||
|
trait Foo;
|
||||||
|
struct S;
|
||||||
|
impl Foo for S { <|> }",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ignore_unnamed_trait_members() {
|
||||||
|
check_assist(
|
||||||
|
add_missing_impl_members,
|
||||||
|
"
|
||||||
|
trait Foo {
|
||||||
|
fn (arg: u32);
|
||||||
|
fn valid(some: u32) -> bool { false }
|
||||||
|
}
|
||||||
|
struct S;
|
||||||
|
impl Foo for S { <|> }",
|
||||||
|
"
|
||||||
|
trait Foo {
|
||||||
|
fn (arg: u32);
|
||||||
|
fn valid(some: u32) -> bool { false }
|
||||||
|
}
|
||||||
|
struct S;
|
||||||
|
impl Foo for S {
|
||||||
|
fn valid(some: u32) -> bool { false }<|>
|
||||||
|
}",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue