Skip to content

Commit 53bc506

Browse files
authored
Fix uninlined format args (#738)
* style: inline format args * chore: add `uninlined_format_args` warning
1 parent 0b8ba06 commit 53bc506

12 files changed

+41
-53
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ quickcheck_macros = "1.0"
1919
[features]
2020
default = ["big-math"]
2121
big-math = ["dep:num-bigint", "dep:num-traits"]
22+
23+
[lints.clippy]
24+
uninlined_format_args = "warn"

src/ciphers/morse_code.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,7 @@ mod tests {
172172
#[test]
173173
fn decrypt_valid_character_set_invalid_morsecode() {
174174
let expected = format!(
175-
"{}{}{}{} {}",
176-
_UNKNOWN_MORSE_CHARACTER,
177-
_UNKNOWN_MORSE_CHARACTER,
178-
_UNKNOWN_MORSE_CHARACTER,
179-
_UNKNOWN_MORSE_CHARACTER,
180-
_UNKNOWN_MORSE_CHARACTER,
175+
"{_UNKNOWN_MORSE_CHARACTER}{_UNKNOWN_MORSE_CHARACTER}{_UNKNOWN_MORSE_CHARACTER}{_UNKNOWN_MORSE_CHARACTER} {_UNKNOWN_MORSE_CHARACTER}",
181176
);
182177

183178
let encypted = ".-.-.--.-.-. --------. ..---.-.-. .-.-.--.-.-. / .-.-.--.-.-.".to_string();

src/conversions/binary_to_hexadecimal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn binary_to_hexadecimal(binary_str: &str) -> String {
6666
}
6767

6868
if is_negative {
69-
format!("-{}", hexadecimal)
69+
format!("-{hexadecimal}")
7070
} else {
7171
hexadecimal
7272
}

src/data_structures/linked_list.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ mod tests {
241241
let second_value = 2;
242242
list.insert_at_tail(1);
243243
list.insert_at_tail(second_value);
244-
println!("Linked List is {}", list);
244+
println!("Linked List is {list}");
245245
match list.get(1) {
246246
Some(val) => assert_eq!(*val, second_value),
247-
None => panic!("Expected to find {} at index 1", second_value),
247+
None => panic!("Expected to find {second_value} at index 1"),
248248
}
249249
}
250250
#[test]
@@ -253,10 +253,10 @@ mod tests {
253253
let second_value = 2;
254254
list.insert_at_head(1);
255255
list.insert_at_head(second_value);
256-
println!("Linked List is {}", list);
256+
println!("Linked List is {list}");
257257
match list.get(0) {
258258
Some(val) => assert_eq!(*val, second_value),
259-
None => panic!("Expected to find {} at index 0", second_value),
259+
None => panic!("Expected to find {second_value} at index 0"),
260260
}
261261
}
262262

@@ -266,10 +266,10 @@ mod tests {
266266
let second_value = 2;
267267
list.insert_at_ith(0, 0);
268268
list.insert_at_ith(1, second_value);
269-
println!("Linked List is {}", list);
269+
println!("Linked List is {list}");
270270
match list.get(1) {
271271
Some(val) => assert_eq!(*val, second_value),
272-
None => panic!("Expected to find {} at index 1", second_value),
272+
None => panic!("Expected to find {second_value} at index 1"),
273273
}
274274
}
275275

@@ -279,10 +279,10 @@ mod tests {
279279
let second_value = 2;
280280
list.insert_at_ith(0, 1);
281281
list.insert_at_ith(0, second_value);
282-
println!("Linked List is {}", list);
282+
println!("Linked List is {list}");
283283
match list.get(0) {
284284
Some(val) => assert_eq!(*val, second_value),
285-
None => panic!("Expected to find {} at index 0", second_value),
285+
None => panic!("Expected to find {second_value} at index 0"),
286286
}
287287
}
288288

@@ -294,15 +294,15 @@ mod tests {
294294
list.insert_at_ith(0, 1);
295295
list.insert_at_ith(1, second_value);
296296
list.insert_at_ith(1, third_value);
297-
println!("Linked List is {}", list);
297+
println!("Linked List is {list}");
298298
match list.get(1) {
299299
Some(val) => assert_eq!(*val, third_value),
300-
None => panic!("Expected to find {} at index 1", third_value),
300+
None => panic!("Expected to find {third_value} at index 1"),
301301
}
302302

303303
match list.get(2) {
304304
Some(val) => assert_eq!(*val, second_value),
305-
None => panic!("Expected to find {} at index 1", second_value),
305+
None => panic!("Expected to find {second_value} at index 1"),
306306
}
307307
}
308308

@@ -331,7 +331,7 @@ mod tests {
331331
] {
332332
match list.get(i) {
333333
Some(val) => assert_eq!(*val, expected),
334-
None => panic!("Expected to find {} at index {}", expected, i),
334+
None => panic!("Expected to find {expected} at index {i}"),
335335
}
336336
}
337337
}
@@ -379,13 +379,13 @@ mod tests {
379379
list.insert_at_tail(second_value);
380380
match list.delete_tail() {
381381
Some(val) => assert_eq!(val, 2),
382-
None => panic!("Expected to remove {} at tail", second_value),
382+
None => panic!("Expected to remove {second_value} at tail"),
383383
}
384384

385-
println!("Linked List is {}", list);
385+
println!("Linked List is {list}");
386386
match list.get(0) {
387387
Some(val) => assert_eq!(*val, first_value),
388-
None => panic!("Expected to find {} at index 0", first_value),
388+
None => panic!("Expected to find {first_value} at index 0"),
389389
}
390390
}
391391

@@ -398,13 +398,13 @@ mod tests {
398398
list.insert_at_tail(second_value);
399399
match list.delete_head() {
400400
Some(val) => assert_eq!(val, 1),
401-
None => panic!("Expected to remove {} at head", first_value),
401+
None => panic!("Expected to remove {first_value} at head"),
402402
}
403403

404-
println!("Linked List is {}", list);
404+
println!("Linked List is {list}");
405405
match list.get(0) {
406406
Some(val) => assert_eq!(*val, second_value),
407-
None => panic!("Expected to find {} at index 0", second_value),
407+
None => panic!("Expected to find {second_value} at index 0"),
408408
}
409409
}
410410

@@ -417,7 +417,7 @@ mod tests {
417417
list.insert_at_tail(second_value);
418418
match list.delete_ith(1) {
419419
Some(val) => assert_eq!(val, 2),
420-
None => panic!("Expected to remove {} at tail", second_value),
420+
None => panic!("Expected to remove {second_value} at tail"),
421421
}
422422

423423
assert_eq!(list.length, 1);
@@ -432,7 +432,7 @@ mod tests {
432432
list.insert_at_tail(second_value);
433433
match list.delete_ith(0) {
434434
Some(val) => assert_eq!(val, 1),
435-
None => panic!("Expected to remove {} at tail", first_value),
435+
None => panic!("Expected to remove {first_value} at tail"),
436436
}
437437

438438
assert_eq!(list.length, 1);
@@ -449,12 +449,12 @@ mod tests {
449449
list.insert_at_tail(third_value);
450450
match list.delete_ith(1) {
451451
Some(val) => assert_eq!(val, 2),
452-
None => panic!("Expected to remove {} at tail", second_value),
452+
None => panic!("Expected to remove {second_value} at tail"),
453453
}
454454

455455
match list.get(1) {
456456
Some(val) => assert_eq!(*val, third_value),
457-
None => panic!("Expected to find {} at index 1", third_value),
457+
None => panic!("Expected to find {third_value} at index 1"),
458458
}
459459
}
460460

@@ -464,7 +464,7 @@ mod tests {
464464
list.insert_at_tail(1);
465465
list.insert_at_tail(2);
466466
list.insert_at_tail(3);
467-
println!("Linked List is {}", list);
467+
println!("Linked List is {list}");
468468
assert_eq!(3, list.length);
469469
}
470470

@@ -474,7 +474,7 @@ mod tests {
474474
list_str.insert_at_tail("A".to_string());
475475
list_str.insert_at_tail("B".to_string());
476476
list_str.insert_at_tail("C".to_string());
477-
println!("Linked List is {}", list_str);
477+
println!("Linked List is {list_str}");
478478
assert_eq!(3, list_str.length);
479479
}
480480

@@ -483,7 +483,7 @@ mod tests {
483483
let mut list = LinkedList::<i32>::new();
484484
list.insert_at_tail(1);
485485
list.insert_at_tail(2);
486-
println!("Linked List is {}", list);
486+
println!("Linked List is {list}");
487487
let retrived_item = list.get(1);
488488
assert!(retrived_item.is_some());
489489
assert_eq!(2, *retrived_item.unwrap());
@@ -494,7 +494,7 @@ mod tests {
494494
let mut list_str = LinkedList::<String>::new();
495495
list_str.insert_at_tail("A".to_string());
496496
list_str.insert_at_tail("B".to_string());
497-
println!("Linked List is {}", list_str);
497+
println!("Linked List is {list_str}");
498498
let retrived_item = list_str.get(1);
499499
assert!(retrived_item.is_some());
500500
assert_eq!("B", *retrived_item.unwrap());

src/data_structures/segment_tree_recursive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ impl<T: Debug + Default + Ord + Copy> SegmentTree<T> {
8080
target_idx: usize,
8181
val: T,
8282
) {
83-
println!("{:?}", element_range);
83+
println!("{element_range:?}");
8484
if element_range.start > target_idx || element_range.end <= target_idx {
8585
return;
8686
}
8787
if element_range.end - element_range.start <= 1 && element_range.start == target_idx {
88-
println!("{:?}", element_range);
88+
println!("{element_range:?}");
8989
self.tree[idx] = val;
9090
return;
9191
}

src/general/permutations/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ mod tests {
3131
}
3232
for permut_value in permuted {
3333
let count = indices.get_mut(permut_value).unwrap_or_else(|| {
34-
panic!(
35-
"Value {} appears too many times in permutation",
36-
permut_value,
37-
)
34+
panic!("Value {permut_value} appears too many times in permutation")
3835
});
3936
*count -= 1; // use this value
4037
if *count == 0 {

src/graph/decremental_connectivity.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ impl DecrementalConnectivity {
4343

4444
pub fn delete(&mut self, u: usize, v: usize) {
4545
if !self.adjacent[u].contains(&v) || self.component[u] != self.component[v] {
46-
panic!(
47-
"delete called on the edge ({}, {}) which doesn't exist",
48-
u, v
49-
);
46+
panic!("delete called on the edge ({u}, {v}) which doesn't exist");
5047
}
5148

5249
self.adjacent[u].remove(&v);
@@ -148,7 +145,7 @@ fn has_cycle(
148145
visited[node] = true;
149146
for &neighbour in adjacent[node].iter() {
150147
if !adjacent[neighbour].contains(&node) {
151-
panic!("the given graph does not strictly contain bidirectional edges\n {} -> {} exists, but the other direction does not", node, neighbour);
148+
panic!("the given graph does not strictly contain bidirectional edges\n {node} -> {neighbour} exists, but the other direction does not");
152149
}
153150
if !visited[neighbour] {
154151
if has_cycle(adjacent, visited, neighbour, node) {

src/math/binary_exponentiation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod tests {
4242
// Compute all powers from up to ten, using the standard library as the source of truth.
4343
for i in 0..10 {
4444
for j in 0..10 {
45-
println!("{}, {}", i, j);
45+
println!("{i}, {j}");
4646
assert_eq!(binary_exponentiation(i, j), u64::pow(i, j))
4747
}
4848
}

src/math/geometric_series.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod tests {
2020

2121
fn assert_approx_eq(a: f64, b: f64) {
2222
let epsilon = 1e-10;
23-
assert!((a - b).abs() < epsilon, "Expected {}, found {}", a, b);
23+
assert!((a - b).abs() < epsilon, "Expected {a}, found {b}");
2424
}
2525

2626
#[test]

src/math/sylvester_sequence.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
// Other References : https://the-algorithms.com/algorithm/sylvester-sequence?lang=python
55

66
pub fn sylvester(number: i32) -> i128 {
7-
assert!(
8-
number > 0,
9-
"The input value of [n={}] has to be > 0",
10-
number
11-
);
7+
assert!(number > 0, "The input value of [n={number}] has to be > 0");
128

139
if number == 1 {
1410
2

src/math/trig_functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ mod tests {
187187
}
188188
};
189189

190-
assert_eq!(format!("{:.5}", value), format!("{:.5}", expected_result));
190+
assert_eq!(format!("{value:.5}"), format!("{:.5}", expected_result));
191191
}
192192
}
193193

src/sorting/bingo_sort.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn bingo_sort(vec: &mut [i32]) {
3737
fn print_array(arr: &[i32]) {
3838
print!("Sorted Array: ");
3939
for &element in arr {
40-
print!("{} ", element);
40+
print!("{element} ");
4141
}
4242
println!();
4343
}

0 commit comments

Comments
 (0)