Skip to content

Commit 2f07c07

Browse files
authored
Merge pull request #824 from bgurney-rh/rust-1.67
Resolve clippy 1.67 errors
2 parents d710bfe + 812bcd0 commit 2f07c07

File tree

12 files changed

+41
-57
lines changed

12 files changed

+41
-57
lines changed

build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ static DM_VERSIONS: &[&str] = &["4.1.0", "4.2.0", "4.6.0", "4.37.0", "4.41.0"];
1111

1212
fn main() {
1313
let version = Version::parse(&format!(
14-
"{}.{}.{}",
15-
DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL
14+
"{DM_VERSION_MAJOR}.{DM_VERSION_MINOR}.{DM_VERSION_PATCHLEVEL}"
1615
))
1716
.expect("simple version string is not parseable");
1817

src/cachedev.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl TargetParams for CacheTargetParams {
154154
self.policy_args.len(),
155155
self.policy_args
156156
.iter()
157-
.map(|(k, v)| format!("{} {}", k, v))
157+
.map(|(k, v)| format!("{k} {v}"))
158158
.collect::<Vec<String>>()
159159
.join(" ")
160160
)
@@ -556,7 +556,7 @@ impl CacheDev {
556556
cache_block_size: Sectors,
557557
) -> DmResult<CacheDev> {
558558
if device_exists(dm, name)? {
559-
let err_msg = format!("cachedev {} already exists", name);
559+
let err_msg = format!("cachedev {name} already exists");
560560
return Err(DmError::Dm(ErrorEnum::Invalid, err_msg));
561561
}
562562

@@ -713,7 +713,7 @@ impl CacheDev {
713713
fn parse_pairs(start_index: usize, vals: &[&str]) -> DmResult<(usize, Vec<(String, String)>)> {
714714
let num_pairs: usize = parse_value(vals[start_index], "number of pairs")?;
715715
if num_pairs % 2 != 0 {
716-
let err_msg = format!("Number of args \"{}\" is not even", num_pairs);
716+
let err_msg = format!("Number of args \"{num_pairs}\" is not even");
717717
return Err(DmError::Dm(ErrorEnum::Invalid, err_msg));
718718
}
719719
let next_start_index = start_index + num_pairs + 1;
@@ -857,7 +857,7 @@ mod tests {
857857

858858
assert!(!status.needs_check);
859859
}
860-
status => panic!("unexpected thinpool status: {:?}", status),
860+
status => panic!("unexpected thinpool status: {status:?}"),
861861
}
862862

863863
let table = CacheDev::read_kernel_table(&dm, &DevId::Name(cache.name()))

src/core/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl FromStr for Device {
3636
fn from_str(s: &str) -> Result<Device, DmError> {
3737
let vals = s.split(':').collect::<Vec<_>>();
3838
if vals.len() != 2 {
39-
let err_msg = format!("value \"{}\" split into wrong number of fields", s);
39+
let err_msg = format!("value \"{s}\" split into wrong number of fields");
4040
return Err(DmError::Core(errors::Error::InvalidArgument(err_msg)));
4141
}
4242
let major = vals[0].parse::<u32>().map_err(|_| {

src/core/errors.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ impl std::fmt::Display for Error {
4545
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4646
match self {
4747
Error::ContextInit(err) => {
48-
write!(f, "DM context not initialized due to IO error: {}", err)
48+
write!(f, "DM context not initialized due to IO error: {err}")
4949
}
50-
Error::InvalidArgument(err) => write!(f, "invalid argument: {}", err),
50+
Error::InvalidArgument(err) => write!(f, "invalid argument: {err}"),
5151
Error::Ioctl(op, hdr_in, hdr_out, err) => write!(
5252
f,
53-
"low-level ioctl error due to nix error; ioctl number: {}, input header: {:?}, header result: {:?}, error: {}",
54-
op, hdr_in, hdr_out, err
53+
"low-level ioctl error due to nix error; ioctl number: {op}, input header: {hdr_in:?}, header result: {hdr_out:?}, error: {err}"
5554
),
5655
Error::IoctlResultTooLarge => write!(
5756
f,
@@ -65,7 +64,7 @@ impl std::fmt::Display for Error {
6564
err
6665
),
6766
Error::GeneralIo(err) => {
68-
write!(f, "failed to perform operation due to IO error: {}", err)
67+
write!(f, "failed to perform operation due to IO error: {err}")
6968
}
7069
}
7170
}

src/core/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub enum DevId<'a> {
4444
impl<'a> fmt::Display for DevId<'a> {
4545
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4646
match *self {
47-
DevId::Name(name) => write!(f, "{}", name),
48-
DevId::Uuid(uuid) => write!(f, "{}", uuid),
47+
DevId::Name(name) => write!(f, "{name}"),
48+
DevId::Uuid(uuid) => write!(f, "{uuid}"),
4949
}
5050
}
5151
}

src/lineardev.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl FromStr for Direction {
104104
} else if s == "w" {
105105
Ok(Direction::Writes)
106106
} else {
107-
let err_msg = format!("Expected r or w, found {}", s);
107+
let err_msg = format!("Expected r or w, found {s}");
108108
Err(DmError::Dm(ErrorEnum::Invalid, err_msg))
109109
}
110110
}
@@ -145,11 +145,9 @@ impl fmt::Display for FeatureArg {
145145
match self {
146146
FeatureArg::DropWrites => write!(f, "drop_writes"),
147147
FeatureArg::ErrorWrites => write!(f, "error_writes"),
148-
FeatureArg::CorruptBioByte(offset, direction, value, flags) => write!(
149-
f,
150-
"corrupt_bio_byte {} {} {} {}",
151-
offset, direction, value, flags
152-
),
148+
FeatureArg::CorruptBioByte(offset, direction, value, flags) => {
149+
write!(f, "corrupt_bio_byte {offset} {direction} {value} {flags}")
150+
}
153151
}
154152
}
155153
}
@@ -260,7 +258,7 @@ impl FromStr for FlakeyTargetParams {
260258
result.push(FeatureArg::CorruptBioByte(offset, direction, value, flags));
261259
}
262260
x => {
263-
let err_msg = format!("{} is an unrecognized feature parameter", x);
261+
let err_msg = format!("{x} is an unrecognized feature parameter");
264262
return Err(DmError::Dm(ErrorEnum::Invalid, err_msg));
265263
}
266264
}
@@ -364,7 +362,7 @@ impl FromStr for LinearDevTargetParams {
364362
let target_type = Some(s.split_once(' ').map_or(s, |x| x.0)).ok_or_else(|| {
365363
DmError::Dm(
366364
ErrorEnum::Invalid,
367-
format!("target line string \"{}\" did not contain any values", s),
365+
format!("target line string \"{s}\" did not contain any values"),
368366
)
369367
})?;
370368
if target_type == FLAKEY_TARGET_NAME {
@@ -378,7 +376,7 @@ impl FromStr for LinearDevTargetParams {
378376
} else {
379377
Err(DmError::Dm(
380378
ErrorEnum::Invalid,
381-
format!("unexpected target type \"{}\"", target_type),
379+
format!("unexpected target type \"{target_type}\""),
382380
))
383381
}
384382
}

src/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ impl From<errors::Error> for DmError {
4545
impl fmt::Display for DmError {
4646
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4747
match *self {
48-
DmError::Core(ref err) => write!(f, "DM Core error: {}", err),
49-
DmError::Dm(ref err, ref msg) => write!(f, "DM error: {}: {}", err, msg),
48+
DmError::Core(ref err) => write!(f, "DM Core error: {err}"),
49+
DmError::Dm(ref err, ref msg) => write!(f, "DM error: {err}: {msg}"),
5050
}
5151
}
5252
}

src/shared.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ pub fn device_match<T: TargetTable, D: DmDevice<T>>(
165165
let device_table = dev.table();
166166
if !D::equivalent_tables(&kernel_table, device_table)? {
167167
let err_msg = format!(
168-
"Specified new table \"{:?}\" does not match kernel table \"{:?}\"",
169-
device_table, kernel_table
168+
"Specified new table \"{device_table:?}\" does not match kernel table \"{kernel_table:?}\""
170169
);
171170

172171
return Err(DmError::Dm(ErrorEnum::Invalid, err_msg));
@@ -187,7 +186,7 @@ pub fn device_match<T: TargetTable, D: DmDevice<T>>(
187186
/// Check if a device of the given name exists.
188187
pub fn device_exists(dm: &DM, name: &DmName) -> DmResult<bool> {
189188
dm.list_devices()
190-
.map(|l| l.iter().any(|&(ref n, _, _)| &**n == name))
189+
.map(|l| l.iter().any(|(n, _, _)| &**n == name))
191190
}
192191

193192
/// Parse a device from either of a path or a maj:min pair
@@ -197,7 +196,7 @@ pub fn parse_device(val: &str, desc: &str) -> DmResult<Device> {
197196
.ok_or_else(|| {
198197
DmError::Dm(
199198
ErrorEnum::Invalid,
200-
format!("Failed to parse \"{}\" from input \"{}\"", desc, val),
199+
format!("Failed to parse \"{desc}\" from input \"{val}\""),
201200
)
202201
})?
203202
.into()
@@ -215,10 +214,7 @@ where
215214
val.parse::<T>().map_err(|_| {
216215
DmError::Dm(
217216
ErrorEnum::Invalid,
218-
format!(
219-
"Failed to parse value for \"{}\" from input \"{}\"",
220-
desc, val
221-
),
217+
format!("Failed to parse value for \"{desc}\" from input \"{val}\""),
222218
)
223219
})
224220
}
@@ -232,8 +228,7 @@ pub fn get_status_line_fields(status_line: &str, number_required: usize) -> DmRe
232228
return Err(DmError::Dm(
233229
ErrorEnum::Invalid,
234230
format!(
235-
"Insufficient number of fields for status; requires at least {}, found only {} in status line \"{}\"",
236-
number_required, length, status_line
231+
"Insufficient number of fields for status; requires at least {number_required}, found only {length} in status line \"{status_line}\""
237232
),
238233
));
239234
}
@@ -250,7 +245,7 @@ pub fn get_status(status_lines: &[(u64, u64, String, String)]) -> DmResult<Strin
250245
format!(
251246
"Incorrect number of lines for status; expected 1, found {} in status result \"{}\"",
252247
length,
253-
status_lines.iter().map(|(s, l, t, v)| format!("{} {} {} {}", s, l, t, v)).collect::<Vec<String>>().join(", ")
248+
status_lines.iter().map(|(s, l, t, v)| format!("{s} {l} {t} {v}")).collect::<Vec<String>>().join(", ")
254249
),
255250
));
256251
}
@@ -268,8 +263,7 @@ pub fn make_unexpected_value_error(value_index: usize, value: &str, item_name: &
268263
DmError::Dm(
269264
ErrorEnum::Invalid,
270265
format!(
271-
"Kernel returned unexpected {}th value \"{}\" for item representing {} in status result",
272-
value_index, value, item_name
266+
"Kernel returned unexpected {value_index}th value \"{value}\" for item representing {item_name} in status result"
273267
),
274268
)
275269
}

src/testing/test_lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,15 @@ fn execute_cmd(cmd: &mut Command) -> DmResult<()> {
8484
match cmd.output() {
8585
Err(err) => Err(DmError::Dm(
8686
ErrorEnum::Error,
87-
format!("cmd: {:?}, error '{}'", cmd, err),
87+
format!("cmd: {cmd:?}, error '{err}'"),
8888
)),
8989
Ok(result) => {
9090
if result.status.success() {
9191
Ok(())
9292
} else {
9393
let std_out_txt = String::from_utf8_lossy(&result.stdout);
9494
let std_err_txt = String::from_utf8_lossy(&result.stderr);
95-
let err_msg = format!(
96-
"cmd: {:?} stdout: {} stderr: {}",
97-
cmd, std_out_txt, std_err_txt
98-
);
95+
let err_msg = format!("cmd: {cmd:?} stdout: {std_out_txt} stderr: {std_err_txt}");
9996
Err(DmError::Dm(ErrorEnum::Error, err_msg))
10097
}
10198
}
@@ -111,7 +108,7 @@ pub fn xfs_create_fs(devnode: &Path, uuid: Option<Uuid>) -> DmResult<()> {
111108

112109
if let Some(uuid) = uuid {
113110
command.arg("-m");
114-
command.arg(format!("uuid={}", uuid));
111+
command.arg(format!("uuid={uuid}"));
115112
}
116113
execute_cmd(&mut command)
117114
}
@@ -121,7 +118,7 @@ pub fn xfs_set_uuid(devnode: &Path, uuid: &Uuid) -> DmResult<()> {
121118
execute_cmd(
122119
Command::new("xfs_admin")
123120
.arg("-U")
124-
.arg(format!("{}", uuid))
121+
.arg(format!("{uuid}"))
125122
.arg(devnode),
126123
)
127124
}
@@ -233,7 +230,7 @@ fn dm_test_devices_remove() -> Result<()> {
233230

234231
do_while_progress().and_then(|remain| {
235232
if !remain.is_empty() {
236-
let err_msg = format!("Some test-generated DM devices remaining: {:?}", remain);
233+
let err_msg = format!("Some test-generated DM devices remaining: {remain:?}");
237234
Err(err_msg.into())
238235
} else {
239236
Ok(())

src/thindev.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ impl FromStr for ThinTargetParams {
5252
let vals = s.split(' ').collect::<Vec<_>>();
5353
let len = vals.len();
5454
if !(3..=4).contains(&len) {
55-
let err_msg = format!(
56-
"expected 3 or 4 values in params string \"{}\", found {}",
57-
s, len
58-
);
55+
let err_msg = format!("expected 3 or 4 values in params string \"{s}\", found {len}");
5956
return Err(DmError::Dm(ErrorEnum::Invalid, err_msg));
6057
}
6158

@@ -257,7 +254,7 @@ impl ThinDev {
257254
thin_pool: &ThinPoolDev,
258255
thin_id: ThinDevId,
259256
) -> DmResult<ThinDev> {
260-
message(dm, thin_pool, &format!("create_thin {}", thin_id))?;
257+
message(dm, thin_pool, &format!("create_thin {thin_id}"))?;
261258

262259
if device_exists(dm, name)? {
263260
let err_msg = "Uncreated device should not be known to kernel";
@@ -405,7 +402,7 @@ impl ThinDev {
405402
pub fn destroy(&mut self, dm: &DM, thin_pool: &ThinPoolDev) -> DmResult<()> {
406403
let thin_id = self.table.table.params.thin_id;
407404
self.teardown(dm)?;
408-
message(dm, thin_pool, &format!("delete {}", thin_id))?;
405+
message(dm, thin_pool, &format!("delete {thin_id}"))?;
409406
Ok(())
410407
}
411408
}
@@ -557,7 +554,7 @@ mod tests {
557554
udev_settle().unwrap();
558555

559556
// Make sure the uuid symlink was created
560-
let symlink = PathBuf::from(format!("/dev/disk/by-uuid/{}", path_uuid));
557+
let symlink = PathBuf::from(format!("/dev/disk/by-uuid/{path_uuid}"));
561558
assert!(symlink.exists());
562559

563560
assert_eq!(*devnode, canonicalize(symlink).unwrap());
@@ -721,7 +718,7 @@ mod tests {
721718
.unwrap();
722719

723720
for i in 0..100 {
724-
let file_path = tmp_dir.path().join(format!("devicemapper_test{}.txt", i));
721+
let file_path = tmp_dir.path().join(format!("devicemapper_test{i}.txt"));
725722
writeln!(
726723
&OpenOptions::new()
727724
.create(true)

0 commit comments

Comments
 (0)