From 3d80b9f0737e6e522dc2273ddec7c9634978883c Mon Sep 17 00:00:00 2001 From: kageru Date: Thu, 29 Apr 2021 19:14:28 +0200 Subject: [PATCH] clippy lints and stabilizations A few things have changed in the past few months --- 2020/src/bin/day03.rs | 1 + 2020/src/bin/day08.rs | 3 ++- 2020/src/bin/day09.rs | 2 +- 2020/src/bin/day10.rs | 1 + 2020/src/bin/day12.rs | 1 + 2020/src/bin/day13.rs | 4 ++-- 2020/src/bin/day14.rs | 11 ++++++----- 2020/src/bin/day15.rs | 1 + 2020/src/bin/day16.rs | 4 ++-- 2020/src/bin/day18.rs | 1 + 2020/src/bin/day19.rs | 8 ++++---- 2020/src/grid.rs | 6 +++--- 2020/src/grid/position.rs | 2 +- 13 files changed, 26 insertions(+), 19 deletions(-) diff --git a/2020/src/bin/day03.rs b/2020/src/bin/day03.rs index 3a474d6..cb0ad70 100644 --- a/2020/src/bin/day03.rs +++ b/2020/src/bin/day03.rs @@ -1,5 +1,6 @@ #![feature(iter_map_while)] #![feature(test)] +#![allow(clippy::ptr_arg)] extern crate test; use aoc2020::common::*; use itertools::Itertools; diff --git a/2020/src/bin/day08.rs b/2020/src/bin/day08.rs index 072991f..2a5bae9 100644 --- a/2020/src/bin/day08.rs +++ b/2020/src/bin/day08.rs @@ -1,4 +1,5 @@ -#![feature(test, str_split_once)] +#![feature(test)] +#![allow(clippy::ptr_arg, clippy::upper_case_acronyms)] extern crate test; use aoc2020::common::*; diff --git a/2020/src/bin/day09.rs b/2020/src/bin/day09.rs index df41014..049103c 100644 --- a/2020/src/bin/day09.rs +++ b/2020/src/bin/day09.rs @@ -40,7 +40,7 @@ fn sum_up_to(input: &[usize], n: usize) -> Option { return None; } } - return None; + None } fn main() { diff --git a/2020/src/bin/day10.rs b/2020/src/bin/day10.rs index ffd017b..2eff161 100644 --- a/2020/src/bin/day10.rs +++ b/2020/src/bin/day10.rs @@ -1,4 +1,5 @@ #![feature(test)] +#![allow(clippy::ptr_arg)] extern crate test; use aoc2020::common::*; diff --git a/2020/src/bin/day12.rs b/2020/src/bin/day12.rs index c43f1dd..01c052b 100644 --- a/2020/src/bin/day12.rs +++ b/2020/src/bin/day12.rs @@ -1,4 +1,5 @@ #![feature(test)] +#![allow(clippy::ptr_arg)] extern crate test; use aoc2020::{common::*, grid::*}; diff --git a/2020/src/bin/day13.rs b/2020/src/bin/day13.rs index 63b4a0a..4e69d50 100644 --- a/2020/src/bin/day13.rs +++ b/2020/src/bin/day13.rs @@ -18,7 +18,7 @@ fn chinese_remainder(divs: Vec, rems: Vec) -> i64 { if x1 < 0 { x1 += b0; } - return x1; + x1 } let mut sum = 0; let prod: i64 = divs.iter().product(); @@ -26,7 +26,7 @@ fn chinese_remainder(divs: Vec, rems: Vec) -> i64 { let p = prod / div; sum += rem * mul_inv(p, *div) * p; } - return sum % prod; + sum % prod } type Parsed = (i64, Vec>); diff --git a/2020/src/bin/day14.rs b/2020/src/bin/day14.rs index f7f0d81..6987910 100644 --- a/2020/src/bin/day14.rs +++ b/2020/src/bin/day14.rs @@ -1,4 +1,5 @@ -#![feature(test, str_split_once, destructuring_assignment, bool_to_option)] +#![feature(test, destructuring_assignment, bool_to_option)] +#![allow(clippy::ptr_arg)] extern crate test; use std::collections::HashMap; @@ -22,7 +23,7 @@ fn read_input() -> String { read_file(14) } -fn parse_input<'a>(raw: &'a str) -> Parsed<'a> { +fn parse_input(raw: &'_ str) -> Parsed<'_> { raw.lines() .map(|l| { if let Some(l) = l.strip_prefix("mask = ") { @@ -58,7 +59,7 @@ fn calc_bitmasks_p1(b: &str) -> (usize, usize) { (calc_bitmask(b, |(_, b)| *b == b'1'), calc_bitmask(b, |(_, b)| *b != b'0')) } -fn part1<'a>(parsed: &Parsed<'a>) -> usize { +fn part1(parsed: &Parsed<'_>) -> usize { let (mut ones, mut zeros) = (0, 0); let mut mem = HashMap::new(); for command in parsed { @@ -72,7 +73,7 @@ fn part1<'a>(parsed: &Parsed<'a>) -> usize { mem.values().sum() } -fn states_to_number(bits: &Vec) -> usize { +fn states_to_number(bits: &[BitState]) -> usize { bits.iter() .rev() .enumerate() @@ -95,7 +96,7 @@ fn get_variations(input: Vec) -> Vec { } } -fn part2<'a>(parsed: &Parsed<'a>) -> usize { +fn part2(parsed: &Parsed<'_>) -> usize { let mut mask = vec![]; parsed .iter() diff --git a/2020/src/bin/day15.rs b/2020/src/bin/day15.rs index d9a15c6..df8e980 100644 --- a/2020/src/bin/day15.rs +++ b/2020/src/bin/day15.rs @@ -1,4 +1,5 @@ #![feature(test)] +#![allow(clippy::ptr_arg)] extern crate test; use std::collections::HashMap; use aoc2020::common::*; diff --git a/2020/src/bin/day16.rs b/2020/src/bin/day16.rs index d081609..7e858de 100644 --- a/2020/src/bin/day16.rs +++ b/2020/src/bin/day16.rs @@ -1,4 +1,4 @@ -#![feature(test, str_split_once)] +#![feature(test)] extern crate test; use aoc2020::common::*; use itertools::Itertools; @@ -79,7 +79,7 @@ fn part2(parsed: &Parsed, key: &str) -> usize { let mut rules = vec![None; len]; for i in (0..len).cycle() { let at_index = only_valid.iter().map(|v| v[i]).collect_vec(); - if let Some(_) = rules[i] { + if rules[i].is_some() { continue; } if let Some(rule) = remaining_rules diff --git a/2020/src/bin/day18.rs b/2020/src/bin/day18.rs index 89526f8..eec46c2 100644 --- a/2020/src/bin/day18.rs +++ b/2020/src/bin/day18.rs @@ -1,4 +1,5 @@ #![feature(test)] +#![allow(clippy::ptr_arg)] extern crate test; use aoc2020::common::*; use itertools::Itertools; diff --git a/2020/src/bin/day19.rs b/2020/src/bin/day19.rs index 14c613c..30e6061 100644 --- a/2020/src/bin/day19.rs +++ b/2020/src/bin/day19.rs @@ -1,4 +1,4 @@ -#![feature(test, str_split_once, bool_to_option)] +#![feature(test, bool_to_option)] extern crate test; use aoc2020::common::*; use itertools::Itertools; @@ -34,7 +34,7 @@ impl RuleSet { } fn matches(&self, s: &str, rule: Rule) -> Vec { - if s.len() == 0 { + if s.is_empty() { return vec![]; } match rule { @@ -60,7 +60,7 @@ fn read_input() -> String { read_file(19) } -fn parse_input<'a>(raw: &'a str) -> Parsed<'a> { +fn parse_input(raw: &'_ str) -> Parsed<'_> { let (rules, inputs) = raw.split_once("\n\n").unwrap(); let rules = RuleSet( rules @@ -78,7 +78,7 @@ fn parse_input<'a>(raw: &'a str) -> Parsed<'a> { .or_else(|| split.next_tuple().map(|(a, b)| Rule::Any(vec![a, b]))) .unwrap() } - chr if chr.contains('"') => Rule::Char(chr.bytes().skip_while(|&b| b != b'"').skip(1).next().unwrap()), + chr if chr.contains('"') => Rule::Char(chr.bytes().skip_while(|&b| b != b'"').nth(1).unwrap()), and if and.contains(' ') => Rule::And(and.split(' ').map(|s| s.parse().unwrap()).collect()), useless => Rule::Useless(useless.parse().unwrap()), }) diff --git a/2020/src/grid.rs b/2020/src/grid.rs index a287722..e203726 100644 --- a/2020/src/grid.rs +++ b/2020/src/grid.rs @@ -14,11 +14,11 @@ pub struct Grid { impl Grid { pub fn get_convert>(&self, pos: Pos) -> T { - self.fields.get(&pos.into()).copied().unwrap_or_else(|| T::default()) + self.fields.get(&pos.into()).copied().unwrap_or_default() } pub fn get(&self, pos: &P) -> T { - self.fields.get(pos).copied().unwrap_or_else(|| T::default()) + self.fields.get(pos).copied().unwrap_or_default() } pub fn insert>(&mut self, pos: Pos, t: T) { @@ -35,7 +35,7 @@ impl std::iter::FromIterator<(P, T)> for Grid } impl Grid { - fn draw_ascii(&self) -> String { + pub fn draw_ascii(&self) -> String { draw_ascii(&self.fields) } } diff --git a/2020/src/grid/position.rs b/2020/src/grid/position.rs index 074d308..4f02707 100644 --- a/2020/src/grid/position.rs +++ b/2020/src/grid/position.rs @@ -187,7 +187,7 @@ mod p4d { // associated Error type. fn unwrap_number_result>(i: I) -> i64 { match i.try_into() { - Ok(i) => return i, + Ok(i) => i, _ => panic!("Bad coordinate"), } }