Skip to content

Fix uninlined format args #738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ quickcheck_macros = "1.0"
[features]
default = ["big-math"]
big-math = ["dep:num-bigint", "dep:num-traits"]

[lints.clippy]
uninlined_format_args = "warn"
7 changes: 1 addition & 6 deletions src/ciphers/morse_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,7 @@ mod tests {
#[test]
fn decrypt_valid_character_set_invalid_morsecode() {
let expected = format!(
"{}{}{}{} {}",
_UNKNOWN_MORSE_CHARACTER,
_UNKNOWN_MORSE_CHARACTER,
_UNKNOWN_MORSE_CHARACTER,
_UNKNOWN_MORSE_CHARACTER,
_UNKNOWN_MORSE_CHARACTER,
"{_UNKNOWN_MORSE_CHARACTER}{_UNKNOWN_MORSE_CHARACTER}{_UNKNOWN_MORSE_CHARACTER}{_UNKNOWN_MORSE_CHARACTER} {_UNKNOWN_MORSE_CHARACTER}",
);

let encypted = ".-.-.--.-.-. --------. ..---.-.-. .-.-.--.-.-. / .-.-.--.-.-.".to_string();
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/binary_to_hexadecimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn binary_to_hexadecimal(binary_str: &str) -> String {
}

if is_negative {
format!("-{}", hexadecimal)
format!("-{hexadecimal}")
} else {
hexadecimal
}
Expand Down
52 changes: 26 additions & 26 deletions src/data_structures/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ mod tests {
let second_value = 2;
list.insert_at_tail(1);
list.insert_at_tail(second_value);
println!("Linked List is {}", list);
println!("Linked List is {list}");
match list.get(1) {
Some(val) => assert_eq!(*val, second_value),
None => panic!("Expected to find {} at index 1", second_value),
None => panic!("Expected to find {second_value} at index 1"),
}
}
#[test]
Expand All @@ -253,10 +253,10 @@ mod tests {
let second_value = 2;
list.insert_at_head(1);
list.insert_at_head(second_value);
println!("Linked List is {}", list);
println!("Linked List is {list}");
match list.get(0) {
Some(val) => assert_eq!(*val, second_value),
None => panic!("Expected to find {} at index 0", second_value),
None => panic!("Expected to find {second_value} at index 0"),
}
}

Expand All @@ -266,10 +266,10 @@ mod tests {
let second_value = 2;
list.insert_at_ith(0, 0);
list.insert_at_ith(1, second_value);
println!("Linked List is {}", list);
println!("Linked List is {list}");
match list.get(1) {
Some(val) => assert_eq!(*val, second_value),
None => panic!("Expected to find {} at index 1", second_value),
None => panic!("Expected to find {second_value} at index 1"),
}
}

Expand All @@ -279,10 +279,10 @@ mod tests {
let second_value = 2;
list.insert_at_ith(0, 1);
list.insert_at_ith(0, second_value);
println!("Linked List is {}", list);
println!("Linked List is {list}");
match list.get(0) {
Some(val) => assert_eq!(*val, second_value),
None => panic!("Expected to find {} at index 0", second_value),
None => panic!("Expected to find {second_value} at index 0"),
}
}

Expand All @@ -294,15 +294,15 @@ mod tests {
list.insert_at_ith(0, 1);
list.insert_at_ith(1, second_value);
list.insert_at_ith(1, third_value);
println!("Linked List is {}", list);
println!("Linked List is {list}");
match list.get(1) {
Some(val) => assert_eq!(*val, third_value),
None => panic!("Expected to find {} at index 1", third_value),
None => panic!("Expected to find {third_value} at index 1"),
}

match list.get(2) {
Some(val) => assert_eq!(*val, second_value),
None => panic!("Expected to find {} at index 1", second_value),
None => panic!("Expected to find {second_value} at index 1"),
}
}

Expand Down Expand Up @@ -331,7 +331,7 @@ mod tests {
] {
match list.get(i) {
Some(val) => assert_eq!(*val, expected),
None => panic!("Expected to find {} at index {}", expected, i),
None => panic!("Expected to find {expected} at index {i}"),
}
}
}
Expand Down Expand Up @@ -379,13 +379,13 @@ mod tests {
list.insert_at_tail(second_value);
match list.delete_tail() {
Some(val) => assert_eq!(val, 2),
None => panic!("Expected to remove {} at tail", second_value),
None => panic!("Expected to remove {second_value} at tail"),
}

println!("Linked List is {}", list);
println!("Linked List is {list}");
match list.get(0) {
Some(val) => assert_eq!(*val, first_value),
None => panic!("Expected to find {} at index 0", first_value),
None => panic!("Expected to find {first_value} at index 0"),
}
}

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

println!("Linked List is {}", list);
println!("Linked List is {list}");
match list.get(0) {
Some(val) => assert_eq!(*val, second_value),
None => panic!("Expected to find {} at index 0", second_value),
None => panic!("Expected to find {second_value} at index 0"),
}
}

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

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

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

match list.get(1) {
Some(val) => assert_eq!(*val, third_value),
None => panic!("Expected to find {} at index 1", third_value),
None => panic!("Expected to find {third_value} at index 1"),
}
}

Expand All @@ -464,7 +464,7 @@ mod tests {
list.insert_at_tail(1);
list.insert_at_tail(2);
list.insert_at_tail(3);
println!("Linked List is {}", list);
println!("Linked List is {list}");
assert_eq!(3, list.length);
}

Expand All @@ -474,7 +474,7 @@ mod tests {
list_str.insert_at_tail("A".to_string());
list_str.insert_at_tail("B".to_string());
list_str.insert_at_tail("C".to_string());
println!("Linked List is {}", list_str);
println!("Linked List is {list_str}");
assert_eq!(3, list_str.length);
}

Expand All @@ -483,7 +483,7 @@ mod tests {
let mut list = LinkedList::<i32>::new();
list.insert_at_tail(1);
list.insert_at_tail(2);
println!("Linked List is {}", list);
println!("Linked List is {list}");
let retrived_item = list.get(1);
assert!(retrived_item.is_some());
assert_eq!(2, *retrived_item.unwrap());
Expand All @@ -494,7 +494,7 @@ mod tests {
let mut list_str = LinkedList::<String>::new();
list_str.insert_at_tail("A".to_string());
list_str.insert_at_tail("B".to_string());
println!("Linked List is {}", list_str);
println!("Linked List is {list_str}");
let retrived_item = list_str.get(1);
assert!(retrived_item.is_some());
assert_eq!("B", *retrived_item.unwrap());
Expand Down
4 changes: 2 additions & 2 deletions src/data_structures/segment_tree_recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ impl<T: Debug + Default + Ord + Copy> SegmentTree<T> {
target_idx: usize,
val: T,
) {
println!("{:?}", element_range);
println!("{element_range:?}");
if element_range.start > target_idx || element_range.end <= target_idx {
return;
}
if element_range.end - element_range.start <= 1 && element_range.start == target_idx {
println!("{:?}", element_range);
println!("{element_range:?}");
self.tree[idx] = val;
return;
}
Expand Down
5 changes: 1 addition & 4 deletions src/general/permutations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ mod tests {
}
for permut_value in permuted {
let count = indices.get_mut(permut_value).unwrap_or_else(|| {
panic!(
"Value {} appears too many times in permutation",
permut_value,
)
panic!("Value {permut_value} appears too many times in permutation")
});
*count -= 1; // use this value
if *count == 0 {
Expand Down
7 changes: 2 additions & 5 deletions src/graph/decremental_connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ impl DecrementalConnectivity {

pub fn delete(&mut self, u: usize, v: usize) {
if !self.adjacent[u].contains(&v) || self.component[u] != self.component[v] {
panic!(
"delete called on the edge ({}, {}) which doesn't exist",
u, v
);
panic!("delete called on the edge ({u}, {v}) which doesn't exist");
}

self.adjacent[u].remove(&v);
Expand Down Expand Up @@ -148,7 +145,7 @@ fn has_cycle(
visited[node] = true;
for &neighbour in adjacent[node].iter() {
if !adjacent[neighbour].contains(&node) {
panic!("the given graph does not strictly contain bidirectional edges\n {} -> {} exists, but the other direction does not", node, neighbour);
panic!("the given graph does not strictly contain bidirectional edges\n {node} -> {neighbour} exists, but the other direction does not");
}
if !visited[neighbour] {
if has_cycle(adjacent, visited, neighbour, node) {
Expand Down
2 changes: 1 addition & 1 deletion src/math/binary_exponentiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod tests {
// Compute all powers from up to ten, using the standard library as the source of truth.
for i in 0..10 {
for j in 0..10 {
println!("{}, {}", i, j);
println!("{i}, {j}");
assert_eq!(binary_exponentiation(i, j), u64::pow(i, j))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/math/geometric_series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod tests {

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

#[test]
Expand Down
6 changes: 1 addition & 5 deletions src/math/sylvester_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
// Other References : https://the-algorithms.com/algorithm/sylvester-sequence?lang=python

pub fn sylvester(number: i32) -> i128 {
assert!(
number > 0,
"The input value of [n={}] has to be > 0",
number
);
assert!(number > 0, "The input value of [n={number}] has to be > 0");

if number == 1 {
2
Expand Down
2 changes: 1 addition & 1 deletion src/math/trig_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod tests {
}
};

assert_eq!(format!("{:.5}", value), format!("{:.5}", expected_result));
assert_eq!(format!("{value:.5}"), format!("{:.5}", expected_result));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sorting/bingo_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn bingo_sort(vec: &mut [i32]) {
fn print_array(arr: &[i32]) {
print!("Sorted Array: ");
for &element in arr {
print!("{} ", element);
print!("{element} ");
}
println!();
}
Expand Down