style: Make clippy happy

This commit is contained in:
Ed Page 2023-09-01 10:19:16 -05:00
parent 67ca12a847
commit 0c05b217d4
8 changed files with 31 additions and 44 deletions

View file

@ -7,7 +7,7 @@ fn codegen() {
let content = String::from_utf8(content).unwrap(); let content = String::from_utf8(content).unwrap();
let content = codegenrs::rustfmt(&content, None).unwrap(); let content = codegenrs::rustfmt(&content, None).unwrap();
snapbox::assert_eq_path("./src/dict_codegen.rs", &content); snapbox::assert_eq_path("./src/dict_codegen.rs", content);
} }
#[test] #[test]

View file

@ -28,9 +28,9 @@ impl<V> DictTrie<V> {
match child.children { match child.children {
DictTrieChild::Nested(n) => { DictTrieChild::Nested(n) => {
let byte = bytes[i]; let byte = bytes[i];
let index = if (b'a'..=b'z').contains(&byte) { let index = if byte.is_ascii_lowercase() {
byte - b'a' byte - b'a'
} else if (b'A'..=b'Z').contains(&byte) { } else if byte.is_ascii_uppercase() {
byte - b'A' byte - b'A'
} else { } else {
return self.unicode.find(word); return self.unicode.find(word);

View file

@ -3,10 +3,11 @@ use clap::Parser;
use typos_cli::config; use typos_cli::config;
#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)] #[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum, Default)]
pub enum Format { pub enum Format {
Silent, Silent,
Brief, Brief,
#[default]
Long, Long,
Json, Json,
} }
@ -32,12 +33,6 @@ impl Format {
} }
} }
impl Default for Format {
fn default() -> Self {
Format::Long
}
}
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[command(rename_all = "kebab-case")] #[command(rename_all = "kebab-case")]
#[command(about, author, version)] #[command(about, author, version)]

View file

@ -483,7 +483,9 @@ impl Eq for DictConfig {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
#[derive(Default)]
pub enum Locale { pub enum Locale {
#[default]
En, En,
EnUs, EnUs,
EnGb, EnGb,
@ -507,12 +509,6 @@ impl Locale {
} }
} }
impl Default for Locale {
fn default() -> Self {
Locale::En
}
}
impl std::str::FromStr for Locale { impl std::str::FromStr for Locale {
type Err = String; type Err = String;

View file

@ -18,17 +18,14 @@ impl BuiltIn {
} }
} }
pub fn correct_ident<'s, 'w>( pub fn correct_ident<'s>(
&'s self, &'s self,
_ident: typos::tokens::Identifier<'w>, _ident: typos::tokens::Identifier<'_>,
) -> Option<Status<'s>> { ) -> Option<Status<'s>> {
None None
} }
pub fn correct_word<'s, 'w>( pub fn correct_word<'s>(&'s self, word_token: typos::tokens::Word<'_>) -> Option<Status<'s>> {
&'s self,
word_token: typos::tokens::Word<'w>,
) -> Option<Status<'s>> {
if word_token.case() == typos::tokens::Case::None { if word_token.case() == typos::tokens::Case::None {
return None; return None;
} }
@ -162,11 +159,11 @@ impl BuiltIn {
} }
impl typos::Dictionary for BuiltIn { impl typos::Dictionary for BuiltIn {
fn correct_ident<'s, 'w>(&'s self, ident: typos::tokens::Identifier<'w>) -> Option<Status<'s>> { fn correct_ident<'s>(&'s self, ident: typos::tokens::Identifier<'_>) -> Option<Status<'s>> {
BuiltIn::correct_ident(self, ident) BuiltIn::correct_ident(self, ident)
} }
fn correct_word<'s, 'w>(&'s self, word: typos::tokens::Word<'w>) -> Option<Status<'s>> { fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option<Status<'s>> {
BuiltIn::correct_word(self, word) BuiltIn::correct_word(self, word)
} }
} }
@ -246,7 +243,7 @@ impl<'i, 'w, D: typos::Dictionary> Override<'i, 'w, D> {
} }
impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> { impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
fn correct_ident<'s, 't>(&'s self, ident: typos::tokens::Identifier<'t>) -> Option<Status<'s>> { fn correct_ident<'s>(&'s self, ident: typos::tokens::Identifier<'_>) -> Option<Status<'s>> {
for ignored in &self.ignored_identifiers { for ignored in &self.ignored_identifiers {
if ignored.is_match(ident.token()) { if ignored.is_match(ident.token()) {
return Some(Status::Valid); return Some(Status::Valid);
@ -264,7 +261,7 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
} }
} }
fn correct_word<'s, 't>(&'s self, word: typos::tokens::Word<'t>) -> Option<Status<'s>> { fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option<Status<'s>> {
if word.case() == typos::tokens::Case::None { if word.case() == typos::tokens::Case::None {
return None; return None;
} }

View file

@ -39,7 +39,6 @@ fn parse_dict(path: &str) -> Vec<(String, Vec<String>)> {
reader reader
.records() .records()
.into_iter()
.map(Result::unwrap) .map(Result::unwrap)
.map(|record| { .map(|record| {
let mut iter = record.into_iter(); let mut iter = record.into_iter();

View file

@ -5,12 +5,12 @@ pub trait Dictionary: Send + Sync {
/// Look up the validity of an Identifier. /// Look up the validity of an Identifier.
/// ///
/// `None` if the status is unknown. /// `None` if the status is unknown.
fn correct_ident<'s, 'w>(&'s self, ident: crate::tokens::Identifier<'w>) -> Option<Status<'s>>; fn correct_ident<'s>(&'s self, ident: crate::tokens::Identifier<'_>) -> Option<Status<'s>>;
/// Look up the validity of a Word. /// Look up the validity of a Word.
/// ///
/// `None` if the status is unknown. /// `None` if the status is unknown.
fn correct_word<'s, 'w>(&'s self, word: crate::tokens::Word<'w>) -> Option<Status<'s>>; fn correct_word<'s>(&'s self, word: crate::tokens::Word<'_>) -> Option<Status<'s>>;
} }
/// Validity of a term in a Dictionary. /// Validity of a term in a Dictionary.

View file

@ -510,21 +510,21 @@ mod parser {
#[inline] #[inline]
fn is_lower_hex_digit(i: impl AsChar + Copy) -> bool { fn is_lower_hex_digit(i: impl AsChar + Copy) -> bool {
let c = i.as_char(); let c = i.as_char();
('a'..='f').contains(&c) || ('0'..='9').contains(&c) ('a'..='f').contains(&c) || c.is_ascii_digit()
} }
#[inline] #[inline]
fn is_upper_hex_digit(i: impl AsChar + Copy) -> bool { fn is_upper_hex_digit(i: impl AsChar + Copy) -> bool {
let c = i.as_char(); let c = i.as_char();
('A'..='F').contains(&c) || ('0'..='9').contains(&c) ('A'..='F').contains(&c) || c.is_ascii_digit()
} }
#[inline] #[inline]
fn is_base64_digit(i: impl AsChar + Copy) -> bool { fn is_base64_digit(i: impl AsChar + Copy) -> bool {
let c = i.as_char(); let c = i.as_char();
('a'..='z').contains(&c) c.is_ascii_lowercase()
|| ('A'..='Z').contains(&c) || c.is_ascii_uppercase()
|| ('0'..='9').contains(&c) || c.is_ascii_digit()
|| c == '+' || c == '+'
|| c == '/' || c == '/'
} }
@ -538,18 +538,18 @@ mod parser {
#[inline] #[inline]
fn is_localport_char(i: impl AsChar + Copy) -> bool { fn is_localport_char(i: impl AsChar + Copy) -> bool {
let c = i.as_char(); let c = i.as_char();
('a'..='z').contains(&c) c.is_ascii_lowercase()
|| ('A'..='Z').contains(&c) || c.is_ascii_uppercase()
|| ('0'..='9').contains(&c) || c.is_ascii_digit()
|| "!#$%&'*+-/=?^_`{|}~().".find(c).is_some() || "!#$%&'*+-/=?^_`{|}~().".find(c).is_some()
} }
#[inline] #[inline]
fn is_domain_char(i: impl AsChar + Copy) -> bool { fn is_domain_char(i: impl AsChar + Copy) -> bool {
let c = i.as_char(); let c = i.as_char();
('a'..='z').contains(&c) c.is_ascii_lowercase()
|| ('A'..='Z').contains(&c) || c.is_ascii_uppercase()
|| ('0'..='9').contains(&c) || c.is_ascii_digit()
|| "-().".find(c).is_some() || "-().".find(c).is_some()
} }
@ -568,9 +568,9 @@ mod parser {
#[inline] #[inline]
fn is_uri_unreserved(i: impl AsChar + Copy) -> bool { fn is_uri_unreserved(i: impl AsChar + Copy) -> bool {
let c = i.as_char(); let c = i.as_char();
('a'..='z').contains(&c) c.is_ascii_lowercase()
|| ('A'..='Z').contains(&c) || c.is_ascii_uppercase()
|| ('0'..='9').contains(&c) || c.is_ascii_digit()
|| "-._~".find(c).is_some() || "-._~".find(c).is_some()
} }
@ -583,7 +583,7 @@ mod parser {
#[inline] #[inline]
fn is_scheme_char(i: impl AsChar + Copy) -> bool { fn is_scheme_char(i: impl AsChar + Copy) -> bool {
let c = i.as_char(); let c = i.as_char();
('a'..='z').contains(&c) || ('0'..='9').contains(&c) || "+.-".find(c).is_some() c.is_ascii_lowercase() || c.is_ascii_digit() || "+.-".find(c).is_some()
} }
#[inline] #[inline]