Skip to content

Commit bb80b2e

Browse files
committed
clippy nursery 🍼
1 parent 43dbcdb commit bb80b2e

File tree

9 files changed

+29
-29
lines changed

9 files changed

+29
-29
lines changed

2019/day1/day1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ struct Puzzle {
55
}
66

77
impl Puzzle {
8-
fn new() -> Puzzle {
9-
Puzzle { data: vec![] }
8+
const fn new() -> Self {
9+
Self { data: vec![] }
1010
}
1111

1212
/// Get the puzzle input.

2019/day16/day16.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn parse_data(data: &str) -> Vec<u8> {
88
.filter_map(|x| {
99
let digit = (x as u32).wrapping_sub('0' as u32);
1010
if digit < 10 {
11-
Some(digit as u8)
11+
u8::try_from(digit).ok()
1212
} else {
1313
None
1414
}
@@ -25,9 +25,9 @@ fn fft(signal: &mut [u8]) {
2525
for n in 0..signal.len() {
2626
let mut s = 0;
2727
for i in 0..signal.len() {
28-
s += pattern[(1 + i) / (1 + n) % 4] * phase[i] as i32;
28+
s += pattern[(1 + i) / (1 + n) % 4] * i32::from(phase[i]);
2929
}
30-
signal[n] = (s.abs() % 10) as u8;
30+
signal[n] = u8::try_from(s.abs() % 10).unwrap();
3131
}
3232
}
3333

@@ -37,7 +37,7 @@ fn part1(data: &[u8]) -> u32 {
3737
for _ in 0..100 {
3838
fft(&mut p);
3939
}
40-
p[0..8].iter().fold(0, |acc, d| acc * 10 + (*d as u32))
40+
p[0..8].iter().fold(0, |acc, d| acc * 10 + u32::from(*d))
4141
}
4242

4343
/// Solve part two: find the eight-digit message embedded in the final output list.
@@ -60,10 +60,10 @@ fn part2(data: &[u8]) -> u32 {
6060
t[i] = s;
6161
}
6262

63-
p = t.to_owned();
63+
p.clone_from(&t);
6464
}
6565

66-
p[0..8].iter().fold(0, |acc, d| acc * 10 + (*d as u32))
66+
p[0..8].iter().fold(0, |acc, d| acc * 10 + u32::from(*d))
6767
}
6868

6969
fn main() {

2019/day18/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ struct Puzzle {
1212
}
1313

1414
impl Puzzle {
15-
fn new() -> Puzzle {
16-
Puzzle { maze: grid![] }
15+
fn new() -> Self {
16+
Self { maze: grid![] }
1717
}
1818

1919
/// Get the puzzle input.

2019/day18/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl State {
2020
/// # Panics
2121
/// may be...
2222
#[must_use]
23-
pub fn next(&self, paths: &HashMap<u8, Vec<Path>>) -> Vec<(State, usize)> {
23+
pub fn next(&self, paths: &HashMap<u8, Vec<Path>>) -> Vec<(Self, usize)> {
2424
// impl Iterator<Item = Self> {
2525

2626
let mut result = vec![];

2019/day2/day2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const ADD: u32 = 1;
88
const MUL: u32 = 2;
99

1010
impl Puzzle {
11-
fn new() -> Puzzle {
12-
Puzzle {
11+
const fn new() -> Self {
12+
Self {
1313
program: Vec::new(),
1414
}
1515
}
@@ -33,7 +33,7 @@ impl Puzzle {
3333
fn dump(&self) -> String {
3434
self.program
3535
.iter()
36-
.map(|x| x.to_string())
36+
.map(std::string::ToString::to_string)
3737
.collect::<Vec<String>>()
3838
.join(",")
3939
}

2019/day22/day22.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! [Day 22: Slam Shuffle](https://adventofcode.com/2019/day/22)
22
3-
#![allow(clippy::unreadable_literal)]
3+
// #![allow(clippy::unreadable_literal)]
44

55
// Calculates (n^x) % p
6-
fn modular_exponent(mut n: i128, mut x: i128, p: i128) -> i128 {
6+
const fn modular_exponent(mut n: i128, mut x: i128, p: i128) -> i128 {
77
let mut ans = 1;
88
if x <= 0 {
99
return 1;
@@ -59,14 +59,14 @@ struct Congruence {
5959
impl Congruence {
6060
fn compose(&self, lhs: &Self) -> Self {
6161
assert_eq!(self.m, lhs.m);
62-
Congruence {
62+
Self {
6363
a: (self.a * lhs.a) % self.m,
6464
c: (self.c * lhs.a + lhs.c) % self.m,
6565
m: self.m,
6666
}
6767
}
6868

69-
fn value(&self, index: i128) -> i128 {
69+
const fn value(&self, index: i128) -> i128 {
7070
(self.a * index + self.c) % self.m
7171
}
7272

@@ -129,8 +129,8 @@ struct Puzzle {
129129
}
130130

131131
impl Puzzle {
132-
fn new() -> Puzzle {
133-
Puzzle { shuffles: vec![] }
132+
const fn new() -> Self {
133+
Self { shuffles: vec![] }
134134
}
135135

136136
/// Get the puzzle input.
@@ -196,12 +196,12 @@ impl Puzzle {
196196

197197
/// Solve part two.
198198
fn part2(&self) -> i128 {
199-
let m = 119315717514047;
199+
let m = 119_315_717_514_047;
200200
self.shuffles
201201
.iter()
202202
.fold(Congruence { a: 1, c: 0, m }, |acc, t| acc.compose(&t.op(m)))
203203
.inv()
204-
.pow(101741582076661)
204+
.pow(101_741_582_076_661)
205205
.value(2020)
206206
}
207207
}

2019/day3/day3.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn steps(instrs: &[Instr], target: (i32, i32)) -> u32 {
4444
0
4545
}
4646

47-
fn manhattan(p: (i32, i32)) -> i32 {
47+
const fn manhattan(p: (i32, i32)) -> i32 {
4848
p.0.abs() + p.1.abs()
4949
}
5050

@@ -53,8 +53,8 @@ struct Puzzle {
5353
}
5454

5555
impl Puzzle {
56-
fn new() -> Puzzle {
57-
Puzzle { paths: Vec::new() }
56+
const fn new() -> Self {
57+
Self { paths: Vec::new() }
5858
}
5959

6060
/// Get the puzzle input.

2019/day4/day4.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ struct Puzzle {
88
}
99

1010
impl Puzzle {
11-
fn new() -> Puzzle {
12-
Puzzle { a: 0, b: 0 }
11+
const fn new() -> Self {
12+
Self { a: 0, b: 0 }
1313
}
1414

1515
/// Get the puzzle input.

2019/day6/day6.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ struct Puzzle {
99
}
1010

1111
impl Puzzle {
12-
fn new() -> Puzzle {
13-
Puzzle {
12+
fn new() -> Self {
13+
Self {
1414
orbits: HashMap::new(),
1515
}
1616
}

0 commit comments

Comments
 (0)