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