aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/add_missing_impl_members.rs72
1 files changed, 70 insertions, 2 deletions
diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs
index 97af6362c..5000d0122 100644
--- a/crates/ra_assists/src/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/add_missing_impl_members.rs
@@ -69,6 +69,7 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) ->
69 69
70 let missing_fns: Vec<_> = trait_fns 70 let missing_fns: Vec<_> = trait_fns
71 .into_iter() 71 .into_iter()
72 .filter(|t| def_name(t).is_some())
72 .filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t))) 73 .filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t)))
73 .collect(); 74 .collect();
74 if missing_fns.is_empty() { 75 if missing_fns.is_empty() {
@@ -89,8 +90,7 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) ->
89 .unwrap_or_else(|| impl_block_indent().to_owned() + DEFAULT_INDENT) 90 .unwrap_or_else(|| impl_block_indent().to_owned() + DEFAULT_INDENT)
90 }; 91 };
91 92
92 let mut func_bodies = missing_fns.into_iter().map(build_func_body); 93 let func_bodies = missing_fns.into_iter().map(build_func_body).join("\n");
93 let func_bodies = func_bodies.join("\n");
94 let func_bodies = String::from("\n") + &func_bodies; 94 let func_bodies = String::from("\n") + &func_bodies;
95 let func_bodies = reindent(&func_bodies, &indent) + "\n"; 95 let func_bodies = reindent(&func_bodies, &indent) + "\n";
96 96
@@ -153,6 +153,40 @@ impl Foo for S {
153 } 153 }
154 154
155 #[test] 155 #[test]
156 fn test_copied_overriden_members() {
157 check_assist(
158 add_missing_impl_members,
159 "
160trait Foo {
161 fn foo(&self);
162 fn bar(&self) -> bool { true }
163 fn baz(&self) -> u32 { 42 }
164}
165
166struct S;
167
168impl Foo for S {
169 fn bar(&self) {}
170 <|>
171}",
172 "
173trait Foo {
174 fn foo(&self);
175 fn bar(&self) -> bool { true }
176 fn baz(&self) -> u32 { 42 }
177}
178
179struct S;
180
181impl Foo for S {
182 fn bar(&self) {}
183 fn foo(&self) { unimplemented!() }
184 fn baz(&self) -> u32 { 42 }<|>
185}",
186 );
187 }
188
189 #[test]
156 fn test_empty_impl_block() { 190 fn test_empty_impl_block() {
157 check_assist( 191 check_assist(
158 add_missing_impl_members, 192 add_missing_impl_members,
@@ -179,4 +213,38 @@ struct S;
179impl Foo for S {}<|>", 213impl Foo for S {}<|>",
180 ) 214 )
181 } 215 }
216
217 #[test]
218 fn test_empty_trait() {
219 check_assist_not_applicable(
220 add_missing_impl_members,
221 "
222trait Foo;
223struct S;
224impl Foo for S { <|> }",
225 )
226 }
227
228 #[test]
229 fn test_ignore_unnamed_trait_members() {
230 check_assist(
231 add_missing_impl_members,
232 "
233trait Foo {
234 fn (arg: u32);
235 fn valid(some: u32) -> bool { false }
236}
237struct S;
238impl Foo for S { <|> }",
239 "
240trait Foo {
241 fn (arg: u32);
242 fn valid(some: u32) -> bool { false }
243}
244struct S;
245impl Foo for S {
246 fn valid(some: u32) -> bool { false }<|>
247}",
248 )
249 }
182} 250}