Skip to content

Commit 3548f35

Browse files
committed
Rustc lints
1 parent c223708 commit 3548f35

File tree

14 files changed

+64
-34
lines changed

14 files changed

+64
-34
lines changed

Diff for: src/lib.rs

+30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,36 @@
55
// Configure rustdoc
66
#![doc(html_logo_url = "https://maneatingape.github.io/advent-of-code-rust/logo.png")]
77
#![allow(rustdoc::private_intra_doc_links)]
8+
// Stricter Rustc lints
9+
#![warn(
10+
absolute_paths_not_starting_with_crate,
11+
elided_lifetimes_in_paths,
12+
explicit_outlives_requirements,
13+
ffi_unwind_calls,
14+
//invalid_reference_casting, // Not supported by GitHub actions yet
15+
keyword_idents,
16+
let_underscore_drop,
17+
macro_use_extern_crate,
18+
meta_variable_misuse,
19+
missing_abi,
20+
non_ascii_idents,
21+
noop_method_call,
22+
pointer_structural_match,
23+
single_use_lifetimes,
24+
trivial_casts,
25+
trivial_numeric_casts,
26+
unreachable_pub,
27+
unsafe_code,
28+
unsafe_op_in_unsafe_fn,
29+
unused_crate_dependencies,
30+
unused_extern_crates,
31+
unused_import_braces,
32+
unused_lifetimes,
33+
unused_macro_rules,
34+
unused_qualifications,
35+
unused_tuple_struct_fields,
36+
variant_size_differences
37+
)]
838
// Clippy Pedantic lints excluding some noisy rules.
939
#![warn(clippy::pedantic)]
1040
#![allow(clippy::similar_names)]

Diff for: src/util/parse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<T: Signed> Iterator for ParseSigned<'_, T> {
108108
}
109109
}
110110

111-
fn try_unsigned<T: Unsigned>(bytes: &mut Bytes) -> Option<T> {
111+
fn try_unsigned<T: Unsigned>(bytes: &mut Bytes<'_>) -> Option<T> {
112112
let mut n = loop {
113113
let byte = bytes.next()?;
114114
let digit = byte.to_decimal();
@@ -130,7 +130,7 @@ fn try_unsigned<T: Unsigned>(bytes: &mut Bytes) -> Option<T> {
130130
}
131131
}
132132

133-
fn try_signed<T: Signed>(bytes: &mut Bytes) -> Option<T> {
133+
fn try_signed<T: Signed>(bytes: &mut Bytes<'_>) -> Option<T> {
134134
let (mut n, negative) = loop {
135135
let byte = bytes.next()?;
136136
let digit = byte.to_decimal();

Diff for: src/year2015/day04.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn parse(input: &str) -> Shared {
5757

5858
// Wait for threads to finish
5959
for handle in handles {
60-
let _ = handle.join();
60+
let _unused = handle.join();
6161
}
6262

6363
shared

Diff for: src/year2020/day02.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Rule<'a> {
2020
}
2121

2222
impl Rule<'_> {
23-
fn from([a, b, c, d]: [&str; 4]) -> Rule {
23+
fn from([a, b, c, d]: [&str; 4]) -> Rule<'_> {
2424
let start = a.unsigned();
2525
let end = b.unsigned();
2626
let letter = c.as_bytes()[0];
@@ -29,7 +29,7 @@ impl Rule<'_> {
2929
}
3030
}
3131

32-
pub fn parse(input: &str) -> Vec<Rule> {
32+
pub fn parse(input: &str) -> Vec<Rule<'_>> {
3333
input
3434
.split(['-', ':', ' ', '\n'])
3535
.filter(|s| !s.is_empty())
@@ -38,7 +38,7 @@ pub fn parse(input: &str) -> Vec<Rule> {
3838
.collect()
3939
}
4040

41-
pub fn part1(input: &[Rule]) -> usize {
41+
pub fn part1(input: &[Rule<'_>]) -> usize {
4242
input
4343
.iter()
4444
.filter(|rule| {
@@ -48,7 +48,7 @@ pub fn part1(input: &[Rule]) -> usize {
4848
.count()
4949
}
5050

51-
pub fn part2(input: &[Rule]) -> usize {
51+
pub fn part2(input: &[Rule<'_>]) -> usize {
5252
input
5353
.iter()
5454
.filter(|rule| {

Diff for: src/year2020/day04.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ use std::ops::RangeInclusive;
99

1010
type Passport<'a> = Vec<[&'a str; 2]>;
1111

12-
pub fn parse(input: &str) -> Vec<Passport> {
12+
pub fn parse(input: &str) -> Vec<Passport<'_>> {
1313
input.split("\n\n").map(parse_block).collect()
1414
}
1515

16-
pub fn part1(input: &[Passport]) -> usize {
16+
pub fn part1(input: &[Passport<'_>]) -> usize {
1717
input.iter().filter(|passport| passport.len() == 7).count()
1818
}
1919

20-
pub fn part2(input: &[Passport]) -> usize {
20+
pub fn part2(input: &[Passport<'_>]) -> usize {
2121
input
2222
.iter()
2323
.filter(|passport| passport.len() == 7)
2424
.filter(|passport| passport.iter().all(validate_field))
2525
.count()
2626
}
2727

28-
fn parse_block(block: &str) -> Passport {
28+
fn parse_block(block: &str) -> Passport<'_> {
2929
let mut fields = Vec::with_capacity(7);
3030

3131
for pair @ [key, _] in block.split([':', ' ', '\n']).chunk::<2>() {

Diff for: src/year2020/day17.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::util::point::*;
1818
/// axis per round (one positive and one negative). Adding padding at the edges to avoid boundary
1919
/// checks gives a maximum width of 8 + 2 * (6 + 1) = 22 for the x and y dimensions and
2020
/// 1 + 2 * (6 + 1) = 15 for the z and w dimensions.
21-
mod size {
21+
pub mod size {
2222
pub const X: i32 = 22;
2323
pub const Y: i32 = 22;
2424
pub const Z: i32 = 15;
@@ -27,7 +27,7 @@ mod size {
2727

2828
/// Pack a four dimensional array into a one dimensional vec to avoid the speed penalty of
2929
/// following multiple pointers and increase memory locality for caching.
30-
mod stride {
30+
pub mod stride {
3131
use super::size;
3232
pub const X: i32 = 1;
3333
pub const Y: i32 = size::X * X;

Diff for: src/year2020/day18.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn parse(input: &str) -> Vec<&str> {
1818
}
1919

2020
pub fn part1(input: &[&str]) -> u64 {
21-
fn helper(bytes: &mut Bytes) -> u64 {
21+
fn helper(bytes: &mut Bytes<'_>) -> u64 {
2222
let mut total = value(bytes, helper);
2323

2424
while let Some(operation) = next(bytes) {
@@ -37,7 +37,7 @@ pub fn part1(input: &[&str]) -> u64 {
3737
}
3838

3939
pub fn part2(input: &[&str]) -> u64 {
40-
fn helper(bytes: &mut Bytes) -> u64 {
40+
fn helper(bytes: &mut Bytes<'_>) -> u64 {
4141
let mut total = value(bytes, helper);
4242

4343
while let Some(operation) = next(bytes) {
@@ -60,7 +60,7 @@ pub fn part2(input: &[&str]) -> u64 {
6060
/// Convenience wrapper around [`Bytes`] iterator. Encountering a `)` is also considered end of
6161
/// sequence. The expressions are consistently formatted so encountering a space just means
6262
/// skip and return the next character that will always be present.
63-
fn next(bytes: &mut Bytes) -> Option<u8> {
63+
fn next(bytes: &mut Bytes<'_>) -> Option<u8> {
6464
match bytes.next() {
6565
None | Some(b')') => None,
6666
Some(b' ') => bytes.next(),
@@ -70,7 +70,7 @@ fn next(bytes: &mut Bytes) -> Option<u8> {
7070

7171
/// Convenience wrapper to return the value of either the next raw digit literal or a
7272
/// sub-expression nested in parentheses.
73-
fn value(bytes: &mut Bytes, helper: impl Fn(&mut Bytes) -> u64) -> u64 {
73+
fn value(bytes: &mut Bytes<'_>, helper: impl Fn(&mut Bytes<'_>) -> u64) -> u64 {
7474
match next(bytes).unwrap() {
7575
b'(' => helper(bytes),
7676
b => b.to_decimal() as u64,

Diff for: src/year2020/day19.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub enum Rule {
6565

6666
type Input<'a> = (Vec<Rule>, Vec<&'a [u8]>);
6767

68-
pub fn parse(input: &str) -> Input {
68+
pub fn parse(input: &str) -> Input<'_> {
6969
let (prefix, suffix) = input.split_once("\n\n").unwrap();
7070
let mut tokens = Vec::new();
7171
let mut rules = vec![Letter(0); 640]; // 640 rules ought to be enough for anybody.
@@ -88,12 +88,12 @@ pub fn parse(input: &str) -> Input {
8888
(rules, messages)
8989
}
9090

91-
pub fn part1(input: &Input) -> usize {
91+
pub fn part1(input: &Input<'_>) -> usize {
9292
let (rules, messages) = input;
9393
messages.iter().filter(|message| check(rules, 0, message, 0) == Some(message.len())).count()
9494
}
9595

96-
pub fn part2(input: &Input) -> usize {
96+
pub fn part2(input: &Input<'_>) -> usize {
9797
let (rules, messages) = input;
9898
let predicate = |message: &&&[u8]| {
9999
let mut index = 0;

Diff for: src/year2020/day21.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Ingredient {
5757
candidates: usize,
5858
}
5959

60-
pub fn parse(input: &str) -> Input {
60+
pub fn parse(input: &str) -> Input<'_> {
6161
let mut ingredients: FastMap<&str, Ingredient> = FastMap::new();
6262
let mut allergens = FastMap::new();
6363
let mut allergens_per_food = Vec::new();
@@ -97,11 +97,11 @@ pub fn parse(input: &str) -> Input {
9797
Input { ingredients, allergens }
9898
}
9999

100-
pub fn part1(input: &Input) -> u32 {
100+
pub fn part1(input: &Input<'_>) -> u32 {
101101
input.ingredients.values().filter(|i| i.candidates == 0).map(|i| i.food.count_ones()).sum()
102102
}
103103

104-
pub fn part2(input: &Input) -> String {
104+
pub fn part2(input: &Input<'_>) -> String {
105105
let mut ingredients = input.ingredients.clone();
106106
ingredients.retain(|_, v| v.candidates != 0);
107107

Diff for: src/year2021/day03.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ pub struct Input<'a> {
1212
numbers: Vec<&'a [u8]>,
1313
}
1414

15-
pub fn parse(input: &str) -> Input {
15+
pub fn parse(input: &str) -> Input<'_> {
1616
let numbers: Vec<_> = input.lines().map(str::as_bytes).collect();
1717
Input { width: numbers[0].len(), numbers }
1818
}
1919

20-
pub fn part1(input: &Input) -> u32 {
20+
pub fn part1(input: &Input<'_>) -> u32 {
2121
let mut gamma = 0;
2222
let mut epsilon = 0;
2323

@@ -35,7 +35,7 @@ pub fn part1(input: &Input) -> u32 {
3535
gamma * epsilon
3636
}
3737

38-
pub fn part2(input: &Input) -> u32 {
38+
pub fn part2(input: &Input<'_>) -> u32 {
3939
let gamma = rating(input, |a, b| a >= b);
4040
let epsilon = rating(input, |a, b| a < b);
4141
gamma * epsilon
@@ -50,7 +50,7 @@ fn fold(numbers: &[u8], width: usize) -> u32 {
5050
numbers.iter().take(width).fold(0, |acc, &n| (acc << 1) | (n & 1) as u32)
5151
}
5252

53-
fn rating(input: &Input, cmp: impl Fn(usize, usize) -> bool) -> u32 {
53+
fn rating(input: &Input<'_>, cmp: impl Fn(usize, usize) -> bool) -> u32 {
5454
let mut numbers = input.numbers.clone();
5555

5656
for i in 0..input.width {

Diff for: src/year2021/day16.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct BitStream<'a> {
2222
}
2323

2424
impl BitStream<'_> {
25-
fn from(s: &str) -> BitStream {
25+
fn from(s: &str) -> BitStream<'_> {
2626
BitStream { available: 0, bits: 0, read: 0, iter: s.bytes() }
2727
}
2828

@@ -56,7 +56,7 @@ pub enum Packet {
5656
}
5757

5858
impl Packet {
59-
fn from(bit_stream: &mut BitStream) -> Packet {
59+
fn from(bit_stream: &mut BitStream<'_>) -> Packet {
6060
let version = bit_stream.next(3);
6161
let type_id = bit_stream.next(3);
6262

Diff for: src/year2022/day13.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Packet<'a> {
2525
}
2626

2727
impl Packet<'_> {
28-
fn new(str: &str) -> Packet {
28+
fn new(str: &str) -> Packet<'_> {
2929
Packet { slice: str.as_bytes(), index: 0, extra: Vec::new() }
3030
}
3131
}

Diff for: src/year2022/day16.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Valve<'a> {
2525
}
2626

2727
impl Valve<'_> {
28-
fn parse(line: &str) -> Valve {
28+
fn parse(line: &str) -> Valve<'_> {
2929
let mut tokens: Vec<_> = line
3030
.split(|c: char| !c.is_ascii_uppercase() && !c.is_ascii_digit())
3131
.filter(|s| !s.is_empty())
@@ -36,7 +36,7 @@ impl Valve<'_> {
3636
Valve { name, flow, edges: tokens }
3737
}
3838

39-
fn cmp(&self, other: &Valve) -> Ordering {
39+
fn cmp(&self, other: &Valve<'_>) -> Ordering {
4040
let first = other.flow.cmp(&self.flow);
4141
if first == Ordering::Equal {
4242
self.name.cmp(other.name)

Diff for: src/year2022/day17.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct State<'a> {
2727
}
2828

2929
impl State<'_> {
30-
fn new(input: &[u8]) -> State {
30+
fn new(input: &[u8]) -> State<'_> {
3131
let mut state = State {
3232
rocks: ROCKS.iter().copied().cycle(),
3333
jets: input.iter().copied().cycle(),
@@ -39,7 +39,7 @@ impl State<'_> {
3939
}
4040
}
4141

42-
impl<'a> Iterator for State<'a> {
42+
impl Iterator for State<'_> {
4343
type Item = usize;
4444

4545
fn next(&mut self) -> Option<Self::Item> {

0 commit comments

Comments
 (0)