Addressed many cargo clippy complaints

This commit is contained in:
Magnus Hovland Hoff 2022-04-03 22:03:03 +02:00
parent 95a73b9471
commit bf34e2923b
13 changed files with 66 additions and 135 deletions

82
Cargo.lock generated
View file

@ -262,7 +262,7 @@ version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
dependencies = [
"proc-macro2 1.0.26",
"proc-macro2",
"quote 1.0.9",
"syn 1.0.71",
]
@ -428,24 +428,10 @@ dependencies = [
[[package]]
name = "indoc"
version = "0.2.8"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "098a82c5223d3162a32d79f84e43d718c32f050d07b796285684ee43059bc8c4"
checksum = "e7906a9fababaeacb774f72410e497a1d18de916322e33797bb2cd29baa23c9e"
dependencies = [
"indoc-impl",
"proc-macro-hack",
]
[[package]]
name = "indoc-impl"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cf2a15c870db1b07595cc9adaece19fac97d59a16665e79cd728b391a6b711"
dependencies = [
"proc-macro-hack",
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
"unindent",
]
@ -632,7 +618,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c"
dependencies = [
"migrations_internals",
"proc-macro2 1.0.26",
"proc-macro2",
"quote 1.0.9",
"syn 1.0.71",
]
@ -822,30 +808,6 @@ version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]]
name = "proc-macro-hack"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7f95648580798cc44ff8efb9bb0d7ee5205ea32e087b31b0732f3e8c2648ee2"
dependencies = [
"proc-macro-hack-impl",
]
[[package]]
name = "proc-macro-hack-impl"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7be55bf0ae1635f4d7c7ddd6efc05c631e98a82104a73d35550bbc52db960027"
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.26"
@ -869,22 +831,13 @@ version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2 1.0.26",
"proc-macro2",
]
[[package]]
@ -1148,7 +1101,7 @@ version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d"
dependencies = [
"proc-macro2 1.0.26",
"proc-macro2",
"quote 1.0.9",
"syn 1.0.71",
]
@ -1267,24 +1220,13 @@ dependencies = [
"unicode-xid 0.0.4",
]
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
]
[[package]]
name = "syn"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad184cc9470f9117b2ac6817bfe297307418819ba40552f9b3846f05c33d5373"
dependencies = [
"proc-macro2 1.0.26",
"proc-macro2",
"quote 1.0.9",
"unicode-xid 0.2.2",
]
@ -1643,12 +1585,6 @@ version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.2"
@ -1657,9 +1593,9 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "unindent"
version = "0.1.7"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
checksum = "514672a55d7380da379785a4d70ca8386c8883ff7eaae877be4d2081cebe73d8"
[[package]]
name = "url"

View file

@ -79,7 +79,7 @@ default-features = false
git = "https://github.com/maghoff/pulldown-cmark.git"
[dev-dependencies]
indoc = "0.2"
indoc = "1.0.4"
matches = "0.1"
[features]

View file

@ -19,7 +19,7 @@ impl LicenseId {
fn include_notice(&self) -> bool {
use self::LicenseId::*;
match self {
&Mpl2 => false,
Mpl2 => false,
_ => true,
}
}
@ -29,10 +29,10 @@ impl quote::ToTokens for LicenseId {
fn to_tokens(&self, tokens: &mut quote::Tokens) {
use self::LicenseId::*;
tokens.append(match self {
&Bsd3Clause => "Bsd3Clause",
&Mit => "Mit",
&Mpl2 => "Mpl2",
&Ofl11 => "Ofl11",
Bsd3Clause => "Bsd3Clause",
Mit => "Mit",
Mpl2 => "Mpl2",
Ofl11 => "Ofl11",
});
}
}
@ -60,9 +60,9 @@ impl quote::ToTokens for LicenseReport {
&c.chosen_license,
);
let link = match link {
&Some(ref link) => quote! { Some(#link) },
&None => quote! { None },
let link = match *link {
Some(ref link) => quote! { Some(#link) },
None => quote! { None },
};
let copyright = match license.include_notice() {

View file

@ -10,12 +10,12 @@ fn user_crate_root() -> PathBuf {
std::env::current_dir().expect("Unable to get current directory")
}
fn find_attr<'a>(attrs: &'a Vec<syn::Attribute>, name: &str) -> Option<&'a str> {
fn find_attr<'a>(attrs: &'a [syn::Attribute], name: &str) -> Option<&'a str> {
attrs
.iter()
.find(|&x| x.name() == name)
.and_then(|ref attr| match &attr.value {
&syn::MetaItem::NameValue(_, syn::Lit::Str(ref template, _)) => Some(template),
.and_then(|attr| match attr.value {
syn::MetaItem::NameValue(_, syn::Lit::Str(ref template, _)) => Some(template),
_ => None,
})
.map(|x| x.as_ref())

View file

@ -12,7 +12,7 @@ compile_error!("dynamic-assets must not be used for production");
lazy_static! {
pub static ref VERSION: String = || -> String {
let mut components = Vec::<String>::new();
let mut components = vec![];
#[cfg(debug_assertions)]
components.push("debug".into());

View file

@ -1,3 +1,5 @@
#![allow(clippy::into_iter_on_ref)]
#![allow(clippy::vec_init_then_push)]
#![recursion_limit = "128"]
// for diesel's infer_schema!
@ -9,15 +11,12 @@
#[cfg(test)]
#[macro_use]
extern crate matches;
#[cfg(test)]
#[macro_use]
extern crate indoc;
#[macro_use]
extern crate bart_derive;
#[macro_use]
extern crate codegen;
#[macro_use]
#[allow(clippy::useless_attribute)]
#[allow(deprecated)]
extern crate diesel_infer_schema;
#[macro_use]

View file

@ -17,11 +17,11 @@ pub enum MergeResult<Item: Debug + PartialEq> {
}
impl<'a> MergeResult<&'a str> {
pub fn to_strings(self) -> MergeResult<String> {
pub fn into_strings(self) -> MergeResult<String> {
match self {
MergeResult::Clean(x) => MergeResult::Clean(x),
MergeResult::Conflicted(x) => {
MergeResult::Conflicted(x.into_iter().map(Output::to_strings).collect())
MergeResult::Conflicted(x.into_iter().map(Output::into_strings).collect())
}
}
}
@ -80,10 +80,7 @@ pub fn merge_lines<'a>(a: &'a str, o: &'a str, b: &'a str) -> MergeResult<&'a st
let chunks = ChunkIterator::new(&oa, &ob);
let hunks: Vec<_> = chunks.map(resolve).collect();
let clean = hunks.iter().all(|x| match x {
&Resolved(..) => true,
_ => false,
});
let clean = hunks.iter().all(|x| matches!(x, Resolved(..)));
if clean {
MergeResult::Clean(
@ -108,10 +105,7 @@ pub fn merge_chars<'a>(a: &'a str, o: &'a str, b: &'a str) -> MergeResult<char>
let chunks = ChunkIterator::new(&oa, &ob);
let hunks: Vec<_> = chunks.map(resolve).collect();
let clean = hunks.iter().all(|x| match x {
&Resolved(..) => true,
_ => false,
});
let clean = hunks.iter().all(|x| matches!(x, Resolved(..)));
if clean {
MergeResult::Clean(
@ -130,6 +124,7 @@ pub fn merge_chars<'a>(a: &'a str, o: &'a str, b: &'a str) -> MergeResult<char>
#[cfg(test)]
mod test {
use indoc::indoc;
use super::output::Output::*;
use super::output::*;

View file

@ -11,7 +11,7 @@ pub enum Output<Item: Debug + PartialEq> {
}
impl<'a> Output<&'a str> {
pub fn to_strings(self) -> Output<String> {
pub fn into_strings(self) -> Output<String> {
match self {
Output::Resolved(x) => Output::Resolved(x.into_iter().map(str::to_string).collect()),
Output::Conflict(a, o, b) => Output::Conflict(
@ -26,10 +26,10 @@ impl<'a> Output<&'a str> {
fn choose_left<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
operations
.iter()
.filter_map(|x| match x {
&Both(y, _) => Some(y),
&Left(y) => Some(y),
&Right(_) => None,
.filter_map(|x| match *x {
Both(y, _) => Some(y),
Left(y) => Some(y),
Right(_) => None,
})
.collect()
}
@ -37,19 +37,16 @@ fn choose_left<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
fn choose_right<Item: Copy>(operations: &[diff::Result<Item>]) -> Vec<Item> {
operations
.iter()
.filter_map(|x| match x {
&Both(_, y) => Some(y),
&Left(_) => None,
&Right(y) => Some(y),
.filter_map(|x| match *x {
Both(_, y) => Some(y),
Left(_) => None,
Right(y) => Some(y),
})
.collect()
}
fn no_change<Item>(operations: &[diff::Result<Item>]) -> bool {
operations.iter().all(|x| match x {
&Both(..) => true,
_ => false,
})
operations.iter().all(|x| matches!(x, Both(..)))
}
pub fn resolve<'a, Item: 'a + Debug + PartialEq + Copy>(chunk: Chunk<'a, Item>) -> Output<Item> {

View file

@ -28,20 +28,20 @@ impl License {
fn link(&self) -> &'static str {
use self::License::*;
match self {
&Bsd3Clause => "bsd-3-clause",
&Mit => "mit",
&Mpl2 => "mpl2",
&Ofl11 => "sil-ofl-1.1",
Bsd3Clause => "bsd-3-clause",
Mit => "mit",
Mpl2 => "mpl2",
Ofl11 => "sil-ofl-1.1",
}
}
fn name(&self) -> &'static str {
use self::License::*;
match self {
&Bsd3Clause => "BSD-3-Clause",
&Mit => "MIT",
&Mpl2 => "MPL2",
&Ofl11 => "OFL-1.1",
Bsd3Clause => "BSD-3-Clause",
Mit => "MIT",
Mpl2 => "MPL2",
Ofl11 => "OFL-1.1",
}
}
}

View file

@ -81,12 +81,12 @@ impl QueryParameters {
}
}
fn apply_query_config<'a>(
mut query: article_revisions::BoxedQuery<'a, diesel::sqlite::Sqlite>,
fn apply_query_config(
mut query: article_revisions::BoxedQuery<diesel::sqlite::Sqlite>,
article_id: Option<i32>,
author: Option<String>,
limit: i32,
) -> article_revisions::BoxedQuery<'a, diesel::sqlite::Sqlite> {
) -> article_revisions::BoxedQuery<diesel::sqlite::Sqlite> {
use diesel::prelude::*;
if let Some(article_id) = article_id {

View file

@ -152,9 +152,9 @@ impl Resource for SearchResource {
}
fn head(&self) -> ResponseFuture {
let content_type = match &self.response_type {
&ResponseType::Json => ContentType(APPLICATION_JSON.clone()),
&ResponseType::Html => ContentType(TEXT_HTML.clone()),
let content_type = match self.response_type {
ResponseType::Json => ContentType(APPLICATION_JSON.clone()),
ResponseType::Html => ContentType(TEXT_HTML.clone()),
};
Box::new(futures::finished(
@ -183,7 +183,11 @@ impl Resource for SearchResource {
}
// TODO: Show a search "front page" when no query is given:
let query = self.query.as_ref().cloned().unwrap_or("".to_owned());
let query = self
.query
.as_ref()
.cloned()
.unwrap_or_else(|| "".to_owned());
let data = self.state.search_query(
query,
@ -215,8 +219,8 @@ impl Resource for SearchResource {
None
};
match &self.response_type {
&ResponseType::Json => Ok(head.with_body(
match self.response_type {
ResponseType::Json => Ok(head.with_body(
serde_json::to_string(&JsonResponse {
query: self.query.as_deref().unwrap_or(""),
hits: &data,
@ -225,7 +229,7 @@ impl Resource for SearchResource {
})
.expect("Should never fail"),
)),
&ResponseType::Html => Ok(head.with_body(
ResponseType::Html => Ok(head.with_body(
system_page(
None, // Hmm, should perhaps accept `base` as argument
"Search",

View file

@ -143,7 +143,7 @@ impl Service for Site {
false => None,
};
let accept_header = headers.get().cloned().unwrap_or(Accept(vec![]));
let accept_header = headers.get().cloned().unwrap_or_else(|| Accept(vec![]));
let base = root_base_from_request_uri(uri.path());
let base2 = base.clone(); // Bah, stupid clone

View file

@ -281,7 +281,7 @@ impl<'a> SyncState<'a> {
.get_article_revision_stub(article_id, revision + 1)?
.expect("Application layer guarantee"),
title: title_merge,
body: body_merge.to_strings(),
body: body_merge.into_strings(),
theme,
}));
}
@ -625,7 +625,7 @@ mod test {
.create_article(None, "Title".into(), "Body".into(), None, Theme::Cyan)
.unwrap();
assert_eq!("title", article_revision.slug);
assert_eq!(true, article_revision.latest);
assert!(article_revision.latest);
assert_eq!(Theme::Cyan, article_revision.theme);
}
@ -896,7 +896,7 @@ mod test {
vec!["a"],
vec!["b"]
),])
.to_strings()
.into_strings()
);
assert_eq!(Theme::Amber, theme);
}