From 3e51dcf8f2a048d1f624e2076837029665d27f9a Mon Sep 17 00:00:00 2001 From: Jeremy <_@jeremy.ca> Date: Tue, 14 Sep 2021 20:51:22 +0000 Subject: [PATCH] Clean-up --- rust-toolchain.toml | 2 +- src/check.rs | 20 ++++++++------------ src/compare.rs | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a307fe6..e9d4cf2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] channel = "nightly" -components = [ "rustfmt" ] +components = [ "rustfmt", "clippy" ] diff --git a/src/check.rs b/src/check.rs index be5023c..3006127 100644 --- a/src/check.rs +++ b/src/check.rs @@ -80,9 +80,7 @@ trait Sortable { impl Sortable for Variant { fn to_path(&self) -> Result { - Ok(Comparable { - segments: vec![Box::new(self.ident.clone())], - }) + Ok(Comparable::of(self.ident.clone())) } fn attrs(&mut self) -> &mut Vec { &mut self.attrs @@ -91,11 +89,9 @@ impl Sortable for Variant { impl Sortable for Field { fn to_path(&self) -> Result { - Ok(Comparable { - segments: vec![Box::new( - self.ident.as_ref().expect("must be named field").clone(), - )], - }) + Ok(Comparable::of( + self.ident.as_ref().expect("must be named field").clone(), + )) } fn attrs(&mut self) -> &mut Vec { &mut self.attrs @@ -119,9 +115,9 @@ impl Sortable for Arm { _ => None, }, Pat::Ident(pat) if is_just_ident(pat) => Some(Comparable::of(pat.ident.clone())), - Pat::Path(pat) => Some(comprables_of_path(&pat.path)), - Pat::Struct(pat) => Some(comprables_of_path(&pat.path)), - Pat::TupleStruct(pat) => Some(comprables_of_path(&pat.path)), + Pat::Path(pat) => Some(comparables_of_path(&pat.path)), + Pat::Struct(pat) => Some(comparables_of_path(&pat.path)), + Pat::TupleStruct(pat) => Some(comparables_of_path(&pat.path)), Pat::Wild(pat) => Some(Comparable::of(pat.underscore_token)), _ => None, }; @@ -138,7 +134,7 @@ impl Sortable for Arm { } } -fn comprables_of_path(path: &syn::Path) -> Comparable { +fn comparables_of_path(path: &syn::Path) -> Comparable { let mut segments: Vec> = vec![]; for seg in path.segments.iter() { diff --git a/src/compare.rs b/src/compare.rs index 9a8c935..84fbdb3 100644 --- a/src/compare.rs +++ b/src/compare.rs @@ -35,7 +35,7 @@ impl Segment for Ident { impl Segment for LitStr { fn to_string(&self) -> String { - self.value().to_string() + self.value() } } @@ -69,7 +69,7 @@ fn cmp_segment(lhs: &str, rhs: &str, mode: UnderscoreOrder) -> Ordering { let mut lhs_atoms = iter_atoms(lhs); let mut rhs_atoms = iter_atoms(rhs); - // Comparable segments can't be empty. + // Path segments can't be empty. let mut left = lhs_atoms.next().unwrap(); let mut right = rhs_atoms.next().unwrap();