Skip to content

Commit d076817

Browse files
committed
dogfood
1 parent 1401c8f commit d076817

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

clippy_lints/src/path_from_format.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_hir::{Expr, ExprKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::sym;
10+
use std::fmt::Write as _;
1011
use std::path::Path;
1112

1213
declare_clippy_lint! {
@@ -60,10 +61,16 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
6061
let order_of_real_vars: Vec<usize> = format_args.formatters.iter().map(|(x, _)| *x).collect();
6162
let mut sugg = String::new();
6263
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+
){
6774
span_lint_and_note(
6875
cx,
6976
PATH_FROM_FORMAT,
@@ -80,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
8087
}
8188
else {
8289
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]]);
8491
}
8592
}
8693
else if string_parts[n].is_empty() {
@@ -92,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for PathFromFormat {
9299
string.remove(0);
93100
}
94101
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]]);
96103
}
97104
}
98105
if !string_parts[real_vars.len()].is_empty() {
@@ -121,9 +128,9 @@ fn push_comps(string: &mut String, path: &Path) {
121128
for n in comps {
122129
let x = n.as_os_str().to_string_lossy().to_string();
123130
if string.is_empty() {
124-
string.push_str(&format!("Path::new(\"{x}\")"));
131+
let _ = write!(string, "Path::new(\"{x}\")");
125132
} else {
126-
string.push_str(&format!(".join(\"{x}\")"));
133+
let _ = write!(string, ".join(\"{x}\")");
127134
}
128135
}
129136
}

0 commit comments

Comments
 (0)