Skip to content

Commit

Permalink
Simplifications from clippy
Browse files Browse the repository at this point in the history
`clippy::uninlined_format_args` and 2 more.
  • Loading branch information
Philippe-Cholet committed Jul 4, 2024
1 parent ca8a8fb commit df00c92
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions benches/powerset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fn calc_iters(n: usize) -> usize {
}

fn powerset_n(c: &mut Criterion, n: usize) {
let id = format!("powerset {}", n);
let id = format!("powerset {n}");
c.bench_function(id.as_str(), move |b| {
b.iter(|| {
for _ in 0..calc_iters(n) {
Expand All @@ -21,7 +21,7 @@ fn powerset_n(c: &mut Criterion, n: usize) {
}

fn powerset_n_fold(c: &mut Criterion, n: usize) {
let id = format!("powerset {} fold", n);
let id = format!("powerset {n} fold");
c.bench_function(id.as_str(), move |b| {
b.iter(|| {
for _ in 0..calc_iters(n) {
Expand Down
4 changes: 2 additions & 2 deletions examples/iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn main() {
});
let mut irises = match irises {
Err(e) => {
println!("Error parsing: {:?}", e);
println!("Error parsing: {e:?}");
std::process::exit(1);
}
Ok(data) => data,
Expand Down Expand Up @@ -101,7 +101,7 @@ fn main() {

// using Itertools::tuple_combinations
for (a, b) in (0..4).tuple_combinations() {
println!("Column {} vs {}:", a, b);
println!("Column {a} vs {b}:");

// Clear plot
//
Expand Down
12 changes: 3 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2320,10 +2320,10 @@ pub trait Itertools: Iterator {
// estimate lower bound of capacity needed
let (lower, _) = self.size_hint();
let mut result = String::with_capacity(sep.len() * lower);
write!(&mut result, "{}", first_elt).unwrap();
write!(&mut result, "{first_elt}").unwrap();
self.for_each(|elt| {
result.push_str(sep);
write!(&mut result, "{}", elt).unwrap();
write!(&mut result, "{elt}").unwrap();
});
result
}
Expand Down Expand Up @@ -4522,13 +4522,7 @@ where
(Some(a), Some(b)) => a == b,
_ => false,
};
assert!(
equal,
"Failed assertion {a:?} == {b:?} for iteration {i}",
i = i,
a = a,
b = b
);
assert!(equal, "Failed assertion {a:?} == {b:?} for iteration {i}");
i += 1;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/process_results_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ where

impl<'a, I, T, E> DoubleEndedIterator for ProcessResults<'a, I, E>
where
I: Iterator<Item = Result<T, E>>,
I: DoubleEndedIterator,
I: DoubleEndedIterator<Item = Result<T, E>>,
{
fn next_back(&mut self) -> Option<Self::Item> {
let item = self.iter.next_back();
Expand Down
2 changes: 1 addition & 1 deletion src/repeatn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
fn next(&mut self) -> Option<Self::Item> {
if self.n > 1 {
self.n -= 1;
self.elt.as_ref().cloned()
self.elt.clone()
} else {
self.n = 0;
self.elt.take()
Expand Down
10 changes: 4 additions & 6 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ where
let actual_count = total_actual_count - i;
if actual_count != returned_count {
println!(
"Total iterations: {} True count: {} returned count: {}",
i, actual_count, returned_count
"Total iterations: {i} True count: {actual_count} returned count: {returned_count}"
);

return false;
Expand Down Expand Up @@ -676,7 +675,7 @@ quickcheck! {
assert_eq!(perm.len(), k);

let all_items_valid = perm.iter().all(|p| vals.contains(p));
assert!(all_items_valid, "perm contains value not from input: {:?}", perm);
assert!(all_items_valid, "perm contains value not from input: {perm:?}");

// Check that all perm items are distinct
let distinct_len = {
Expand All @@ -686,7 +685,7 @@ quickcheck! {
assert_eq!(perm.len(), distinct_len);

// Check that the perm is new
assert!(actual.insert(perm.clone()), "perm already encountered: {:?}", perm);
assert!(actual.insert(perm.clone()), "perm already encountered: {perm:?}");
}
}

Expand All @@ -712,8 +711,7 @@ quickcheck! {
for next_perm in perms {
assert!(
next_perm > curr_perm,
"next perm isn't greater-than current; next_perm={:?} curr_perm={:?} n={}",
next_perm, curr_perm, n
"next perm isn't greater-than current; next_perm={next_perm:?} curr_perm={curr_perm:?} n={n}"
);

curr_perm = next_perm;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ fn tree_reduce() {
Some(s.to_string())
};
let num_strings = (0..i).map(|x| x.to_string());
let actual = num_strings.tree_reduce(|a, b| format!("{} {} x", a, b));
let actual = num_strings.tree_reduce(|a, b| format!("{a} {b} x"));
assert_eq!(actual, expected);
}
}
Expand Down

0 comments on commit df00c92

Please sign in to comment.