@@ -36,7 +36,7 @@ use crate::assist_context::{AssistContext, Assists};
36
36
//
37
37
// fn main() -> () {
38
38
// let a = 3;
39
- // let b: B = <B> ::from(a);
39
+ // let b: B = B ::from(a);
40
40
// }
41
41
// ```
42
42
pub ( crate ) fn into_to_qualified_from ( acc : & mut Assists , ctx : & AssistContext < ' _ > ) -> Option < ( ) > {
@@ -54,22 +54,24 @@ pub(crate) fn into_to_qualified_from(acc: &mut Assists, ctx: &AssistContext<'_>)
54
54
let type_call = sema. type_of_expr ( & method_call. clone ( ) . into ( ) ) ?;
55
55
let adjusted_tc = type_call. adjusted ( ) ;
56
56
57
- if adjusted_tc. is_unknown ( ) && adjusted_tc . contains_unknown ( ) {
57
+ if adjusted_tc. contains_unknown ( ) {
58
58
return None ;
59
59
}
60
60
61
- let qualified_from = format ! (
62
- "<{}>::from({})" ,
63
- adjusted_tc. display_source_code( db, scope. module( ) . into( ) , true ) . ok( ) ?,
64
- receiver
65
- ) ;
66
-
61
+ let sc = adjusted_tc. display_source_code ( db, scope. module ( ) . into ( ) , true ) . ok ( ) ?;
67
62
acc. add (
68
63
AssistId ( "into_to_qualified_from" , AssistKind :: Generate ) ,
69
64
"Convert `into` to fully qualified `from`" ,
70
65
nameref. syntax ( ) . text_range ( ) ,
71
66
|edit| {
72
- edit. replace ( method_call. syntax ( ) . text_range ( ) , qualified_from) ;
67
+ edit. replace (
68
+ method_call. syntax ( ) . text_range ( ) ,
69
+ if sc. chars ( ) . find ( |c| !c. is_alphanumeric ( ) && c != & ':' ) . is_some ( ) {
70
+ format ! ( "<{}>::from({})" , sc, receiver)
71
+ } else {
72
+ format ! ( "{}::from({})" , sc, receiver)
73
+ } ,
74
+ ) ;
73
75
} ,
74
76
) ;
75
77
}
@@ -112,7 +114,7 @@ impl From<A> for B {
112
114
113
115
fn main() -> () {
114
116
let a: A = A;
115
- let b: B = <B> ::from(a);
117
+ let b: B = B ::from(a);
116
118
}"# ,
117
119
)
118
120
}
@@ -160,7 +162,7 @@ mod C {
160
162
161
163
fn main() -> () {
162
164
let a: A = A;
163
- let b: B = <B> ::from(a);
165
+ let b: B = B ::from(a);
164
166
}"# ,
165
167
)
166
168
}
@@ -204,7 +206,7 @@ mod C {
204
206
205
207
fn main() -> () {
206
208
let a: A = A;
207
- let b: C::B = < C::B> ::from(a);
209
+ let b: C::B = C::B::from(a);
208
210
}"# ,
209
211
)
210
212
}
0 commit comments