@@ -7,6 +7,7 @@ use rustc_hir::{Expr, ExprKind};
7
7
use rustc_lint:: { LateContext , LateLintPass } ;
8
8
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
9
9
use rustc_span:: sym;
10
+ use std:: fmt:: Write as _;
10
11
use std:: path:: Path ;
11
12
12
13
declare_clippy_lint ! {
@@ -60,10 +61,16 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
60
61
let order_of_real_vars: Vec <usize > = format_args. formatters. iter( ) . map( |( x, _) | * x) . collect( ) ;
61
62
let mut sugg = String :: new( ) ;
62
63
for n in 0 ..real_vars. len( ) {
63
- if ( !string_parts[ n] . is_empty( )
64
- && !( string_parts[ n] . ends_with( '/' ) || string_parts[ n] . ends_with( '\\' ) ) )
65
- || ( !string_parts[ n+1 ] . is_empty( )
66
- && ( !( string_parts[ n+1 ] . starts_with( '/' ) || string_parts[ n+1 ] . starts_with( '\\' ) ) ) ) {
64
+ if !(
65
+ string_parts[ n] . is_empty( )
66
+ || string_parts[ n] . ends_with( '/' )
67
+ || string_parts[ n] . ends_with( '\\' )
68
+ )
69
+ || !(
70
+ string_parts[ n+1 ] . is_empty( )
71
+ || string_parts[ n+1 ] . starts_with( '/' )
72
+ || string_parts[ n+1 ] . starts_with( '\\' )
73
+ ) {
67
74
span_lint_and_note(
68
75
cx,
69
76
PATH_FROM_FORMAT ,
@@ -80,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
80
87
}
81
88
else {
82
89
push_comps( & mut sugg, Path :: new( string_parts[ 0 ] ) ) ;
83
- sugg . push_str ( & format! ( ".join({})" , real_vars[ order_of_real_vars[ 0 ] ] ) ) ;
90
+ let _ = write! ( sugg , ".join({})" , real_vars[ order_of_real_vars[ 0 ] ] ) ;
84
91
}
85
92
}
86
93
else if string_parts[ n] . is_empty( ) {
@@ -92,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
92
99
string. remove( 0 ) ;
93
100
}
94
101
push_comps( & mut sugg, Path :: new( & string) ) ;
95
- sugg . push_str ( & format! ( ".join({})" , real_vars[ order_of_real_vars[ n] ] ) ) ;
102
+ let _ = write! ( sugg , ".join({})" , real_vars[ order_of_real_vars[ n] ] ) ;
96
103
}
97
104
}
98
105
if !string_parts[ real_vars. len( ) ] . is_empty( ) {
@@ -121,9 +128,9 @@ fn push_comps(string: &mut String, path: &Path) {
121
128
for n in comps {
122
129
let x = n. as_os_str ( ) . to_string_lossy ( ) . to_string ( ) ;
123
130
if string. is_empty ( ) {
124
- string . push_str ( & format ! ( "Path::new(\" {x}\" )" ) ) ;
131
+ let _ = write ! ( string , "Path::new(\" {x}\" )" ) ;
125
132
} else {
126
- string . push_str ( & format ! ( ".join(\" {x}\" )" ) ) ;
133
+ let _ = write ! ( string , ".join(\" {x}\" )" ) ;
127
134
}
128
135
}
129
136
}
0 commit comments