]> git.lizzy.rs Git - rust.git/blob - crates/ide_completion/src/completions/trait_impl.rs
internal: Expand the derive attribute into a pseudo expansion
[rust.git] / crates / ide_completion / src / completions / trait_impl.rs
1 //! Completion for associated items in a trait implementation.
2 //!
3 //! This module adds the completion items related to implementing associated
4 //! items within an `impl Trait for Struct` block. The current context node
5 //! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node
6 //! and an direct child of an `IMPL`.
7 //!
8 //! # Examples
9 //!
10 //! Considering the following trait `impl`:
11 //!
12 //! ```ignore
13 //! trait SomeTrait {
14 //!     fn foo();
15 //! }
16 //!
17 //! impl SomeTrait for () {
18 //!     fn f$0
19 //! }
20 //! ```
21 //!
22 //! may result in the completion of the following method:
23 //!
24 //! ```ignore
25 //! # trait SomeTrait {
26 //! #    fn foo();
27 //! # }
28 //!
29 //! impl SomeTrait for () {
30 //!     fn foo() {}$0
31 //! }
32 //! ```
33
34 use hir::{self, HasAttrs};
35 use ide_db::{path_transform::PathTransform, traits::get_missing_assoc_items, SymbolKind};
36 use syntax::{
37     ast::{self, edit_in_place::AttrsOwnerEdit},
38     display::function_declaration,
39     AstNode, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, T,
40 };
41 use text_edit::TextEdit;
42
43 use crate::{CompletionContext, CompletionItem, CompletionItemKind, Completions};
44
45 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
46 enum ImplCompletionKind {
47     All,
48     Fn,
49     TypeAlias,
50     Const,
51 }
52
53 pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
54     if let Some((kind, trigger, impl_def)) = completion_match(ctx.token.clone()) {
55         if let Some(hir_impl) = ctx.sema.to_def(&impl_def) {
56             get_missing_assoc_items(&ctx.sema, &impl_def).into_iter().for_each(|item| {
57                 match (item, kind) {
58                     (
59                         hir::AssocItem::Function(fn_item),
60                         ImplCompletionKind::All | ImplCompletionKind::Fn,
61                     ) => add_function_impl(acc, ctx, &trigger, fn_item, hir_impl),
62                     (
63                         hir::AssocItem::TypeAlias(type_item),
64                         ImplCompletionKind::All | ImplCompletionKind::TypeAlias,
65                     ) => add_type_alias_impl(acc, ctx, &trigger, type_item),
66                     (
67                         hir::AssocItem::Const(const_item),
68                         ImplCompletionKind::All | ImplCompletionKind::Const,
69                     ) => add_const_impl(acc, ctx, &trigger, const_item, hir_impl),
70                     _ => {}
71                 }
72             });
73         }
74     }
75 }
76
77 fn completion_match(mut token: SyntaxToken) -> Option<(ImplCompletionKind, SyntaxNode, ast::Impl)> {
78     // For keyword without name like `impl .. { fn $0 }`, the current position is inside
79     // the whitespace token, which is outside `FN` syntax node.
80     // We need to follow the previous token in this case.
81     if token.kind() == SyntaxKind::WHITESPACE {
82         token = token.prev_token()?;
83     }
84
85     let parent_kind = token.parent().map_or(SyntaxKind::EOF, |it| it.kind());
86     let impl_item_offset = match token.kind() {
87         // `impl .. { const $0 }`
88         // ERROR      0
89         //   CONST_KW <- *
90         T![const] => 0,
91         // `impl .. { fn/type $0 }`
92         // FN/TYPE_ALIAS  0
93         //   FN_KW        <- *
94         T![fn] | T![type] => 0,
95         // `impl .. { fn/type/const foo$0 }`
96         // FN/TYPE_ALIAS/CONST  1
97         //  NAME                0
98         //    IDENT             <- *
99         SyntaxKind::IDENT if parent_kind == SyntaxKind::NAME => 1,
100         // `impl .. { foo$0 }`
101         // MACRO_CALL       3
102         //  PATH            2
103         //    PATH_SEGMENT  1
104         //      NAME_REF    0
105         //        IDENT     <- *
106         SyntaxKind::IDENT if parent_kind == SyntaxKind::NAME_REF => 3,
107         _ => return None,
108     };
109
110     let impl_item = token.ancestors().nth(impl_item_offset)?;
111     // Must directly belong to an impl block.
112     // IMPL
113     //   ASSOC_ITEM_LIST
114     //     <item>
115     let impl_def = ast::Impl::cast(impl_item.parent()?.parent()?)?;
116     let kind = match impl_item.kind() {
117         // `impl ... { const $0 fn/type/const }`
118         _ if token.kind() == T![const] => ImplCompletionKind::Const,
119         SyntaxKind::CONST | SyntaxKind::ERROR => ImplCompletionKind::Const,
120         SyntaxKind::TYPE_ALIAS => ImplCompletionKind::TypeAlias,
121         SyntaxKind::FN => ImplCompletionKind::Fn,
122         SyntaxKind::MACRO_CALL => ImplCompletionKind::All,
123         _ => return None,
124     };
125     Some((kind, impl_item, impl_def))
126 }
127
128 fn add_function_impl(
129     acc: &mut Completions,
130     ctx: &CompletionContext,
131     fn_def_node: &SyntaxNode,
132     func: hir::Function,
133     impl_def: hir::Impl,
134 ) {
135     let fn_name = func.name(ctx.db).to_smol_str();
136
137     let label = if func.assoc_fn_params(ctx.db).is_empty() {
138         format!("fn {}()", fn_name)
139     } else {
140         format!("fn {}(..)", fn_name)
141     };
142
143     let completion_kind = if func.self_param(ctx.db).is_some() {
144         CompletionItemKind::Method
145     } else {
146         CompletionItemKind::SymbolKind(SymbolKind::Function)
147     };
148
149     let range = replacement_range(ctx, fn_def_node);
150     let mut item = CompletionItem::new(completion_kind, range, label);
151     item.lookup_by(fn_name).set_documentation(func.docs(ctx.db));
152
153     if let Some(source) = ctx.sema.source(func) {
154         let assoc_item = ast::AssocItem::Fn(source.value);
155         if let Some(transformed_item) = get_transformed_assoc_item(ctx, assoc_item, impl_def) {
156             let transformed_fn = match transformed_item {
157                 ast::AssocItem::Fn(func) => func,
158                 _ => unreachable!(),
159             };
160
161             let function_decl = function_declaration(&transformed_fn);
162             match ctx.config.snippet_cap {
163                 Some(cap) => {
164                     let snippet = format!("{} {{\n    $0\n}}", function_decl);
165                     item.snippet_edit(cap, TextEdit::replace(range, snippet));
166                 }
167                 None => {
168                     let header = format!("{} {{", function_decl);
169                     item.text_edit(TextEdit::replace(range, header));
170                 }
171             };
172             item.add_to(acc);
173         }
174     }
175 }
176
177 /// Transform a relevant associated item to inline generics from the impl, remove attrs and docs, etc.
178 fn get_transformed_assoc_item(
179     ctx: &CompletionContext,
180     assoc_item: ast::AssocItem,
181     impl_def: hir::Impl,
182 ) -> Option<ast::AssocItem> {
183     let assoc_item = assoc_item.clone_for_update();
184     let trait_ = impl_def.trait_(ctx.db)?;
185     let source_scope = &ctx.sema.scope_for_def(trait_);
186     let target_scope = &ctx.sema.scope(ctx.sema.source(impl_def)?.syntax().value);
187     let transform = PathTransform::trait_impl(
188         target_scope,
189         source_scope,
190         trait_,
191         ctx.sema.source(impl_def)?.value,
192     );
193
194     transform.apply(assoc_item.syntax());
195     if let ast::AssocItem::Fn(func) = &assoc_item {
196         func.remove_attrs_and_docs();
197     }
198     Some(assoc_item)
199 }
200
201 fn add_type_alias_impl(
202     acc: &mut Completions,
203     ctx: &CompletionContext,
204     type_def_node: &SyntaxNode,
205     type_alias: hir::TypeAlias,
206 ) {
207     let alias_name = type_alias.name(ctx.db).to_smol_str();
208
209     let snippet = format!("type {} = ", alias_name);
210
211     let range = replacement_range(ctx, type_def_node);
212     let mut item = CompletionItem::new(SymbolKind::TypeAlias, range, &snippet);
213     item.text_edit(TextEdit::replace(range, snippet))
214         .lookup_by(alias_name)
215         .set_documentation(type_alias.docs(ctx.db));
216     item.add_to(acc);
217 }
218
219 fn add_const_impl(
220     acc: &mut Completions,
221     ctx: &CompletionContext,
222     const_def_node: &SyntaxNode,
223     const_: hir::Const,
224     impl_def: hir::Impl,
225 ) {
226     let const_name = const_.name(ctx.db).map(|n| n.to_smol_str());
227
228     if let Some(const_name) = const_name {
229         if let Some(source) = ctx.sema.source(const_) {
230             let assoc_item = ast::AssocItem::Const(source.value);
231             if let Some(transformed_item) = get_transformed_assoc_item(ctx, assoc_item, impl_def) {
232                 let transformed_const = match transformed_item {
233                     ast::AssocItem::Const(const_) => const_,
234                     _ => unreachable!(),
235                 };
236
237                 let snippet = make_const_compl_syntax(&transformed_const);
238
239                 let range = replacement_range(ctx, const_def_node);
240                 let mut item = CompletionItem::new(SymbolKind::Const, range, &snippet);
241                 item.text_edit(TextEdit::replace(range, snippet))
242                     .lookup_by(const_name)
243                     .set_documentation(const_.docs(ctx.db));
244                 item.add_to(acc);
245             }
246         }
247     }
248 }
249
250 fn make_const_compl_syntax(const_: &ast::Const) -> String {
251     const_.remove_attrs_and_docs();
252
253     let const_start = const_.syntax().text_range().start();
254     let const_end = const_.syntax().text_range().end();
255
256     let start =
257         const_.syntax().first_child_or_token().map_or(const_start, |f| f.text_range().start());
258
259     let end = const_
260         .syntax()
261         .children_with_tokens()
262         .find(|s| s.kind() == T![;] || s.kind() == T![=])
263         .map_or(const_end, |f| f.text_range().start());
264
265     let len = end - start;
266     let range = TextRange::new(0.into(), len);
267
268     let syntax = const_.syntax().text().slice(range).to_string();
269
270     format!("{} = ", syntax.trim_end())
271 }
272
273 fn replacement_range(ctx: &CompletionContext, item: &SyntaxNode) -> TextRange {
274     let first_child = item
275         .children_with_tokens()
276         .find(|child| {
277             !matches!(child.kind(), SyntaxKind::COMMENT | SyntaxKind::WHITESPACE | SyntaxKind::ATTR)
278         })
279         .unwrap_or_else(|| SyntaxElement::Node(item.clone()));
280
281     TextRange::new(first_child.text_range().start(), ctx.source_range().end())
282 }
283
284 #[cfg(test)]
285 mod tests {
286     use expect_test::{expect, Expect};
287
288     use crate::tests::{check_edit, completion_list_no_kw};
289
290     fn check(ra_fixture: &str, expect: Expect) {
291         let actual = completion_list_no_kw(ra_fixture);
292         expect.assert_eq(&actual)
293     }
294
295     #[test]
296     fn no_completion_inside_fn() {
297         check(
298             r"
299 trait Test { fn test(); fn test2(); }
300 struct T;
301
302 impl Test for T {
303     fn test() {
304         t$0
305     }
306 }
307 ",
308             expect![[r#"
309                 sp Self
310                 tt Test
311                 st T
312                 bt u32
313             "#]],
314         );
315
316         check(
317             r"
318 trait Test { fn test(); fn test2(); }
319 struct T;
320
321 impl Test for T {
322     fn test() {
323         fn t$0
324     }
325 }
326 ",
327             expect![[""]],
328         );
329
330         check(
331             r"
332 trait Test { fn test(); fn test2(); }
333 struct T;
334
335 impl Test for T {
336     fn test() {
337         fn $0
338     }
339 }
340 ",
341             expect![[""]],
342         );
343
344         // https://github.com/rust-analyzer/rust-analyzer/pull/5976#issuecomment-692332191
345         check(
346             r"
347 trait Test { fn test(); fn test2(); }
348 struct T;
349
350 impl Test for T {
351     fn test() {
352         foo.$0
353     }
354 }
355 ",
356             expect![[r#""#]],
357         );
358
359         check(
360             r"
361 trait Test { fn test(_: i32); fn test2(); }
362 struct T;
363
364 impl Test for T {
365     fn test(t$0)
366 }
367 ",
368             expect![[r#"
369                 sp Self
370                 st T
371             "#]],
372         );
373
374         check(
375             r"
376 trait Test { fn test(_: fn()); fn test2(); }
377 struct T;
378
379 impl Test for T {
380     fn test(f: fn $0)
381 }
382 ",
383             expect![[r#"
384                 sp Self
385                 st T
386             "#]],
387         );
388     }
389
390     #[test]
391     fn no_completion_inside_const() {
392         check(
393             r"
394 trait Test { const TEST: fn(); const TEST2: u32; type Test; fn test(); }
395 struct T;
396
397 impl Test for T {
398     const TEST: fn $0
399 }
400 ",
401             expect![[r#""#]],
402         );
403
404         check(
405             r"
406 trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
407 struct T;
408
409 impl Test for T {
410     const TEST: T$0
411 }
412 ",
413             expect![[r#"
414                 sp Self
415                 tt Test
416                 st T
417                 bt u32
418             "#]],
419         );
420
421         check(
422             r"
423 trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
424 struct T;
425
426 impl Test for T {
427     const TEST: u32 = f$0
428 }
429 ",
430             expect![[r#"
431                 sp Self
432                 tt Test
433                 st T
434                 bt u32
435             "#]],
436         );
437
438         check(
439             r"
440 trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
441 struct T;
442
443 impl Test for T {
444     const TEST: u32 = {
445         t$0
446     };
447 }
448 ",
449             expect![[r#"
450                 sp Self
451                 tt Test
452                 st T
453                 bt u32
454             "#]],
455         );
456
457         check(
458             r"
459 trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
460 struct T;
461
462 impl Test for T {
463     const TEST: u32 = {
464         fn $0
465     };
466 }
467 ",
468             expect![[""]],
469         );
470
471         check(
472             r"
473 trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
474 struct T;
475
476 impl Test for T {
477     const TEST: u32 = {
478         fn t$0
479     };
480 }
481 ",
482             expect![[""]],
483         );
484     }
485
486     #[test]
487     fn no_completion_inside_type() {
488         check(
489             r"
490 trait Test { type Test; type Test2; fn test(); }
491 struct T;
492
493 impl Test for T {
494     type Test = T$0;
495 }
496 ",
497             expect![[r#"
498                 sp Self
499                 tt Test
500                 st T
501                 bt u32
502             "#]],
503         );
504
505         check(
506             r"
507 trait Test { type Test; type Test2; fn test(); }
508 struct T;
509
510 impl Test for T {
511     type Test = fn $0;
512 }
513 ",
514             expect![[r#"
515                 sp Self
516                 tt Test
517                 st T
518                 bt u32
519             "#]],
520         );
521     }
522
523     #[test]
524     fn name_ref_single_function() {
525         check_edit(
526             "test",
527             r#"
528 trait Test {
529     fn test();
530 }
531 struct T;
532
533 impl Test for T {
534     t$0
535 }
536 "#,
537             r#"
538 trait Test {
539     fn test();
540 }
541 struct T;
542
543 impl Test for T {
544     fn test() {
545     $0
546 }
547 }
548 "#,
549         );
550     }
551
552     #[test]
553     fn single_function() {
554         check_edit(
555             "test",
556             r#"
557 trait Test {
558     fn test();
559 }
560 struct T;
561
562 impl Test for T {
563     fn t$0
564 }
565 "#,
566             r#"
567 trait Test {
568     fn test();
569 }
570 struct T;
571
572 impl Test for T {
573     fn test() {
574     $0
575 }
576 }
577 "#,
578         );
579     }
580
581     #[test]
582     fn generic_fn() {
583         check_edit(
584             "foo",
585             r#"
586 trait Test {
587     fn foo<T>();
588 }
589 struct T;
590
591 impl Test for T {
592     fn f$0
593 }
594 "#,
595             r#"
596 trait Test {
597     fn foo<T>();
598 }
599 struct T;
600
601 impl Test for T {
602     fn foo<T>() {
603     $0
604 }
605 }
606 "#,
607         );
608         check_edit(
609             "foo",
610             r#"
611 trait Test {
612     fn foo<T>() where T: Into<String>;
613 }
614 struct T;
615
616 impl Test for T {
617     fn f$0
618 }
619 "#,
620             r#"
621 trait Test {
622     fn foo<T>() where T: Into<String>;
623 }
624 struct T;
625
626 impl Test for T {
627     fn foo<T>()
628 where T: Into<String> {
629     $0
630 }
631 }
632 "#,
633         );
634     }
635
636     #[test]
637     fn associated_type() {
638         check_edit(
639             "SomeType",
640             r#"
641 trait Test {
642     type SomeType;
643 }
644
645 impl Test for () {
646     type S$0
647 }
648 "#,
649             "
650 trait Test {
651     type SomeType;
652 }
653
654 impl Test for () {
655     type SomeType = \n\
656 }
657 ",
658         );
659     }
660
661     #[test]
662     fn associated_const() {
663         check_edit(
664             "SOME_CONST",
665             r#"
666 trait Test {
667     const SOME_CONST: u16;
668 }
669
670 impl Test for () {
671     const S$0
672 }
673 "#,
674             "
675 trait Test {
676     const SOME_CONST: u16;
677 }
678
679 impl Test for () {
680     const SOME_CONST: u16 = \n\
681 }
682 ",
683         );
684
685         check_edit(
686             "SOME_CONST",
687             r#"
688 trait Test {
689     const SOME_CONST: u16 = 92;
690 }
691
692 impl Test for () {
693     const S$0
694 }
695 "#,
696             "
697 trait Test {
698     const SOME_CONST: u16 = 92;
699 }
700
701 impl Test for () {
702     const SOME_CONST: u16 = \n\
703 }
704 ",
705         );
706     }
707
708     #[test]
709     fn complete_without_name() {
710         let test = |completion: &str, hint: &str, completed: &str, next_sibling: &str| {
711             check_edit(
712                 completion,
713                 &format!(
714                     r#"
715 trait Test {{
716     type Foo;
717     const CONST: u16;
718     fn bar();
719 }}
720 struct T;
721
722 impl Test for T {{
723     {}
724     {}
725 }}
726 "#,
727                     hint, next_sibling
728                 ),
729                 &format!(
730                     r#"
731 trait Test {{
732     type Foo;
733     const CONST: u16;
734     fn bar();
735 }}
736 struct T;
737
738 impl Test for T {{
739     {}
740     {}
741 }}
742 "#,
743                     completed, next_sibling
744                 ),
745             )
746         };
747
748         // Enumerate some possible next siblings.
749         for next_sibling in &[
750             "",
751             "fn other_fn() {}", // `const $0 fn` -> `const fn`
752             "type OtherType = i32;",
753             "const OTHER_CONST: i32 = 0;",
754             "async fn other_fn() {}",
755             "unsafe fn other_fn() {}",
756             "default fn other_fn() {}",
757             "default type OtherType = i32;",
758             "default const OTHER_CONST: i32 = 0;",
759         ] {
760             test("bar", "fn $0", "fn bar() {\n    $0\n}", next_sibling);
761             test("Foo", "type $0", "type Foo = ", next_sibling);
762             test("CONST", "const $0", "const CONST: u16 = ", next_sibling);
763         }
764     }
765
766     #[test]
767     fn snippet_does_not_overwrite_comment_or_attr() {
768         let test = |completion: &str, hint: &str, completed: &str| {
769             check_edit(
770                 completion,
771                 &format!(
772                     r#"
773 trait Foo {{
774     type Type;
775     fn function();
776     const CONST: i32 = 0;
777 }}
778 struct T;
779
780 impl Foo for T {{
781     // Comment
782     #[bar]
783     {}
784 }}
785 "#,
786                     hint
787                 ),
788                 &format!(
789                     r#"
790 trait Foo {{
791     type Type;
792     fn function();
793     const CONST: i32 = 0;
794 }}
795 struct T;
796
797 impl Foo for T {{
798     // Comment
799     #[bar]
800     {}
801 }}
802 "#,
803                     completed
804                 ),
805             )
806         };
807         test("function", "fn f$0", "fn function() {\n    $0\n}");
808         test("Type", "type T$0", "type Type = ");
809         test("CONST", "const C$0", "const CONST: i32 = ");
810     }
811
812     #[test]
813     fn generics_are_inlined_in_return_type() {
814         check_edit(
815             "function",
816             r#"
817 trait Foo<T> {
818     fn function() -> T;
819 }
820 struct Bar;
821
822 impl Foo<u32> for Bar {
823     fn f$0
824 }
825 "#,
826             r#"
827 trait Foo<T> {
828     fn function() -> T;
829 }
830 struct Bar;
831
832 impl Foo<u32> for Bar {
833     fn function() -> u32 {
834     $0
835 }
836 }
837 "#,
838         )
839     }
840
841     #[test]
842     fn generics_are_inlined_in_parameter() {
843         check_edit(
844             "function",
845             r#"
846 trait Foo<T> {
847     fn function(bar: T);
848 }
849 struct Bar;
850
851 impl Foo<u32> for Bar {
852     fn f$0
853 }
854 "#,
855             r#"
856 trait Foo<T> {
857     fn function(bar: T);
858 }
859 struct Bar;
860
861 impl Foo<u32> for Bar {
862     fn function(bar: u32) {
863     $0
864 }
865 }
866 "#,
867         )
868     }
869
870     #[test]
871     fn generics_are_inlined_when_part_of_other_types() {
872         check_edit(
873             "function",
874             r#"
875 trait Foo<T> {
876     fn function(bar: Vec<T>);
877 }
878 struct Bar;
879
880 impl Foo<u32> for Bar {
881     fn f$0
882 }
883 "#,
884             r#"
885 trait Foo<T> {
886     fn function(bar: Vec<T>);
887 }
888 struct Bar;
889
890 impl Foo<u32> for Bar {
891     fn function(bar: Vec<u32>) {
892     $0
893 }
894 }
895 "#,
896         )
897     }
898
899     #[test]
900     fn generics_are_inlined_complex() {
901         check_edit(
902             "function",
903             r#"
904 trait Foo<T, U, V> {
905     fn function(bar: Vec<T>, baz: U) -> Arc<Vec<V>>;
906 }
907 struct Bar;
908
909 impl Foo<u32, Vec<usize>, u8> for Bar {
910     fn f$0
911 }
912 "#,
913             r#"
914 trait Foo<T, U, V> {
915     fn function(bar: Vec<T>, baz: U) -> Arc<Vec<V>>;
916 }
917 struct Bar;
918
919 impl Foo<u32, Vec<usize>, u8> for Bar {
920     fn function(bar: Vec<u32>, baz: Vec<usize>) -> Arc<Vec<u8>> {
921     $0
922 }
923 }
924 "#,
925         )
926     }
927
928     #[test]
929     fn generics_are_inlined_in_associated_const() {
930         check_edit(
931             "BAR",
932             r#"
933 trait Foo<T> {
934     const BAR: T;
935 }
936 struct Bar;
937
938 impl Foo<u32> for Bar {
939     const B$0;
940 }
941 "#,
942             r#"
943 trait Foo<T> {
944     const BAR: T;
945 }
946 struct Bar;
947
948 impl Foo<u32> for Bar {
949     const BAR: u32 = ;
950 }
951 "#,
952         )
953     }
954
955     #[test]
956     fn generics_are_inlined_in_where_clause() {
957         check_edit(
958             "function",
959             r#"
960 trait SomeTrait<T> {}
961
962 trait Foo<T> {
963     fn function()
964     where Self: SomeTrait<T>;
965 }
966 struct Bar;
967
968 impl Foo<u32> for Bar {
969     fn f$0
970 }
971 "#,
972             r#"
973 trait SomeTrait<T> {}
974
975 trait Foo<T> {
976     fn function()
977     where Self: SomeTrait<T>;
978 }
979 struct Bar;
980
981 impl Foo<u32> for Bar {
982     fn function()
983 where Self: SomeTrait<u32> {
984     $0
985 }
986 }
987 "#,
988         )
989     }
990 }