@@ -110,10 +110,12 @@ fn signature_help_for_call(
110
110
SignatureHelp { doc : None , signature : String :: new ( ) , parameters : vec ! [ ] , active_parameter } ;
111
111
112
112
let db = sema. db ;
113
+ let mut fn_params = None ;
113
114
match callable. kind ( ) {
114
115
hir:: CallableKind :: Function ( func) => {
115
116
res. doc = func. docs ( db) . map ( |it| it. into ( ) ) ;
116
117
format_to ! ( res. signature, "fn {}" , func. name( db) ) ;
118
+ fn_params = Some ( func. assoc_fn_params ( db) ) ;
117
119
}
118
120
hir:: CallableKind :: TupleStruct ( strukt) => {
119
121
res. doc = strukt. docs ( db) . map ( |it| it. into ( ) ) ;
@@ -137,15 +139,23 @@ fn signature_help_for_call(
137
139
format_to ! ( res. signature, "{}" , self_param)
138
140
}
139
141
let mut buf = String :: new ( ) ;
140
- for ( pat, ty) in callable. params ( db) {
142
+ for ( idx , ( pat, ty) ) in callable. params ( db) . into_iter ( ) . enumerate ( ) {
141
143
buf. clear ( ) ;
142
144
if let Some ( pat) = pat {
143
145
match pat {
144
146
Either :: Left ( _self) => format_to ! ( buf, "self: " ) ,
145
147
Either :: Right ( pat) => format_to ! ( buf, "{}: " , pat) ,
146
148
}
147
149
}
148
- format_to ! ( buf, "{}" , ty. display( db) ) ;
150
+ // APITs (argument position `impl Trait`s) are inferred as {unknown} as the user is
151
+ // in the middle of entering call arguments.
152
+ // In that case, fall back to render definition of the argument.
153
+ // This is overly conservative: we do not substitute known type vars
154
+ // (see FIXME in tests::impl_trait).
155
+ match ( ty. contains_unknown ( ) , fn_params. as_deref ( ) ) {
156
+ ( true , Some ( fn_params) ) => format_to ! ( buf, "{}" , fn_params[ idx] . ty( ) . display( db) ) ,
157
+ _ => format_to ! ( buf, "{}" , ty. display( db) ) ,
158
+ }
149
159
res. push_call_param ( & buf) ;
150
160
}
151
161
}
@@ -420,8 +430,8 @@ fn foo<T, U: Copy + Display>(x: T, y: U) -> u32
420
430
fn bar() { foo($03, ); }
421
431
"# ,
422
432
expect ! [ [ r#"
423
- fn foo(x: i32, y: {unknown} ) -> u32
424
- ^^^^^^ ------------
433
+ fn foo(x: i32, y: U ) -> u32
434
+ ^^^^^^ ----
425
435
"# ] ] ,
426
436
) ;
427
437
}
@@ -633,26 +643,21 @@ pub fn do_it() {
633
643
fn test_fn_signature_with_docs_from_actix ( ) {
634
644
check (
635
645
r#"
636
- struct WriteHandler<E>;
637
-
638
- impl<E> WriteHandler<E> {
639
- /// Method is called when writer emits error.
640
- ///
641
- /// If this method returns `ErrorAction::Continue` writer processing
642
- /// continues otherwise stream processing stops.
643
- fn error(&mut self, err: E, ctx: &mut Self::Context) -> Running {
644
- Running::Stop
645
- }
646
-
646
+ trait Actor {
647
+ /// Actor execution context type
648
+ type Context;
649
+ }
650
+ trait WriteHandler<E>
651
+ where
652
+ Self: Actor
653
+ {
647
654
/// Method is called when writer finishes.
648
655
///
649
656
/// By default this method stops actor's `Context`.
650
- fn finished(&mut self, ctx: &mut Self::Context) {
651
- ctx.stop()
652
- }
657
+ fn finished(&mut self, ctx: &mut Self::Context) {}
653
658
}
654
659
655
- pub fn foo(mut r: WriteHandler<()>) {
660
+ fn foo(mut r: impl WriteHandler<()>) {
656
661
r.finished($0);
657
662
}
658
663
"# ,
@@ -661,8 +666,8 @@ pub fn foo(mut r: WriteHandler<()>) {
661
666
662
667
By default this method stops actor's `Context`.
663
668
------
664
- fn finished(&mut self, ctx: &mut {unknown} )
665
- ^^^^^^^^^^^^^^^^^^^
669
+ fn finished(&mut self, ctx: &mut <impl WriteHandler<()> as Actor>::Context )
670
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
666
671
"# ] ] ,
667
672
) ;
668
673
}
@@ -1055,4 +1060,23 @@ fn f() {
1055
1060
"# ] ] ,
1056
1061
) ;
1057
1062
}
1063
+
1064
+ #[ test]
1065
+ fn impl_trait ( ) {
1066
+ // FIXME: Substitute type vars in impl trait (`U` -> `i8`)
1067
+ check (
1068
+ r#"
1069
+ trait Trait<T> {}
1070
+ struct Wrap<T>(T);
1071
+ fn foo<U>(x: Wrap<impl Trait<U>>) {}
1072
+ fn f() {
1073
+ foo::<i8>($0)
1074
+ }
1075
+ "# ,
1076
+ expect ! [ [ r#"
1077
+ fn foo(x: Wrap<impl Trait<U>>)
1078
+ ^^^^^^^^^^^^^^^^^^^^^^
1079
+ "# ] ] ,
1080
+ ) ;
1081
+ }
1058
1082
}
0 commit comments