clippy lints and stabilizations

A few things have changed in the past few months
This commit is contained in:
kageru 2021-04-29 19:14:28 +02:00
parent 506eff857e
commit 3d80b9f073
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
13 changed files with 26 additions and 19 deletions

View File

@ -1,5 +1,6 @@
#![feature(iter_map_while)] #![feature(iter_map_while)]
#![feature(test)] #![feature(test)]
#![allow(clippy::ptr_arg)]
extern crate test; extern crate test;
use aoc2020::common::*; use aoc2020::common::*;
use itertools::Itertools; use itertools::Itertools;

View File

@ -1,4 +1,5 @@
#![feature(test, str_split_once)] #![feature(test)]
#![allow(clippy::ptr_arg, clippy::upper_case_acronyms)]
extern crate test; extern crate test;
use aoc2020::common::*; use aoc2020::common::*;

View File

@ -40,7 +40,7 @@ fn sum_up_to(input: &[usize], n: usize) -> Option<usize> {
return None; return None;
} }
} }
return None; None
} }
fn main() { fn main() {

View File

@ -1,4 +1,5 @@
#![feature(test)] #![feature(test)]
#![allow(clippy::ptr_arg)]
extern crate test; extern crate test;
use aoc2020::common::*; use aoc2020::common::*;

View File

@ -1,4 +1,5 @@
#![feature(test)] #![feature(test)]
#![allow(clippy::ptr_arg)]
extern crate test; extern crate test;
use aoc2020::{common::*, grid::*}; use aoc2020::{common::*, grid::*};

View File

@ -18,7 +18,7 @@ fn chinese_remainder(divs: Vec<i64>, rems: Vec<i64>) -> i64 {
if x1 < 0 { if x1 < 0 {
x1 += b0; x1 += b0;
} }
return x1; x1
} }
let mut sum = 0; let mut sum = 0;
let prod: i64 = divs.iter().product(); let prod: i64 = divs.iter().product();
@ -26,7 +26,7 @@ fn chinese_remainder(divs: Vec<i64>, rems: Vec<i64>) -> i64 {
let p = prod / div; let p = prod / div;
sum += rem * mul_inv(p, *div) * p; sum += rem * mul_inv(p, *div) * p;
} }
return sum % prod; sum % prod
} }
type Parsed = (i64, Vec<Option<i64>>); type Parsed = (i64, Vec<Option<i64>>);

View File

@ -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; extern crate test;
use std::collections::HashMap; use std::collections::HashMap;
@ -22,7 +23,7 @@ fn read_input() -> String {
read_file(14) read_file(14)
} }
fn parse_input<'a>(raw: &'a str) -> Parsed<'a> { fn parse_input(raw: &'_ str) -> Parsed<'_> {
raw.lines() raw.lines()
.map(|l| { .map(|l| {
if let Some(l) = l.strip_prefix("mask = ") { 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')) (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 ones, mut zeros) = (0, 0);
let mut mem = HashMap::new(); let mut mem = HashMap::new();
for command in parsed { for command in parsed {
@ -72,7 +73,7 @@ fn part1<'a>(parsed: &Parsed<'a>) -> usize {
mem.values().sum() mem.values().sum()
} }
fn states_to_number(bits: &Vec<BitState>) -> usize { fn states_to_number(bits: &[BitState]) -> usize {
bits.iter() bits.iter()
.rev() .rev()
.enumerate() .enumerate()
@ -95,7 +96,7 @@ fn get_variations(input: Vec<BitState>) -> Vec<usize> {
} }
} }
fn part2<'a>(parsed: &Parsed<'a>) -> usize { fn part2(parsed: &Parsed<'_>) -> usize {
let mut mask = vec![]; let mut mask = vec![];
parsed parsed
.iter() .iter()

View File

@ -1,4 +1,5 @@
#![feature(test)] #![feature(test)]
#![allow(clippy::ptr_arg)]
extern crate test; extern crate test;
use std::collections::HashMap; use std::collections::HashMap;
use aoc2020::common::*; use aoc2020::common::*;

View File

@ -1,4 +1,4 @@
#![feature(test, str_split_once)] #![feature(test)]
extern crate test; extern crate test;
use aoc2020::common::*; use aoc2020::common::*;
use itertools::Itertools; use itertools::Itertools;
@ -79,7 +79,7 @@ fn part2(parsed: &Parsed, key: &str) -> usize {
let mut rules = vec![None; len]; let mut rules = vec![None; len];
for i in (0..len).cycle() { for i in (0..len).cycle() {
let at_index = only_valid.iter().map(|v| v[i]).collect_vec(); let at_index = only_valid.iter().map(|v| v[i]).collect_vec();
if let Some(_) = rules[i] { if rules[i].is_some() {
continue; continue;
} }
if let Some(rule) = remaining_rules if let Some(rule) = remaining_rules

View File

@ -1,4 +1,5 @@
#![feature(test)] #![feature(test)]
#![allow(clippy::ptr_arg)]
extern crate test; extern crate test;
use aoc2020::common::*; use aoc2020::common::*;
use itertools::Itertools; use itertools::Itertools;

View File

@ -1,4 +1,4 @@
#![feature(test, str_split_once, bool_to_option)] #![feature(test, bool_to_option)]
extern crate test; extern crate test;
use aoc2020::common::*; use aoc2020::common::*;
use itertools::Itertools; use itertools::Itertools;
@ -34,7 +34,7 @@ impl RuleSet {
} }
fn matches(&self, s: &str, rule: Rule) -> Vec<usize> { fn matches(&self, s: &str, rule: Rule) -> Vec<usize> {
if s.len() == 0 { if s.is_empty() {
return vec![]; return vec![];
} }
match rule { match rule {
@ -60,7 +60,7 @@ fn read_input() -> String {
read_file(19) 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, inputs) = raw.split_once("\n\n").unwrap();
let rules = RuleSet( let rules = RuleSet(
rules 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]))) .or_else(|| split.next_tuple().map(|(a, b)| Rule::Any(vec![a, b])))
.unwrap() .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()), and if and.contains(' ') => Rule::And(and.split(' ').map(|s| s.parse().unwrap()).collect()),
useless => Rule::Useless(useless.parse().unwrap()), useless => Rule::Useless(useless.parse().unwrap()),
}) })

View File

@ -14,11 +14,11 @@ pub struct Grid<P: Position, T: Display + Default> {
impl<P: Position, T: Display + Default + Copy> Grid<P, T> { impl<P: Position, T: Display + Default + Copy> Grid<P, T> {
pub fn get_convert<Pos: Into<P>>(&self, pos: Pos) -> T { pub fn get_convert<Pos: Into<P>>(&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 { 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<Pos: Into<P>>(&mut self, pos: Pos, t: T) { pub fn insert<Pos: Into<P>>(&mut self, pos: Pos, t: T) {
@ -35,7 +35,7 @@ impl<P: Position, T: Display + Default> std::iter::FromIterator<(P, T)> for Grid
} }
impl<T: Display + Default + Copy> Grid<Position2D, T> { impl<T: Display + Default + Copy> Grid<Position2D, T> {
fn draw_ascii(&self) -> String { pub fn draw_ascii(&self) -> String {
draw_ascii(&self.fields) draw_ascii(&self.fields)
} }
} }

View File

@ -187,7 +187,7 @@ mod p4d {
// associated Error type. // associated Error type.
fn unwrap_number_result<I: TryInto<i64>>(i: I) -> i64 { fn unwrap_number_result<I: TryInto<i64>>(i: I) -> i64 {
match i.try_into() { match i.try_into() {
Ok(i) => return i, Ok(i) => i,
_ => panic!("Bad coordinate"), _ => panic!("Bad coordinate"),
} }
} }