Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyBanks authored Sep 16, 2021
1 parent c5cb09d commit 3e51dcf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly"
components = [ "rustfmt" ]
components = [ "rustfmt", "clippy" ]
20 changes: 8 additions & 12 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ trait Sortable {

impl Sortable for Variant {
fn to_path(&self) -> Result<Comparable> {
Ok(Comparable {
segments: vec![Box::new(self.ident.clone())],
})
Ok(Comparable::of(self.ident.clone()))
}
fn attrs(&mut self) -> &mut Vec<Attribute> {
&mut self.attrs
Expand All @@ -91,11 +89,9 @@ impl Sortable for Variant {

impl Sortable for Field {
fn to_path(&self) -> Result<Comparable> {
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<Attribute> {
&mut self.attrs
Expand All @@ -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,
};
Expand All @@ -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<Box<dyn Segment>> = vec![];

for seg in path.segments.iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Segment for Ident {

impl Segment for LitStr {
fn to_string(&self) -> String {
self.value().to_string()
self.value()
}
}

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 3e51dcf

Please sign in to comment.