@@ -52,18 +52,24 @@ pub(crate) fn into_to_qualified_from(acc: &mut Assists, ctx: &AssistContext<'_>)
52
52
== FamousDefs ( sema, scope. krate ( ) ) . core_convert_Into ( ) ?
53
53
{
54
54
let type_call = sema. type_of_expr ( & method_call. clone ( ) . into ( ) ) ?;
55
- let type_call_disp =
56
- type_call. adjusted ( ) . display_source_code ( db, scope. module ( ) . into ( ) , true ) . ok ( ) ?;
55
+ let adjusted_tc = type_call. adjusted ( ) ;
56
+
57
+ if adjusted_tc. is_unknown ( ) && adjusted_tc. contains_unknown ( ) {
58
+ return None ;
59
+ }
60
+
61
+ let qualified_from = format ! (
62
+ "<{}>::from({})" ,
63
+ adjusted_tc. display_source_code( db, scope. module( ) . into( ) , true ) . ok( ) ?,
64
+ receiver
65
+ ) ;
57
66
58
67
acc. add (
59
68
AssistId ( "into_to_qualified_from" , AssistKind :: Generate ) ,
60
69
"Convert `into` to fully qualified `from`" ,
61
70
nameref. syntax ( ) . text_range ( ) ,
62
71
|edit| {
63
- edit. replace (
64
- method_call. syntax ( ) . text_range ( ) ,
65
- format ! ( "{}::from({})" , type_call_disp, receiver) ,
66
- ) ;
72
+ edit. replace ( method_call. syntax ( ) . text_range ( ) , qualified_from) ;
67
73
} ,
68
74
) ;
69
75
}
@@ -106,7 +112,7 @@ impl From<A> for B {
106
112
107
113
fn main() -> () {
108
114
let a: A = A;
109
- let b: B = B ::from(a);
115
+ let b: B = <B> ::from(a);
110
116
}"# ,
111
117
)
112
118
}
@@ -154,7 +160,7 @@ mod C {
154
160
155
161
fn main() -> () {
156
162
let a: A = A;
157
- let b: B = B ::from(a);
163
+ let b: B = <B> ::from(a);
158
164
}"# ,
159
165
)
160
166
}
@@ -198,7 +204,67 @@ mod C {
198
204
199
205
fn main() -> () {
200
206
let a: A = A;
201
- let b: C::B = C::B::from(a);
207
+ let b: C::B = <C::B>::from(a);
208
+ }"# ,
209
+ )
210
+ }
211
+
212
+ #[ test]
213
+ fn preceding_type_qualifier ( ) {
214
+ check_assist (
215
+ into_to_qualified_from,
216
+ r#"
217
+ //- minicore: from
218
+ impl From<(i32,i32)> for [i32;2] {
219
+ fn from(value: (i32,i32)) -> Self {
220
+ [value.0, value.1]
221
+ }
222
+ }
223
+
224
+ fn tuple_to_array() -> [i32; 2] {
225
+ (0,1).in$0to()
226
+ }"# ,
227
+ r#"
228
+ impl From<(i32,i32)> for [i32;2] {
229
+ fn from(value: (i32,i32)) -> Self {
230
+ [value.0, value.1]
231
+ }
232
+ }
233
+
234
+ fn tuple_to_array() -> [i32; 2] {
235
+ <[i32; 2]>::from((0,1))
236
+ }"# ,
237
+ )
238
+ }
239
+
240
+ #[ test]
241
+ fn type_with_gens ( ) {
242
+ check_assist (
243
+ into_to_qualified_from,
244
+ r#"
245
+ //- minicore: from
246
+ struct StructA<Gen>(Gen);
247
+
248
+ impl From<i32> for StructA<i32> {
249
+ fn from(value: i32) -> Self {
250
+ StructA(value + 1)
251
+ }
252
+ }
253
+
254
+ fn main() -> () {
255
+ let a: StructA<i32> = 3.in$0to();
256
+ }"# ,
257
+ r#"
258
+ struct StructA<Gen>(Gen);
259
+
260
+ impl From<i32> for StructA<i32> {
261
+ fn from(value: i32) -> Self {
262
+ StructA(value + 1)
263
+ }
264
+ }
265
+
266
+ fn main() -> () {
267
+ let a: StructA<i32> = <StructA<i32>>::from(3);
202
268
}"# ,
203
269
)
204
270
}
0 commit comments