all: fix clippy lints for rust 1.65

This commit is contained in:
Antoine Martin 2022-12-06 01:17:46 +01:00
parent 1d9433098d
commit 008fb72a98
11 changed files with 21 additions and 39 deletions

View file

@ -30,13 +30,7 @@ fn compute_gamma(binary_numbers: &[&str], size: usize) -> u64 {
let mut gamma = 0;
for pos in 0..size {
let digit = if count_ones(binary_numbers, pos) > (binary_numbers.len() / 2) {
// majority of ones
1
} else {
// majority of zeroes
0
};
let digit = u64::from(count_ones(binary_numbers, pos) > (binary_numbers.len() / 2));
gamma = (gamma << 1) | digit;
}

View file

@ -120,7 +120,7 @@ impl Grid {
fn unmarked_numbers(&self) -> impl Iterator<Item = u8> + '_ {
self.number_to_pos
.iter()
.filter_map(|(num, &(x, y))| (!self.access_grid(x, y)).then(|| *num))
.filter_map(|(num, &(x, y))| (!self.access_grid(x, y)).then_some(*num))
}
fn access_grid(&self, x: usize, y: usize) -> bool {

View file

@ -73,7 +73,7 @@ impl std::str::FromStr for Rules {
let (pair, res) = l.split_once(" -> ").context("couldn't parse rule")?;
Ok((
(
*pair.as_bytes().get(0).context("couldn't parse rule")?,
*pair.as_bytes().first().context("couldn't parse rule")?,
*pair.as_bytes().get(1).context("couldn't parse rule")?,
),
res.bytes().next().context("couldn't parse rule")?,

View file

@ -64,31 +64,19 @@ impl Packet {
debug_assert_eq!(op.sub_packets.len(), 2);
let pack1 = &op.sub_packets[0];
let pack2 = &op.sub_packets[1];
if pack1.value() > pack2.value() {
1
} else {
0
}
u64::from(pack1.value() > pack2.value())
}
OperatorType::LessThan => {
debug_assert_eq!(op.sub_packets.len(), 2);
let pack1 = &op.sub_packets[0];
let pack2 = &op.sub_packets[1];
if pack1.value() < pack2.value() {
1
} else {
0
}
u64::from(pack1.value() < pack2.value())
}
OperatorType::EqualTo => {
debug_assert_eq!(op.sub_packets.len(), 2);
let pack1 = &op.sub_packets[0];
let pack2 = &op.sub_packets[1];
if pack1.value() == pack2.value() {
1
} else {
0
}
u64::from(pack1.value() == pack2.value())
}
},
}