Skip to content

Commit

Permalink
Make clippy::pedantic happy
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Sep 23, 2023
1 parent 2f106a3 commit 4e3b85a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
9 changes: 8 additions & 1 deletion aoc-build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#![deny(clippy::pedantic)]
#![allow(
clippy::case_sensitive_file_extension_comparisons,
clippy::missing_errors_doc,
clippy::missing_panics_doc
)]

use regex::Regex;
use std::fs::{self, File};
use std::io::{BufRead, BufReader};
Expand Down Expand Up @@ -31,7 +38,7 @@ pub fn build() -> eyre::Result<()> {
let part = m[2].parse::<usize>()?;
let version = m[3]
.split(',')
.map(|s| s.trim())
.map(str::trim)
.find(|s| version_re.is_match(s));
let (version, extension): (syn::Expr, &str) = match version {
Some(v) => (parse_quote!(Some(String::from(#v))), v),
Expand Down
4 changes: 3 additions & 1 deletion aoc-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::pedantic)]

use proc_macro::TokenStream;
use proc_macro_error::{abort, proc_macro_error};
use quote::{quote, ToTokens};
Expand Down Expand Up @@ -161,7 +163,7 @@ pub fn aoc(attr: TokenStream, input: TokenStream) -> TokenStream {
)
}
ReturnType::Type(_, ref t) => (quote!(Ok(#func_name #inputs)), quote!(::eyre::Result<#t>)),
_ => abort!(func.sig, "AOC part cannot return ()"),
ReturnType::Default => abort!(func.sig, "AOC part cannot return ()"),
};
quote! {
#func
Expand Down
2 changes: 1 addition & 1 deletion aoc/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn input_bytes(day: usize) -> Result<Vec<u8>, Error> {
s.push(b'\n');
s
})),
None => Ok(std::fs::read(format!("input/day{}.txt", day))?),
None => Ok(std::fs::read(format!("input/day{day}.txt"))?),
}
}

Expand Down
2 changes: 2 additions & 0 deletions aoc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::pedantic)]

pub use aoc_derive::*;

pub mod error;
Expand Down
12 changes: 5 additions & 7 deletions aoc/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,27 @@ where
let current_day = opts.day.unwrap_or(chrono::Utc::now().day() as usize);
register();
let mut runners = super::runners::RUNNERS.lock().unwrap();
let keys = runners.keys().cloned().collect::<Vec<_>>();
let keys = runners.keys().copied().collect::<Vec<_>>();
for (day, part) in keys {
if day == current_day || opts.all {
for (version, runner) in runners.remove(&(day, part)).unwrap() {
let before = chrono::Utc::now();
let result = runner();
let after = chrono::Utc::now();
let version = version
.clone()
.map(|v| format!(" — {}", v))
.unwrap_or_else(String::new);
.clone().map_or_else(String::new, |v| format!(" — {}", v));
let elapsed = if opts.timing {
format!(" ({})", pretty_duration(after - before))
} else {
String::new()
};
let header = format!("Day {} - part {}{}: ", day, part, version);
let header = format!("Day {day} - part {part}{version}: ");
let sep = format!("\n{}", " ".repeat(header.len()));
let result = match result {
Ok(e) => e.lines().join(&sep),
Err(e) => format!("<error: {:?}>", e),
Err(e) => format!("<error: {e:?}>"),
};
println!("{}{}{}", header, result, elapsed);
println!("{header}{result}{elapsed}");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions aoc/tests/aoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ fn d3p1s(input: &str) -> String {
#[aoc(day3, part1, vec_str)]
fn d3p1svec(mut input: Vec<&str>) -> String {
input.sort_unstable();
format!("{:?}", input)
format!("{input:?}")
}

#[aoc(day3, part1, ref_str)]
fn d3p1sref(input: &[&str]) -> String {
format!("{:?}", input)
format!("{input:?}")
}

#[aoc(day3, part1, mut_str)]
fn d3p1smut(input: &mut [&str]) -> String {
input.sort_unstable();
format!("{:?}", input)
format!("{input:?}")
}

#[aoc(day3, part1, bytes)]
Expand Down

0 comments on commit 4e3b85a

Please sign in to comment.