Skip to content

Commit 04f1b7a

Browse files
committed
[all] Run clippy
1 parent 1a1bd24 commit 04f1b7a

File tree

21 files changed

+43
-49
lines changed

21 files changed

+43
-49
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aoc2015/src/day07.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Instructions {
107107
fn eval(mut insts: Vec<Instructions>) -> u16 {
108108
let mut wires = Wires::new();
109109
while !insts.is_empty() {
110-
insts.retain(|inst| matches!(inst.exec(&mut wires), None))
110+
insts.retain(|inst| inst.exec(&mut wires).is_none())
111111
}
112112
wires["a"]
113113
}

aoc2015/src/day09.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ fn main() {
7373
let distance: usize = g.get(3).unwrap().as_str().parse().unwrap();
7474
connections
7575
.entry(from.clone())
76-
.or_insert_with(Vec::new)
76+
.or_default()
7777
.push(Connection {
7878
to: to.clone(),
7979
distance,
8080
});
8181
connections
8282
.entry(to)
83-
.or_insert_with(Vec::new)
83+
.or_default()
8484
.push(Connection { to: from, distance });
8585
} else {
8686
panic!();

aoc2015/src/day21.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,21 @@ fn fight(mut player: Entity, mut boss: Entity) -> Battle {
5151
}
5252

5353
fn main() {
54-
let weapons = vec![(8, 4, 0), (10, 5, 0), (25, 6, 0), (40, 7, 0), (74, 8, 0)];
55-
let armor = vec![
56-
(0, 0, 0),
54+
let weapons = [(8, 4, 0), (10, 5, 0), (25, 6, 0), (40, 7, 0), (74, 8, 0)];
55+
let armor = [(0, 0, 0),
5756
(13, 0, 1),
5857
(31, 0, 2),
5958
(53, 0, 3),
6059
(75, 0, 4),
61-
(102, 0, 5),
62-
];
63-
let rings = vec![
64-
(0, 0, 0),
60+
(102, 0, 5)];
61+
let rings = [(0, 0, 0),
6562
(0, 0, 0),
6663
(25, 1, 0),
6764
(50, 2, 0),
6865
(100, 3, 0),
6966
(20, 0, 1),
7067
(40, 0, 2),
71-
(80, 0, 3),
72-
];
68+
(80, 0, 3)];
7369
let mut cheapest = usize::MAX;
7470
let mut expensivest = usize::MIN;
7571
for w in weapons.iter().cloned() {

aoc2015/src/day22.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn calculate_state(state: &State, spell: Spell, min_mana: usize) -> (usize, Opti
163163
let spent = state.spent + spell.mana();
164164
let new_effect = new_player.attack(&mut new_boss, &new_effects, spell);
165165
turn_end(&mut new_effects);
166-
new_effects.extend(new_effect.into_iter());
166+
new_effects.extend(new_effect);
167167
new_boss.attack(&mut new_player, &new_effects);
168168
turn_end(&mut new_effects);
169169
if new_boss.hit_points == 0 {

aoc2016/src/day01.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
use std::{collections::HashSet, fs};
22

33
#[derive(Clone, Copy)]
4+
#[derive(Default)]
45
enum Direction {
6+
#[default]
57
North = 0,
68
East = 1,
79
South = 2,
810
West = 3,
911
}
1012

11-
impl Default for Direction {
12-
fn default() -> Self {
13-
Direction::North
14-
}
15-
}
13+
1614

1715
impl From<usize> for Direction {
1816
fn from(value: usize) -> Self {

aoc2016/src/day02.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ fn main() {
6161
((-1, -1), '7'),
6262
((0, -1), '8'),
6363
((1, -1), '9'),
64-
]
65-
.into_iter(),
64+
],
6665
);
6766
println!(
6867
"part 1: {}",
@@ -83,8 +82,7 @@ fn main() {
8382
((2, -1), 'B'),
8483
((3, -1), 'C'),
8584
((2, -2), 'D'),
86-
]
87-
.into_iter(),
85+
],
8886
);
8987
println!(
9088
"part 2: {}",

aoc2020/src/day07.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn find_containers<'a>(b: Bag<'a>, m: &HashMap<Bag<'a>, Vec<Bag<'a>>>) -> HashSe
3838
ret
3939
}
4040

41-
fn count_bags<'a>(b: Bag<'a>, m: &HashMap<Bag, HashSet<Container>>) -> usize {
41+
fn count_bags(b: Bag<'_>, m: &HashMap<Bag, HashSet<Container>>) -> usize {
4242
1 + match m.get(b) {
4343
Some(c) => c
4444
.iter()

aoc2020/src/day15.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct TurnsSeens {
77
}
88

99
fn next(prev: usize, seen: &mut collections::HashMap<usize, TurnsSeens>) -> usize {
10-
let ts = seen.entry(prev).or_insert_with(TurnsSeens::default);
10+
let ts = seen.entry(prev).or_default();
1111
let n = ts.positions.len();
1212
if ts.i > 1 {
1313
ts.positions[(ts.i + 1) % n] - ts.positions[ts.i % n]
@@ -17,7 +17,7 @@ fn next(prev: usize, seen: &mut collections::HashMap<usize, TurnsSeens>) -> usiz
1717
}
1818

1919
fn record(x: usize, idx: usize, seen: &mut collections::HashMap<usize, TurnsSeens>) {
20-
let ts = seen.entry(x).or_insert_with(TurnsSeens::default);
20+
let ts = seen.entry(x).or_default();
2121
ts.positions[ts.i % ts.positions.len()] = idx;
2222
ts.i += 1;
2323
}

aoc2020/src/day19.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn match_internal<'a>(
6464
impl NumberedRule {
6565
fn matches(&self, s: &str, rules: &HashMap<usize, NumberedRule>) -> bool {
6666
let res = match_internal(self, s.chars(), rules, 4);
67-
res.into_iter().any(|mut cs| cs.next() == None)
67+
res.into_iter().any(|mut cs| cs.next().is_none())
6868
}
6969
}
7070

aoc2020/src/day20.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl Picture {
244244
let mut t = self
245245
.tiles
246246
.iter()
247-
.find(|t| t.top == None && t.left == None)
247+
.find(|t| t.top.is_none() && t.left.is_none())
248248
.unwrap();
249249
for _ in 0..x {
250250
let pos = find_tile_position(t.right.unwrap(), &self.tiles).unwrap();

aoc2020/src/day21.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() {
2424
.and_modify(|afs| {
2525
let v = afs
2626
.iter_mut()
27-
.filter(|a| fs.iter().find(|x| x == a) != None)
27+
.filter(|a| fs.iter().any(|x| x == a))
2828
.map(|a| a.to_owned())
2929
.collect::<Vec<String>>();
3030
*afs = v;
@@ -35,7 +35,7 @@ fn main() {
3535
}
3636
let s: usize = foods
3737
.iter()
38-
.filter(|(f, _)| allergens.iter().find(|(_, fs)| fs.contains(f)) == None)
38+
.filter(|(f, _)| !allergens.iter().any(|(_, fs)| fs.contains(f)))
3939
.map(|(_, s)| s)
4040
.sum();
4141
println!("part 1: {}", s);

aoc2021/src/day12.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ fn main() {
2828
let (from, to) = line.split_once('-').unwrap();
2929
connections
3030
.entry(from.to_owned())
31-
.or_insert_with(Vec::new)
31+
.or_default()
3232
.push(to.to_owned());
3333
connections
3434
.entry(to.to_owned())
35-
.or_insert_with(Vec::new)
35+
.or_default()
3636
.push(from.to_owned());
3737
}
3838
let mut to_visit = vec![Path::new("start", HashSet::new(), false)];

aoc2021/src/day15.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Eq for Path {
6565

6666
impl PartialOrd for Path {
6767
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
68-
other.projected_cost.partial_cmp(&self.projected_cost)
68+
Some(self.cmp(other))
6969
}
7070
}
7171

aoc2021/src/day23.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl PartialEq for State {
8181

8282
impl PartialOrd for State {
8383
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
84-
other.energy.partial_cmp(&self.energy)
84+
Some(self.cmp(other))
8585
}
8686
}
8787

aoc2022/src/day05.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
for line in lines.by_ref().take_while(|l| !l.starts_with(' ')) {
3232
for (idx, item) in line.into_bytes().chunks(4).enumerate() {
3333
let value = item[1];
34-
if (b'A'..=b'Z').contains(&value) {
34+
if value.is_ascii_uppercase() {
3535
stacks1[idx].push_back(value);
3636
}
3737
}

aoc2022/src/day11.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn turn(monkeys: &mut [Monkey], current: usize, decrease: impl Fn(usize) -> usiz
8888
while let Some(worry) = monkeys[current].items.pop_front() {
8989
monkeys[current].inspected += 1;
9090
let worry = decrease(monkeys[current].operation.apply(worry));
91-
let target = if worry % monkeys[current].test as usize == 0 {
91+
let target = if worry % monkeys[current].test == 0 {
9292
monkeys[current].on_true
9393
} else {
9494
monkeys[current].on_false

aoc2022/src/day12.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Eq for Path {}
5757

5858
impl PartialOrd for Path {
5959
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
60-
other.projected_cost.partial_cmp(&self.projected_cost)
60+
Some(self.cmp(other))
6161
}
6262
}
6363

aoc2022/src/day13.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ impl Eq for Packet {}
2929

3030
impl PartialOrd for Packet {
3131
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
32-
match (self, other) {
33-
(Packet::Literal(l), Packet::Literal(r)) => l.partial_cmp(r),
34-
(Packet::List(l), Packet::List(r)) => l.partial_cmp(r),
35-
(Packet::Literal(l), Packet::List(r)) => vec![Packet::Literal(*l)].partial_cmp(r),
36-
(Packet::List(l), Packet::Literal(r)) => l.partial_cmp(&vec![Packet::Literal(*r)]),
37-
}
32+
Some(self.cmp(other))
3833
}
3934
}
4035

4136
impl Ord for Packet {
4237
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
43-
self.partial_cmp(other).unwrap()
38+
match (self, other) {
39+
(Packet::Literal(l), Packet::Literal(r)) => l.cmp(r),
40+
(Packet::List(l), Packet::List(r)) => l.cmp(r),
41+
(Packet::Literal(l), Packet::List(r)) => vec![Packet::Literal(*l)].cmp(r),
42+
(Packet::List(l), Packet::Literal(r)) => l.cmp(&vec![Packet::Literal(*r)]),
43+
}
4444
}
4545
}
4646

aoc2022/src/day19.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ impl Blueprint {
6969

7070
fn should_build(&self, pack: &Pack, robot_type: Material, built: bool) -> bool {
7171
let max_cost = self
72-
.0
73-
.iter()
74-
.map(|(_, c)| *c.0.get(&robot_type).unwrap_or(&0))
72+
.0.values().map(|c| *c.0.get(&robot_type).unwrap_or(&0))
7573
.max()
7674
.unwrap_or(0);
7775
// Are we producing enough of the material to build more robots?

aoc2022/src/day21.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ impl Job {
3333
}
3434
}
3535

36-
fn path_to<'a>(
36+
fn path_to(
3737
&self,
38-
monkeys: &'a HashMap<String, Job>,
38+
monkeys: &HashMap<String, Job>,
3939
target: &str,
4040
path: &mut HashSet<String>,
4141
) -> bool {
@@ -54,7 +54,7 @@ impl Job {
5454
}
5555
}
5656

57-
fn path_to<'a>(monkeys: &'a HashMap<String, Job>, start: &str, key: &str) -> HashSet<String> {
57+
fn path_to(monkeys: &HashMap<String, Job>, start: &str, key: &str) -> HashSet<String> {
5858
let mut result = HashSet::new();
5959
monkeys[start].path_to(monkeys, key, &mut result);
6060
result

0 commit comments

Comments
 (0)