@@ -34,37 +34,44 @@ impl FunctionKind {
3434 if parent_unwrap_call. is_none ( ) {
3535 return Applicability :: Unspecified ;
3636 }
37+
3738 match & self {
3839 FunctionKind :: TryFromFunction ( None ) | FunctionKind :: TryIntoFunction ( None ) => Applicability :: Unspecified ,
3940 _ => Applicability :: MachineApplicable ,
4041 }
4142 }
4243
4344 fn default_sugg ( & self , primary_span : Span ) -> Vec < ( Span , String ) > {
44- match * self {
45- FunctionKind :: TryFromFunction ( _) => vec ! [ ( primary_span, String :: from( "From::from" ) ) ] ,
46- FunctionKind :: TryIntoFunction ( _) => vec ! [ ( primary_span, String :: from( "Into::into" ) ) ] ,
47- FunctionKind :: TryIntoMethod => vec ! [ ( primary_span, String :: from( "into" ) ) ] ,
48- }
45+ let replacement = match * self {
46+ FunctionKind :: TryFromFunction ( _) => "From::from" ,
47+ FunctionKind :: TryIntoFunction ( _) => "Into::into" ,
48+ FunctionKind :: TryIntoMethod => "into" ,
49+ } ;
50+
51+ vec ! [ ( primary_span, String :: from( replacement) ) ]
4952 }
5053
5154 fn machine_applicable_sugg ( & self , primary_span : Span , unwrap_span : Span ) -> Vec < ( Span , String ) > {
55+ use FunctionKind :: * ;
56+ use SpansKind :: * ;
57+
58+ let ( trait_name, fn_name) = {
59+ let ( a, b) = match self {
60+ TryFromFunction ( _) => ( "From" , "from" ) ,
61+ TryIntoFunction ( _) | TryIntoMethod => ( "Into" , "into" ) ,
62+ } ;
63+ ( a. to_string ( ) , b. to_string ( ) )
64+ } ;
65+
5266 let mut sugg = match * self {
53- FunctionKind :: TryFromFunction ( Some ( spans) ) => match spans {
54- SpansKind :: TraitFn { trait_span, fn_span } => {
55- vec ! [ ( trait_span, String :: from( "From" ) ) , ( fn_span, String :: from( "from" ) ) ]
56- } ,
57- SpansKind :: Fn { fn_span } => vec ! [ ( fn_span, String :: from( "from" ) ) ] ,
67+ TryFromFunction ( Some ( spans) ) | TryIntoFunction ( Some ( spans) ) => match spans {
68+ TraitFn { trait_span, fn_span } => vec ! [ ( trait_span, trait_name) , ( fn_span, fn_name) ] ,
69+ Fn { fn_span } => vec ! [ ( fn_span, fn_name) ] ,
5870 } ,
59- FunctionKind :: TryIntoFunction ( Some ( spans) ) => match spans {
60- SpansKind :: TraitFn { trait_span, fn_span } => {
61- vec ! [ ( trait_span, String :: from( "Into" ) ) , ( fn_span, String :: from( "into" ) ) ]
62- } ,
63- SpansKind :: Fn { fn_span } => vec ! [ ( fn_span, String :: from( "into" ) ) ] ,
64- } ,
65- FunctionKind :: TryIntoMethod => vec ! [ ( primary_span, String :: from( "into" ) ) ] ,
71+ TryIntoMethod => vec ! [ ( primary_span, fn_name) ] ,
6672 _ => unreachable ! ( ) ,
6773 } ;
74+
6875 sugg. push ( ( unwrap_span, String :: new ( ) ) ) ;
6976 sugg
7077 }
0 commit comments