]> git.lizzy.rs Git - rust.git/blob - crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
gen PartialEq for Record enums
[rust.git] / crates / ide_assists / src / handlers / replace_derive_with_manual_impl.rs
1 use hir::ModuleDef;
2 use ide_db::helpers::{import_assets::NameToImport, mod_path_to_ast};
3 use ide_db::items_locator;
4 use itertools::Itertools;
5 use syntax::{
6     ast::{self, make, AstNode, NameOwner},
7     SyntaxKind::{IDENT, WHITESPACE},
8 };
9
10 use crate::{
11     assist_context::{AssistBuilder, AssistContext, Assists},
12     utils::{
13         add_trait_assoc_items_to_impl, filter_assoc_items, gen_trait_fn_body,
14         generate_trait_impl_text, render_snippet, Cursor, DefaultMethods,
15     },
16     AssistId, AssistKind,
17 };
18
19 // Assist: replace_derive_with_manual_impl
20 //
21 // Converts a `derive` impl into a manual one.
22 //
23 // ```
24 // # trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
25 // #[derive(Deb$0ug, Display)]
26 // struct S;
27 // ```
28 // ->
29 // ```
30 // # trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
31 // #[derive(Display)]
32 // struct S;
33 //
34 // impl Debug for S {
35 //     $0fn fmt(&self, f: &mut Formatter) -> Result<()> {
36 //         f.debug_struct("S").finish()
37 //     }
38 // }
39 // ```
40 pub(crate) fn replace_derive_with_manual_impl(
41     acc: &mut Assists,
42     ctx: &AssistContext,
43 ) -> Option<()> {
44     let attr = ctx.find_node_at_offset::<ast::Attr>()?;
45     let (name, args) = attr.as_simple_call()?;
46     if name != "derive" {
47         return None;
48     }
49
50     if !args.syntax().text_range().contains(ctx.offset()) {
51         cov_mark::hit!(outside_of_attr_args);
52         return None;
53     }
54
55     let trait_token = args.syntax().token_at_offset(ctx.offset()).find(|t| t.kind() == IDENT)?;
56     let trait_name = trait_token.text();
57
58     let adt = attr.syntax().parent().and_then(ast::Adt::cast)?;
59
60     let current_module = ctx.sema.scope(adt.syntax()).module()?;
61     let current_crate = current_module.krate();
62
63     let found_traits = items_locator::items_with_name(
64         &ctx.sema,
65         current_crate,
66         NameToImport::Exact(trait_name.to_string()),
67         items_locator::AssocItemSearch::Exclude,
68         Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT.inner()),
69     )
70     .filter_map(|item| match item.as_module_def()? {
71         ModuleDef::Trait(trait_) => Some(trait_),
72         _ => None,
73     })
74     .flat_map(|trait_| {
75         current_module
76             .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_))
77             .as_ref()
78             .map(mod_path_to_ast)
79             .zip(Some(trait_))
80     });
81
82     let mut no_traits_found = true;
83     for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) {
84         add_assist(acc, ctx, &attr, &args, &trait_path, Some(trait_), &adt)?;
85     }
86     if no_traits_found {
87         let trait_path = make::ext::ident_path(trait_name);
88         add_assist(acc, ctx, &attr, &args, &trait_path, None, &adt)?;
89     }
90     Some(())
91 }
92
93 fn add_assist(
94     acc: &mut Assists,
95     ctx: &AssistContext,
96     attr: &ast::Attr,
97     input: &ast::TokenTree,
98     trait_path: &ast::Path,
99     trait_: Option<hir::Trait>,
100     adt: &ast::Adt,
101 ) -> Option<()> {
102     let target = attr.syntax().text_range();
103     let annotated_name = adt.name()?;
104     let label = format!("Convert to manual `impl {} for {}`", trait_path, annotated_name);
105     let trait_name = trait_path.segment().and_then(|seg| seg.name_ref())?;
106
107     acc.add(
108         AssistId("replace_derive_with_manual_impl", AssistKind::Refactor),
109         label,
110         target,
111         |builder| {
112             let insert_pos = adt.syntax().text_range().end();
113             let impl_def_with_items =
114                 impl_def_from_trait(&ctx.sema, adt, &annotated_name, trait_, trait_path);
115             update_attribute(builder, input, &trait_name, attr);
116             let trait_path = format!("{}", trait_path);
117             match (ctx.config.snippet_cap, impl_def_with_items) {
118                 (None, _) => {
119                     builder.insert(insert_pos, generate_trait_impl_text(adt, &trait_path, ""))
120                 }
121                 (Some(cap), None) => builder.insert_snippet(
122                     cap,
123                     insert_pos,
124                     generate_trait_impl_text(adt, &trait_path, "    $0"),
125                 ),
126                 (Some(cap), Some((impl_def, first_assoc_item))) => {
127                     let mut cursor = Cursor::Before(first_assoc_item.syntax());
128                     let placeholder;
129                     if let ast::AssocItem::Fn(ref func) = first_assoc_item {
130                         if let Some(m) = func.syntax().descendants().find_map(ast::MacroCall::cast)
131                         {
132                             if m.syntax().text() == "todo!()" {
133                                 placeholder = m;
134                                 cursor = Cursor::Replace(placeholder.syntax());
135                             }
136                         }
137                     }
138
139                     builder.insert_snippet(
140                         cap,
141                         insert_pos,
142                         format!("\n\n{}", render_snippet(cap, impl_def.syntax(), cursor)),
143                     )
144                 }
145             };
146         },
147     )
148 }
149
150 fn impl_def_from_trait(
151     sema: &hir::Semantics<ide_db::RootDatabase>,
152     adt: &ast::Adt,
153     annotated_name: &ast::Name,
154     trait_: Option<hir::Trait>,
155     trait_path: &ast::Path,
156 ) -> Option<(ast::Impl, ast::AssocItem)> {
157     let trait_ = trait_?;
158     let target_scope = sema.scope(annotated_name.syntax());
159     let trait_items = filter_assoc_items(sema.db, &trait_.items(sema.db), DefaultMethods::No);
160     if trait_items.is_empty() {
161         return None;
162     }
163     let impl_def =
164         make::impl_trait(trait_path.clone(), make::ext::ident_path(&annotated_name.text()));
165     let (impl_def, first_assoc_item) =
166         add_trait_assoc_items_to_impl(sema, trait_items, trait_, impl_def, target_scope);
167
168     // Generate a default `impl` function body for the derived trait.
169     if let ast::AssocItem::Fn(ref func) = first_assoc_item {
170         let _ = gen_trait_fn_body(func, trait_path, adt);
171     };
172
173     Some((impl_def, first_assoc_item))
174 }
175
176 fn update_attribute(
177     builder: &mut AssistBuilder,
178     input: &ast::TokenTree,
179     trait_name: &ast::NameRef,
180     attr: &ast::Attr,
181 ) {
182     let trait_name = trait_name.text();
183     let new_attr_input = input
184         .syntax()
185         .descendants_with_tokens()
186         .filter(|t| t.kind() == IDENT)
187         .filter_map(|t| t.into_token().map(|t| t.text().to_string()))
188         .filter(|t| t != &trait_name)
189         .collect::<Vec<_>>();
190     let has_more_derives = !new_attr_input.is_empty();
191
192     if has_more_derives {
193         let new_attr_input = format!("({})", new_attr_input.iter().format(", "));
194         builder.replace(input.syntax().text_range(), new_attr_input);
195     } else {
196         let attr_range = attr.syntax().text_range();
197         builder.delete(attr_range);
198
199         if let Some(line_break_range) = attr
200             .syntax()
201             .next_sibling_or_token()
202             .filter(|t| t.kind() == WHITESPACE)
203             .map(|t| t.text_range())
204         {
205             builder.delete(line_break_range);
206         }
207     }
208 }
209
210 #[cfg(test)]
211 mod tests {
212     use crate::tests::{check_assist, check_assist_not_applicable};
213
214     use super::*;
215
216     #[test]
217     fn add_custom_impl_debug_record_struct() {
218         check_assist(
219             replace_derive_with_manual_impl,
220             r#"
221 //- minicore: fmt
222 #[derive(Debu$0g)]
223 struct Foo {
224     bar: String,
225 }
226 "#,
227             r#"
228 struct Foo {
229     bar: String,
230 }
231
232 impl core::fmt::Debug for Foo {
233     $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
234         f.debug_struct("Foo").field("bar", &self.bar).finish()
235     }
236 }
237 "#,
238         )
239     }
240     #[test]
241     fn add_custom_impl_debug_tuple_struct() {
242         check_assist(
243             replace_derive_with_manual_impl,
244             r#"
245 //- minicore: fmt
246 #[derive(Debu$0g)]
247 struct Foo(String, usize);
248 "#,
249             r#"struct Foo(String, usize);
250
251 impl core::fmt::Debug for Foo {
252     $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
253         f.debug_tuple("Foo").field(&self.0).field(&self.1).finish()
254     }
255 }
256 "#,
257         )
258     }
259     #[test]
260     fn add_custom_impl_debug_empty_struct() {
261         check_assist(
262             replace_derive_with_manual_impl,
263             r#"
264 //- minicore: fmt
265 #[derive(Debu$0g)]
266 struct Foo;
267 "#,
268             r#"
269 struct Foo;
270
271 impl core::fmt::Debug for Foo {
272     $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
273         f.debug_struct("Foo").finish()
274     }
275 }
276 "#,
277         )
278     }
279     #[test]
280     fn add_custom_impl_debug_enum() {
281         check_assist(
282             replace_derive_with_manual_impl,
283             r#"
284 //- minicore: fmt
285 #[derive(Debu$0g)]
286 enum Foo {
287     Bar,
288     Baz,
289 }
290 "#,
291             r#"
292 enum Foo {
293     Bar,
294     Baz,
295 }
296
297 impl core::fmt::Debug for Foo {
298     $0fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
299         match self {
300             Self::Bar => write!(f, "Bar"),
301             Self::Baz => write!(f, "Baz"),
302         }
303     }
304 }
305 "#,
306         )
307     }
308     #[test]
309     fn add_custom_impl_default_record_struct() {
310         check_assist(
311             replace_derive_with_manual_impl,
312             r#"
313 //- minicore: default
314 #[derive(Defau$0lt)]
315 struct Foo {
316     foo: usize,
317 }
318 "#,
319             r#"
320 struct Foo {
321     foo: usize,
322 }
323
324 impl Default for Foo {
325     $0fn default() -> Self {
326         Self { foo: Default::default() }
327     }
328 }
329 "#,
330         )
331     }
332     #[test]
333     fn add_custom_impl_default_tuple_struct() {
334         check_assist(
335             replace_derive_with_manual_impl,
336             r#"
337 //- minicore: default
338 #[derive(Defau$0lt)]
339 struct Foo(usize);
340 "#,
341             r#"
342 struct Foo(usize);
343
344 impl Default for Foo {
345     $0fn default() -> Self {
346         Self(Default::default())
347     }
348 }
349 "#,
350         )
351     }
352     #[test]
353     fn add_custom_impl_default_empty_struct() {
354         check_assist(
355             replace_derive_with_manual_impl,
356             r#"
357 //- minicore: default
358 #[derive(Defau$0lt)]
359 struct Foo;
360 "#,
361             r#"
362 struct Foo;
363
364 impl Default for Foo {
365     $0fn default() -> Self {
366         Self {  }
367     }
368 }
369 "#,
370         )
371     }
372
373     #[test]
374     fn add_custom_impl_hash_record_struct() {
375         check_assist(
376             replace_derive_with_manual_impl,
377             r#"
378 //- minicore: hash
379 #[derive(Has$0h)]
380 struct Foo {
381     bin: usize,
382     bar: usize,
383 }
384 "#,
385             r#"
386 struct Foo {
387     bin: usize,
388     bar: usize,
389 }
390
391 impl core::hash::Hash for Foo {
392     $0fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
393         self.bin.hash(state);
394         self.bar.hash(state);
395     }
396 }
397 "#,
398         )
399     }
400
401     #[test]
402     fn add_custom_impl_hash_tuple_struct() {
403         check_assist(
404             replace_derive_with_manual_impl,
405             r#"
406 //- minicore: hash
407 #[derive(Has$0h)]
408 struct Foo(usize, usize);
409 "#,
410             r#"
411 struct Foo(usize, usize);
412
413 impl core::hash::Hash for Foo {
414     $0fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
415         self.0.hash(state);
416         self.1.hash(state);
417     }
418 }
419 "#,
420         )
421     }
422
423     #[test]
424     fn add_custom_impl_hash_enum() {
425         check_assist(
426             replace_derive_with_manual_impl,
427             r#"
428 //- minicore: hash
429 #[derive(Has$0h)]
430 enum Foo {
431     Bar,
432     Baz,
433 }
434 "#,
435             r#"
436 enum Foo {
437     Bar,
438     Baz,
439 }
440
441 impl core::hash::Hash for Foo {
442     $0fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
443         core::mem::discriminant(self).hash(state);
444     }
445 }
446 "#,
447         )
448     }
449
450     #[test]
451     fn add_custom_impl_clone_record_struct() {
452         check_assist(
453             replace_derive_with_manual_impl,
454             r#"
455 //- minicore: clone
456 #[derive(Clo$0ne)]
457 struct Foo {
458     bin: usize,
459     bar: usize,
460 }
461 "#,
462             r#"
463 struct Foo {
464     bin: usize,
465     bar: usize,
466 }
467
468 impl Clone for Foo {
469     $0fn clone(&self) -> Self {
470         Self { bin: self.bin.clone(), bar: self.bar.clone() }
471     }
472 }
473 "#,
474         )
475     }
476
477     #[test]
478     fn add_custom_impl_clone_tuple_struct() {
479         check_assist(
480             replace_derive_with_manual_impl,
481             r#"
482 //- minicore: clone
483 #[derive(Clo$0ne)]
484 struct Foo(usize, usize);
485 "#,
486             r#"
487 struct Foo(usize, usize);
488
489 impl Clone for Foo {
490     $0fn clone(&self) -> Self {
491         Self(self.0.clone(), self.1.clone())
492     }
493 }
494 "#,
495         )
496     }
497
498     #[test]
499     fn add_custom_impl_clone_empty_struct() {
500         check_assist(
501             replace_derive_with_manual_impl,
502             r#"
503 //- minicore: clone
504 #[derive(Clo$0ne)]
505 struct Foo;
506 "#,
507             r#"
508 struct Foo;
509
510 impl Clone for Foo {
511     $0fn clone(&self) -> Self {
512         Self {  }
513     }
514 }
515 "#,
516         )
517     }
518
519     #[test]
520     fn add_custom_impl_clone_enum() {
521         check_assist(
522             replace_derive_with_manual_impl,
523             r#"
524 //- minicore: clone
525 #[derive(Clo$0ne)]
526 enum Foo {
527     Bar,
528     Baz,
529 }
530 "#,
531             r#"
532 enum Foo {
533     Bar,
534     Baz,
535 }
536
537 impl Clone for Foo {
538     $0fn clone(&self) -> Self {
539         match self {
540             Self::Bar => Self::Bar,
541             Self::Baz => Self::Baz,
542         }
543     }
544 }
545 "#,
546         )
547     }
548
549     #[test]
550     fn add_custom_impl_clone_tuple_enum() {
551         check_assist(
552             replace_derive_with_manual_impl,
553             r#"
554 //- minicore: clone
555 #[derive(Clo$0ne)]
556 enum Foo {
557     Bar(String),
558     Baz,
559 }
560 "#,
561             r#"
562 enum Foo {
563     Bar(String),
564     Baz,
565 }
566
567 impl Clone for Foo {
568     $0fn clone(&self) -> Self {
569         match self {
570             Self::Bar(arg0) => Self::Bar(arg0.clone()),
571             Self::Baz => Self::Baz,
572         }
573     }
574 }
575 "#,
576         )
577     }
578
579     #[test]
580     fn add_custom_impl_clone_record_enum() {
581         check_assist(
582             replace_derive_with_manual_impl,
583             r#"
584 //- minicore: clone
585 #[derive(Clo$0ne)]
586 enum Foo {
587     Bar {
588         bin: String,
589     },
590     Baz,
591 }
592 "#,
593             r#"
594 enum Foo {
595     Bar {
596         bin: String,
597     },
598     Baz,
599 }
600
601 impl Clone for Foo {
602     $0fn clone(&self) -> Self {
603         match self {
604             Self::Bar { bin } => Self::Bar { bin: bin.clone() },
605             Self::Baz => Self::Baz,
606         }
607     }
608 }
609 "#,
610         )
611     }
612
613     #[test]
614     fn add_custom_impl_partial_eq_record_struct() {
615         check_assist(
616             replace_derive_with_manual_impl,
617             r#"
618 //- minicore: eq
619 #[derive(Partial$0Eq)]
620 struct Foo {
621     bin: usize,
622     bar: usize,
623 }
624 "#,
625             r#"
626 struct Foo {
627     bin: usize,
628     bar: usize,
629 }
630
631 impl PartialEq for Foo {
632     $0fn eq(&self, other: &Self) -> bool {
633         self.bin == other.bin && self.bar == other.bar
634     }
635 }
636 "#,
637         )
638     }
639
640     #[test]
641     fn add_custom_impl_partial_eq_tuple_struct() {
642         check_assist(
643             replace_derive_with_manual_impl,
644             r#"
645 //- minicore: eq
646 #[derive(Partial$0Eq)]
647 struct Foo(usize, usize);
648 "#,
649             r#"
650 struct Foo(usize, usize);
651
652 impl PartialEq for Foo {
653     $0fn eq(&self, other: &Self) -> bool {
654         self.0 == other.0 && self.1 == other.1
655     }
656 }
657 "#,
658         )
659     }
660
661     #[test]
662     fn add_custom_impl_partial_eq_empty_struct() {
663         check_assist(
664             replace_derive_with_manual_impl,
665             r#"
666 //- minicore: eq
667 #[derive(Partial$0Eq)]
668 struct Foo;
669 "#,
670             r#"
671 struct Foo;
672
673 impl PartialEq for Foo {
674     $0fn eq(&self, other: &Self) -> bool {
675         true
676     }
677 }
678 "#,
679         )
680     }
681
682     #[test]
683     fn add_custom_impl_partial_eq_enum() {
684         check_assist(
685             replace_derive_with_manual_impl,
686             r#"
687 //- minicore: eq
688 #[derive(Partial$0Eq)]
689 enum Foo {
690     Bar,
691     Baz,
692 }
693 "#,
694             r#"
695 enum Foo {
696     Bar,
697     Baz,
698 }
699
700 impl PartialEq for Foo {
701     $0fn eq(&self, other: &Self) -> bool {
702         core::mem::discriminant(self) == core::mem::discriminant(other)
703     }
704 }
705 "#,
706         )
707     }
708
709     #[test]
710     fn add_custom_impl_partial_eq_tuple_enum() {
711         check_assist(
712             replace_derive_with_manual_impl,
713             r#"
714 //- minicore: eq
715 #[derive(Partial$0Eq)]
716 enum Foo {
717     Bar(String),
718     Baz,
719 }
720 "#,
721             r#"
722 enum Foo {
723     Bar(String),
724     Baz,
725 }
726
727 impl PartialEq for Foo {
728     $0fn eq(&self, other: &Self) -> bool {
729         if core::mem::discriminant(self) == core::mem::discriminant(other) {
730             match (self, other) {
731                 (Self::Bar(l0), Self::Bar(r0)) => l0 == r0,
732                 _ => true,
733             }
734         } else {
735             false
736         }
737     }
738 }
739 "#,
740         )
741     }
742
743     #[test]
744     fn add_custom_impl_partial_eq_record_enum() {
745         check_assist(
746             replace_derive_with_manual_impl,
747             r#"
748 //- minicore: eq
749 #[derive(Partial$0Eq)]
750 enum Foo {
751     Bar {
752         bin: String,
753     },
754     Baz {
755         qux: String,
756         fez: String,
757     },
758     Qux {},
759     Bin,
760 }
761 "#,
762             r#"
763 enum Foo {
764     Bar {
765         bin: String,
766     },
767     Baz {
768         qux: String,
769         fez: String,
770     },
771     Qux {},
772     Bin,
773 }
774
775 impl PartialEq for Foo {
776     $0fn eq(&self, other: &Self) -> bool {
777         if core::mem::discriminant(self) == core::mem::discriminant(other) {
778             match (self, other) {
779                 (Self::Bar { bin: l_bin }, Self::Bar { bin: r_bin }) => l_bin == r_bin,
780                 (Self::Baz { qux: l_qux, fez: l_fez }, Self::Baz { qux: r_qux, fez: r_fez }) => l_qux == r_qux && l_fez == r_fez,
781                 _ => true,
782             }
783         } else {
784             false
785         }
786     }
787 }
788 "#,
789         )
790     }
791     #[test]
792     fn add_custom_impl_all() {
793         check_assist(
794             replace_derive_with_manual_impl,
795             r#"
796 mod foo {
797     pub trait Bar {
798         type Qux;
799         const Baz: usize = 42;
800         const Fez: usize;
801         fn foo();
802         fn bar() {}
803     }
804 }
805
806 #[derive($0Bar)]
807 struct Foo {
808     bar: String,
809 }
810 "#,
811             r#"
812 mod foo {
813     pub trait Bar {
814         type Qux;
815         const Baz: usize = 42;
816         const Fez: usize;
817         fn foo();
818         fn bar() {}
819     }
820 }
821
822 struct Foo {
823     bar: String,
824 }
825
826 impl foo::Bar for Foo {
827     $0type Qux;
828
829     const Baz: usize = 42;
830
831     const Fez: usize;
832
833     fn foo() {
834         todo!()
835     }
836 }
837 "#,
838         )
839     }
840     #[test]
841     fn add_custom_impl_for_unique_input() {
842         check_assist(
843             replace_derive_with_manual_impl,
844             r#"
845 #[derive(Debu$0g)]
846 struct Foo {
847     bar: String,
848 }
849             "#,
850             r#"
851 struct Foo {
852     bar: String,
853 }
854
855 impl Debug for Foo {
856     $0
857 }
858             "#,
859         )
860     }
861
862     #[test]
863     fn add_custom_impl_for_with_visibility_modifier() {
864         check_assist(
865             replace_derive_with_manual_impl,
866             r#"
867 #[derive(Debug$0)]
868 pub struct Foo {
869     bar: String,
870 }
871             "#,
872             r#"
873 pub struct Foo {
874     bar: String,
875 }
876
877 impl Debug for Foo {
878     $0
879 }
880             "#,
881         )
882     }
883
884     #[test]
885     fn add_custom_impl_when_multiple_inputs() {
886         check_assist(
887             replace_derive_with_manual_impl,
888             r#"
889 #[derive(Display, Debug$0, Serialize)]
890 struct Foo {}
891             "#,
892             r#"
893 #[derive(Display, Serialize)]
894 struct Foo {}
895
896 impl Debug for Foo {
897     $0
898 }
899             "#,
900         )
901     }
902
903     #[test]
904     fn test_ignore_derive_macro_without_input() {
905         check_assist_not_applicable(
906             replace_derive_with_manual_impl,
907             r#"
908 #[derive($0)]
909 struct Foo {}
910             "#,
911         )
912     }
913
914     #[test]
915     fn test_ignore_if_cursor_on_param() {
916         check_assist_not_applicable(
917             replace_derive_with_manual_impl,
918             r#"
919 #[derive$0(Debug)]
920 struct Foo {}
921             "#,
922         );
923
924         check_assist_not_applicable(
925             replace_derive_with_manual_impl,
926             r#"
927 #[derive(Debug)$0]
928 struct Foo {}
929             "#,
930         )
931     }
932
933     #[test]
934     fn test_ignore_if_not_derive() {
935         check_assist_not_applicable(
936             replace_derive_with_manual_impl,
937             r#"
938 #[allow(non_camel_$0case_types)]
939 struct Foo {}
940             "#,
941         )
942     }
943
944     #[test]
945     fn works_at_start_of_file() {
946         cov_mark::check!(outside_of_attr_args);
947         check_assist_not_applicable(
948             replace_derive_with_manual_impl,
949             r#"
950 $0#[derive(Debug)]
951 struct S;
952             "#,
953         );
954     }
955 }