@@ -34,37 +34,44 @@ impl FunctionKind {
34
34
if parent_unwrap_call. is_none ( ) {
35
35
return Applicability :: Unspecified ;
36
36
}
37
+
37
38
match & self {
38
39
FunctionKind :: TryFromFunction ( None ) | FunctionKind :: TryIntoFunction ( None ) => Applicability :: Unspecified ,
39
40
_ => Applicability :: MachineApplicable ,
40
41
}
41
42
}
42
43
43
44
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) ) ]
49
52
}
50
53
51
54
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
+
52
66
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) ] ,
58
70
} ,
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) ] ,
66
72
_ => unreachable ! ( ) ,
67
73
} ;
74
+
68
75
sugg. push ( ( unwrap_span, String :: new ( ) ) ) ;
69
76
sugg
70
77
}
0 commit comments