@@ -45,14 +45,14 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
45
45
if let Some ( macro_call) = root_macro_call( args[ 0 ] . span) ;
46
46
if cx. tcx. item_name( macro_call. def_id) == sym:: format;
47
47
if let Some ( format_args) = FormatArgsExpn :: find_nested( cx, & args[ 0 ] , macro_call. expn) ;
48
- let format_string_parts = format_args. format_string_parts;
49
- let format_value_args = format_args. value_args;
50
48
then {
51
- let mut string_parts: Vec <& str > = format_string_parts. iter( ) . map( |x| x. as_str( ) ) . collect( ) ;
49
+ let format_string_parts = format_args. format_string_parts;
50
+ let format_value_args = format_args. value_args;
51
+ let mut string_parts: Vec <& str > = format_string_parts. iter( ) . map( rustc_span:: Symbol :: as_str) . collect( ) ;
52
52
string_parts. push( "" ) ;
53
53
let mut applicability = Applicability :: MachineApplicable ;
54
54
let real_vars: Vec <Sugg <' _>> = format_value_args. iter( ) . map( |x| Sugg :: hir_with_applicability( cx, x, ".." , & mut applicability) ) . collect( ) ;
55
- let order_of_real_vars: Vec <usize > = format_args. formatters. iter( ) . map( |( x, _) | x . clone ( ) ) . collect( ) ;
55
+ let order_of_real_vars: Vec <usize > = format_args. formatters. iter( ) . map( |( x, _) | * x ) . collect( ) ;
56
56
let mut sugg = String :: new( ) ;
57
57
for n in 0 ..real_vars. len( ) {
58
58
if n == 0 {
@@ -63,17 +63,15 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
63
63
sugg = format!( "Path::new(\" {}\" ).join({y})" , string_parts[ 0 ] , y = real_vars[ order_of_real_vars[ 0 ] ] ) ;
64
64
}
65
65
}
66
- else {
67
- if string_parts[ n] . is_empty( ) {
66
+ else if string_parts[ n] . is_empty( ) {
68
67
sugg = format!( "{sugg}.join({})" , real_vars[ order_of_real_vars[ n] ] ) ;
68
+ }
69
+ else {
70
+ let mut string = String :: from( string_parts[ n] ) ;
71
+ if string. starts_with( '/' ) || string. starts_with( '\\' ) {
72
+ string. remove( 0 ) ;
69
73
}
70
- else {
71
- let mut string = String :: from( string_parts[ n] ) ;
72
- if string. starts_with( '/' ) || string. starts_with( '\\' ) {
73
- string. remove( 0 ) ;
74
- }
75
- sugg = format!( "{sugg}.join(\" {}\" ).join({y})" , string, y = real_vars[ order_of_real_vars[ n] ] ) ;
76
- }
74
+ sugg = format!( "{sugg}.join(\" {}\" ).join({y})" , string, y = real_vars[ order_of_real_vars[ n] ] ) ;
77
75
}
78
76
}
79
77
if !string_parts[ real_vars. len( ) ] . is_empty( ) {
0 commit comments