Skip to content

Commit 1a17ea9

Browse files
chore: fix clippy 1.88 errors (#783)
Fixed clippy 1.88
1 parent 7d0de48 commit 1a17ea9

File tree

19 files changed

+80
-103
lines changed

19 files changed

+80
-103
lines changed

cargo-insta/src/cli.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn query_snapshot(
278278
println!(
279279
"{}{}{} {}@{}:",
280280
style("Reviewing [").bold(),
281-
style(format!("{}/{}", i, n)).yellow().bold(),
281+
style(format!("{i}/{n}")).yellow().bold(),
282282
style("]").bold(),
283283
pkg.name.as_str(),
284284
&pkg.version,
@@ -449,12 +449,9 @@ fn handle_target_args<'a>(
449449
(None, None) => {}
450450
};
451451

452-
let metadata = cmd.exec().map_err(|e| {
453-
format!(
454-
"failed to load cargo metadata: {}. Command details: {:?}",
455-
e, cmd
456-
)
457-
})?;
452+
let metadata = cmd
453+
.exec()
454+
.map_err(|e| format!("failed to load cargo metadata: {e}. Command details: {cmd:?}"))?;
458455
let workspace_root = metadata.workspace_root.as_std_path().to_path_buf();
459456
let tool_config = ToolConfig::from_workspace(&workspace_root)?;
460457

@@ -501,7 +498,7 @@ fn handle_target_args<'a>(
501498
.iter()
502499
.map(|x| {
503500
if let Some(no_period) = x.strip_prefix(".") {
504-
eprintln!("`{}` supplied as an extension. This will use `foo.{}` as file names; likely you want `{}` instead.", x, x, no_period)
501+
eprintln!("`{x}` supplied as an extension. This will use `foo.{x}` as file names; likely you want `{no_period}` instead.")
505502
};
506503
x.as_str()
507504
})
@@ -656,19 +653,19 @@ fn review_snapshots(
656653
if !accepted.is_empty() {
657654
println!("{}:", style("accepted").green());
658655
for item in accepted {
659-
println!(" {}", item);
656+
println!(" {item}");
660657
}
661658
}
662659
if !rejected.is_empty() {
663660
println!("{}:", style("rejected").red());
664661
for item in rejected {
665-
println!(" {}", item);
662+
println!(" {item}");
666663
}
667664
}
668665
if !skipped.is_empty() {
669666
println!("{}:", style("skipped").yellow());
670667
for item in skipped {
671-
println!(" {}", item);
668+
println!(" {item}");
672669
}
673670
}
674671
}
@@ -941,7 +938,7 @@ fn handle_unreferenced_snapshots(
941938
// load it, since these are in a different format; just delete
942939
if path.extension() == Some(std::ffi::OsStr::new("pending-snap")) {
943940
if let Err(e) = fs::remove_file(path) {
944-
eprintln!("Failed to remove file: {}", e);
941+
eprintln!("Failed to remove file: {e}");
945942
}
946943
} else {
947944
let snapshot = match Snapshot::from_file(&path) {
@@ -1156,7 +1153,7 @@ fn prepare_test_runner<'snapshot_ref>(
11561153
if matches!(color, ColorWhen::Auto)
11571154
&& matches!(test_runner, TestRunner::CargoTest | TestRunner::Auto)
11581155
{
1159-
proc.arg(format!("--color={}", color));
1156+
proc.arg(format!("--color={color}"));
11601157
};
11611158
Ok((proc, snapshot_ref_file, prevents_doc_run))
11621159
}
@@ -1273,7 +1270,7 @@ fn show_undiscovered_hint(
12731270
let fname = x.file_name().to_string_lossy();
12741271
extensions
12751272
.iter()
1276-
.any(|ext| fname.ends_with(&format!(".{}.new", ext)))
1273+
.any(|ext| fname.ends_with(&format!(".{ext}.new")))
12771274
|| fname.ends_with(".pending-snap")
12781275
})
12791276
.map(|x| x.path().to_path_buf())

cargo-insta/src/container.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ impl PendingSnapshot {
3333
use std::fmt::Write;
3434
let mut rv = String::new();
3535
if let Some(source) = self.new.metadata().source() {
36-
write!(&mut rv, "{}", source).unwrap();
36+
write!(&mut rv, "{source}").unwrap();
3737
}
3838
if let Some(line) = self.line {
39-
write!(&mut rv, ":{}", line).unwrap();
39+
write!(&mut rv, ":{line}").unwrap();
4040
}
4141
if let Some(name) = self.new.snapshot_name() {
42-
write!(&mut rv, " ({})", name).unwrap();
42+
write!(&mut rv, " ({name})").unwrap();
4343
}
4444
rv
4545
}
@@ -173,8 +173,7 @@ impl SnapshotContainer {
173173
let try_removing_snapshot = |p: &Path| {
174174
fs::remove_file(p).unwrap_or_else(|_| {
175175
eprintln!(
176-
"Pending snapshot file at {:?} couldn't be removed. It was likely removed by another process.",
177-
p
176+
"Pending snapshot file at {p:?} couldn't be removed. It was likely removed by another process."
178177
);
179178
});
180179
};

cargo-insta/src/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl FilePatcher {
5656
.tempfile_in(self.filename.parent().ok_or("Parent directory not found")?)?;
5757

5858
for line in &self.lines {
59-
writeln!(temp_file, "{}", line)?;
59+
writeln!(temp_file, "{line}")?;
6060
}
6161

6262
temp_file.flush()?;

cargo-insta/src/walk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(crate) fn make_snapshot_walker(
7676

7777
extensions
7878
.iter()
79-
.flat_map(|ext| [format!("*.{}", ext), format!("*.{}.new", ext)])
79+
.flat_map(|ext| [format!("*.{ext}"), format!("*.{ext}.new")])
8080
.chain(std::iter::once("*.pending-snap".to_string()))
8181
.for_each(|pattern| {
8282
override_builder.add(&pattern).unwrap();

cargo-insta/tests/functional/main.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl TestFiles {
126126
format!(
127127
r#"
128128
[package]
129-
name = "{}"
129+
name = "{name}"
130130
version = "0.1.0"
131131
edition = "2021"
132132
@@ -135,8 +135,7 @@ doctest = false
135135
136136
[dependencies]
137137
insta = {{ path = '$PROJECT_PATH' }}
138-
"#,
139-
name
138+
"#
140139
),
141140
)
142141
}
@@ -258,8 +257,8 @@ impl TestProject {
258257
&updated_content,
259258
3,
260259
Some((
261-
&format!("Original: {}", file_path),
262-
&format!("Updated: {}", file_path),
260+
&format!("Original: {file_path}"),
261+
&format!("Updated: {file_path}"),
263262
)),
264263
)
265264
}
@@ -308,14 +307,13 @@ fn test_force_update_snapshots() {
308307
format!(
309308
r#"
310309
[package]
311-
name = "test_force_update_{}"
310+
name = "test_force_update_{name}"
312311
version = "0.1.0"
313312
edition = "2021"
314313
315314
[dependencies]
316-
insta = {}
317-
"#,
318-
name, insta_dependency
315+
insta = {insta_dependency}
316+
"#
319317
)
320318
.to_string(),
321319
)
@@ -330,10 +328,7 @@ fn test_snapshot_with_newline() {
330328
.to_string(),
331329
)
332330
.add_file(
333-
format!(
334-
"src/snapshots/test_force_update_{}__force_update.snap",
335-
name
336-
),
331+
format!("src/snapshots/test_force_update_{name}__force_update.snap"),
337332
r#"
338333
---
339334
source: src/lib.rs

cargo-insta/tests/functional/test_workspace_source_path.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ fn test_something() {
8181
// The source path should be relative and start with ../ (since workspace and project are siblings)
8282
assert!(
8383
source_path.starts_with("../"),
84-
"Source path should be relative starting with '../', but got: {}",
85-
source_path
84+
"Source path should be relative starting with '../', but got: {source_path}"
8685
);
8786

8887
// The path should be exactly ../project1/src/lib.rs
@@ -201,12 +200,10 @@ fn test_app2() {
201200
// Both should have relative paths
202201
assert!(
203202
snapshot1_content.contains("source: \"../../projects/app1/src/lib.rs\""),
204-
"App1 snapshot source is not the expected relative path. Got:\n{}",
205-
snapshot1_content
203+
"App1 snapshot source is not the expected relative path. Got:\n{snapshot1_content}"
206204
);
207205
assert!(
208206
snapshot2_content.contains("source: \"../../projects/app2/src/lib.rs\""),
209-
"App2 snapshot source is not the expected relative path. Got:\n{}",
210-
snapshot2_content
207+
"App2 snapshot source is not the expected relative path. Got:\n{snapshot2_content}"
211208
);
212209
}

cargo-insta/tests/functional/unreferenced.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ Unused snapshot
306306
let stderr = String::from_utf8_lossy(&output.stderr);
307307
assert!(
308308
stderr.contains("encountered unreferenced snapshots"),
309-
"Expected error message about unreferenced snapshots, got: {}",
310-
stderr
309+
"Expected error message about unreferenced snapshots, got: {stderr}"
311310
);
312311

313312
// Now run without flags - this should also fail due to the config file setting
@@ -328,8 +327,7 @@ Unused snapshot
328327
let stderr = String::from_utf8_lossy(&output.stderr);
329328
assert!(
330329
stderr.contains("encountered unreferenced snapshots"),
331-
"Expected error message about unreferenced snapshots, got: {}",
332-
stderr
330+
"Expected error message about unreferenced snapshots, got: {stderr}"
333331
);
334332

335333
// Run with --unreferenced=delete to clean up

cargo-insta/tests/functional/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ fn test_in_root() {
879879
let stderr = String::from_utf8_lossy(&output.stderr);
880880

881881
// There should only be 1 snapshot
882-
assert!(stderr.contains("1 snapshot to review"), "\n\n{}", stderr);
882+
assert!(stderr.contains("1 snapshot to review"), "\n\n{stderr}");
883883
}
884884

885885
/// Check that `--manifest` points `cargo-insta` at another path

insta/src/content/json.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::content::Content;
77
const COMPACT_MAX_CHARS: usize = 120;
88

99
pub fn format_float<T: Display>(value: T) -> String {
10-
let mut rv = format!("{}", value);
10+
let mut rv = format!("{value}");
1111
if !rv.contains('.') {
1212
rv.push_str(".0");
1313
}
@@ -116,16 +116,16 @@ impl Serializer {
116116
match value {
117117
Content::Bool(true) => self.write_str("true"),
118118
Content::Bool(false) => self.write_str("false"),
119-
Content::U8(n) => write!(self.out, "{}", n).unwrap(),
120-
Content::U16(n) => write!(self.out, "{}", n).unwrap(),
121-
Content::U32(n) => write!(self.out, "{}", n).unwrap(),
122-
Content::U64(n) => write!(self.out, "{}", n).unwrap(),
123-
Content::U128(n) => write!(self.out, "{}", n).unwrap(),
124-
Content::I8(n) => write!(self.out, "{}", n).unwrap(),
125-
Content::I16(n) => write!(self.out, "{}", n).unwrap(),
126-
Content::I32(n) => write!(self.out, "{}", n).unwrap(),
127-
Content::I64(n) => write!(self.out, "{}", n).unwrap(),
128-
Content::I128(n) => write!(self.out, "{}", n).unwrap(),
119+
Content::U8(n) => write!(self.out, "{n}").unwrap(),
120+
Content::U16(n) => write!(self.out, "{n}").unwrap(),
121+
Content::U32(n) => write!(self.out, "{n}").unwrap(),
122+
Content::U64(n) => write!(self.out, "{n}").unwrap(),
123+
Content::U128(n) => write!(self.out, "{n}").unwrap(),
124+
Content::I8(n) => write!(self.out, "{n}").unwrap(),
125+
Content::I16(n) => write!(self.out, "{n}").unwrap(),
126+
Content::I32(n) => write!(self.out, "{n}").unwrap(),
127+
Content::I64(n) => write!(self.out, "{n}").unwrap(),
128+
Content::I128(n) => write!(self.out, "{n}").unwrap(),
129129
Content::F32(f) => {
130130
if f.is_finite() {
131131
self.write_str(&format_float(f));

insta/src/content/yaml/vendored/emitter.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a> YamlEmitter<'a> {
138138
if need_quotes(v) {
139139
escape_str(self.writer, v)?;
140140
} else {
141-
write!(self.writer, "{}", v)?;
141+
write!(self.writer, "{v}")?;
142142
}
143143
Ok(())
144144
}
@@ -151,11 +151,11 @@ impl<'a> YamlEmitter<'a> {
151151
Ok(())
152152
}
153153
Yaml::Integer(v) => {
154-
write!(self.writer, "{}", v)?;
154+
write!(self.writer, "{v}")?;
155155
Ok(())
156156
}
157157
Yaml::Real(ref v) => {
158-
write!(self.writer, "{}", v)?;
158+
write!(self.writer, "{v}")?;
159159
Ok(())
160160
}
161161
Yaml::Null | Yaml::BadValue => {
@@ -340,8 +340,8 @@ a4:
340340
let mut emitter = YamlEmitter::new(&mut writer);
341341
emitter.dump(doc).unwrap();
342342
}
343-
println!("original:\n{}", s);
344-
println!("emitted:\n{}", writer);
343+
println!("original:\n{s}");
344+
println!("emitted:\n{writer}");
345345
let docs_new = match YamlLoader::load_from_str(&writer) {
346346
Ok(y) => y,
347347
Err(e) => panic!("{}", e),
@@ -431,7 +431,7 @@ z: string with spaces"#;
431431
emitter.dump(doc).unwrap();
432432
}
433433

434-
assert_eq!(s, writer, "actual:\n\n{}\n", writer);
434+
assert_eq!(s, writer, "actual:\n\n{writer}\n");
435435
}
436436

437437
#[test]
@@ -491,8 +491,7 @@ bool1: false"#;
491491

492492
assert_eq!(
493493
expected, writer,
494-
"expected:\n{}\nactual:\n{}\n",
495-
expected, writer
494+
"expected:\n{expected}\nactual:\n{writer}\n"
496495
);
497496
}
498497

@@ -535,8 +534,8 @@ a:
535534
let mut emitter = YamlEmitter::new(&mut writer);
536535
emitter.dump(doc).unwrap();
537536
}
538-
println!("original:\n{}", s);
539-
println!("emitted:\n{}", writer);
537+
println!("original:\n{s}");
538+
println!("emitted:\n{writer}");
540539

541540
assert_eq!(s, writer);
542541
}
@@ -559,8 +558,8 @@ a:
559558
let mut emitter = YamlEmitter::new(&mut writer);
560559
emitter.dump(doc).unwrap();
561560
}
562-
println!("original:\n{}", s);
563-
println!("emitted:\n{}", writer);
561+
println!("original:\n{s}");
562+
println!("emitted:\n{writer}");
564563

565564
assert_eq!(s, writer);
566565
}
@@ -581,8 +580,8 @@ a:
581580
let mut emitter = YamlEmitter::new(&mut writer);
582581
emitter.dump(doc).unwrap();
583582
}
584-
println!("original:\n{}", s);
585-
println!("emitted:\n{}", writer);
583+
println!("original:\n{s}");
584+
println!("emitted:\n{writer}");
586585

587586
assert_eq!(s, writer);
588587
}

0 commit comments

Comments
 (0)