@@ -36,7 +36,7 @@ use crate::assist_context::{AssistContext, Assists};
3636//
3737// fn main() -> () {
3838// let a = 3;
39- // let b: B = <B> ::from(a);
39+ // let b: B = B ::from(a);
4040// }
4141// ```
4242pub ( 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<'_>)
5454 let type_call = sema. type_of_expr ( & method_call. clone ( ) . into ( ) ) ?;
5555 let adjusted_tc = type_call. adjusted ( ) ;
5656
57- if adjusted_tc. is_unknown ( ) && adjusted_tc . contains_unknown ( ) {
57+ if adjusted_tc. contains_unknown ( ) {
5858 return None ;
5959 }
6060
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 ( ) ?;
6762 acc. add (
6863 AssistId ( "into_to_qualified_from" , AssistKind :: Generate ) ,
6964 "Convert `into` to fully qualified `from`" ,
7065 nameref. syntax ( ) . text_range ( ) ,
7166 |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+ ) ;
7375 } ,
7476 ) ;
7577 }
@@ -112,7 +114,7 @@ impl From<A> for B {
112114
113115fn main() -> () {
114116 let a: A = A;
115- let b: B = <B> ::from(a);
117+ let b: B = B ::from(a);
116118}"# ,
117119 )
118120 }
@@ -160,7 +162,7 @@ mod C {
160162
161163fn main() -> () {
162164 let a: A = A;
163- let b: B = <B> ::from(a);
165+ let b: B = B ::from(a);
164166}"# ,
165167 )
166168 }
@@ -204,7 +206,7 @@ mod C {
204206
205207fn main() -> () {
206208 let a: A = A;
207- let b: C::B = < C::B> ::from(a);
209+ let b: C::B = C::B::from(a);
208210}"# ,
209211 )
210212 }
0 commit comments