From 1f15186a6c7929d0162ca2b8050947bbb7993f87 Mon Sep 17 00:00:00 2001 From: Jeremy <_@jeremy.ca> Date: Mon, 13 Sep 2021 22:50:41 +0000 Subject: [PATCH 1/6] Support string literal patterns resolves https://github.com/dtolnay/remain/issues/13 From fc56cabcd2fe7811c786d5b96c6d3882b3d18d9c Mon Sep 17 00:00:00 2001 From: Jeremy <_@jeremy.ca> Date: Mon, 13 Sep 2021 23:01:29 +0000 Subject: [PATCH 2/6] add tests/ui/match-strings-[un]stable.rs --- rust-toolchain.toml | 3 +++ tests/ui/match-strings-stable.rs | 30 +++++++++++++++++++++++ tests/ui/match-strings-stable.stderr | 0 tests/ui/match-strings-unstable.rs | 33 ++++++++++++++++++++++++++ tests/ui/match-strings-unstable.stderr | 0 5 files changed, 66 insertions(+) create mode 100644 rust-toolchain.toml create mode 100644 tests/ui/match-strings-stable.rs create mode 100644 tests/ui/match-strings-stable.stderr create mode 100644 tests/ui/match-strings-unstable.rs create mode 100644 tests/ui/match-strings-unstable.stderr diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..a307fe6 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +components = [ "rustfmt" ] diff --git a/tests/ui/match-strings-stable.rs b/tests/ui/match-strings-stable.rs new file mode 100644 index 0000000..c2652b6 --- /dev/null +++ b/tests/ui/match-strings-stable.rs @@ -0,0 +1,30 @@ +#[remain::check] +fn main() { + let value = "trivial_regex"; + + #[sorted] + match value { + "cognitive_complexity" => {} + "implicit_hasher" => {} + "inefficient_to_string" => {} + "integer_division" => {} + "large_digit_groups" => {} + "let_unit_value" => {} + "manual_map" => {} + "match_bool" => {} + "needless_pass_by_value" => {} + "new_ret_no_self" => {} + "nonstandard_macro_braces" => {} + "option_if_let_else" => {} + "option_option" => {} + "rc_buffer" => {} + "string_lit_as_bytes" => {} + "trivial_regex" => {} + "trivially_copy_pass_by_ref" => {} + "useless_let_if_seq" => {} + "unnested_or_patterns" => {} + "unreadable_literal" => {} + "unsafe_vector_initialization" => {} + _ => {} + } +} diff --git a/tests/ui/match-strings-stable.stderr b/tests/ui/match-strings-stable.stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/ui/match-strings-unstable.rs b/tests/ui/match-strings-unstable.rs new file mode 100644 index 0000000..5c24a35 --- /dev/null +++ b/tests/ui/match-strings-unstable.rs @@ -0,0 +1,33 @@ +#![feature(proc_macro_hygiene, stmt_expr_attributes)] + +use remain::sorted; + +fn main() { + let value = "trivial_regex"; + + #[sorted] + match value { + "cognitive_complexity" => {} + "implicit_hasher" => {} + "inefficient_to_string" => {} + "integer_division" => {} + "large_digit_groups" => {} + "let_unit_value" => {} + "manual_map" => {} + "match_bool" => {} + "needless_pass_by_value" => {} + "new_ret_no_self" => {} + "nonstandard_macro_braces" => {} + "option_if_let_else" => {} + "option_option" => {} + "rc_buffer" => {} + "string_lit_as_bytes" => {} + "trivial_regex" => {} + "trivially_copy_pass_by_ref" => {} + "useless_let_if_seq" => {} + "unnested_or_patterns" => {} + "unreadable_literal" => {} + "unsafe_vector_initialization" => {} + _ => {} + } +} diff --git a/tests/ui/match-strings-unstable.stderr b/tests/ui/match-strings-unstable.stderr new file mode 100644 index 0000000..e69de29 From 8624c043706f179aa816439eadbb0e6fc45c0f5f Mon Sep 17 00:00:00 2001 From: Jeremy <_@jeremy.ca> Date: Tue, 14 Sep 2021 02:24:15 +0000 Subject: [PATCH 3/6] treat strings as idents --- src/check.rs | 30 +++++++++++++++++--------- tests/ui/match-strings-stable.stderr | 5 +++++ tests/ui/match-strings-unstable.stderr | 7 ++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/check.rs b/src/check.rs index 39a23e5..6139ea9 100644 --- a/src/check.rs +++ b/src/check.rs @@ -1,5 +1,6 @@ use quote::quote; use std::cmp::Ordering; +use syn::spanned::Spanned; use syn::{Arm, Attribute, Ident, Result, Variant}; use syn::{Error, Field, Pat, PatIdent}; @@ -109,18 +110,27 @@ impl Sortable for Arm { }; let segments = match pat { - Pat::Ident(pat) if is_just_ident(pat) => vec![pat.ident.clone()], - Pat::Path(pat) => idents_of_path(&pat.path), - Pat::Struct(pat) => idents_of_path(&pat.path), - Pat::TupleStruct(pat) => idents_of_path(&pat.path), - Pat::Wild(pat) => vec![Ident::from(pat.underscore_token)], - other => { - let msg = "unsupported by #[remain::sorted]"; - return Err(Error::new_spanned(other, msg)); - } + Pat::Lit(pat_lit) => match pat_lit.expr.as_ref() { + syn::Expr::Lit(lit) => match &lit.lit { + syn::Lit::Str(s) => Some(vec![Ident::new(&s.value(), self.span())]), + _ => None, + }, + _ => None, + }, + Pat::Ident(pat) if is_just_ident(pat) => Some(vec![pat.ident.clone()]), + Pat::Path(pat) => Some(idents_of_path(&pat.path)), + Pat::Struct(pat) => Some(idents_of_path(&pat.path)), + Pat::TupleStruct(pat) => Some(idents_of_path(&pat.path)), + Pat::Wild(pat) => Some(vec![Ident::from(pat.underscore_token)]), + _ => None, }; - Ok(Path { segments }) + if let Some(segments) = segments { + Ok(Path { segments }) + } else { + let msg = "unsupported by #[remain::sorted]"; + Err(Error::new_spanned(pat, msg)) + } } fn attrs(&mut self) -> &mut Vec { &mut self.attrs diff --git a/tests/ui/match-strings-stable.stderr b/tests/ui/match-strings-stable.stderr index e69de29..4819139 100644 --- a/tests/ui/match-strings-stable.stderr +++ b/tests/ui/match-strings-stable.stderr @@ -0,0 +1,5 @@ +error: unnested_or_patterns should sort before useless_let_if_seq + --> $DIR/match-strings-stable.rs:25:9 + | +25 | "unnested_or_patterns" => {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match-strings-unstable.stderr b/tests/ui/match-strings-unstable.stderr index e69de29..116acc0 100644 --- a/tests/ui/match-strings-unstable.stderr +++ b/tests/ui/match-strings-unstable.stderr @@ -0,0 +1,7 @@ +error: unnested_or_patterns should sort before useless_let_if_seq + --> $DIR/match-strings-unstable.rs:8:5 + | +8 | #[sorted] + | ^^^^^^^^^ + | + = note: this error originates in the attribute macro `sorted` (in Nightly builds, run with -Z macro-backtrace for more info) From 0af5f74ca6c9eff4b649dafe91ab954c73bd4682 Mon Sep 17 00:00:00 2001 From: Jeremy <_@jeremy.ca> Date: Tue, 14 Sep 2021 18:39:02 +0000 Subject: [PATCH 4/6] but they're not identifiers --- tests/ui/match-strings-stable.rs | 1 + tests/ui/match-strings-unstable.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/ui/match-strings-stable.rs b/tests/ui/match-strings-stable.rs index c2652b6..515cb4f 100644 --- a/tests/ui/match-strings-stable.rs +++ b/tests/ui/match-strings-stable.rs @@ -5,6 +5,7 @@ fn main() { #[sorted] match value { "cognitive_complexity" => {} + "hello world" => {} "implicit_hasher" => {} "inefficient_to_string" => {} "integer_division" => {} diff --git a/tests/ui/match-strings-unstable.rs b/tests/ui/match-strings-unstable.rs index 5c24a35..58d2e6c 100644 --- a/tests/ui/match-strings-unstable.rs +++ b/tests/ui/match-strings-unstable.rs @@ -8,6 +8,7 @@ fn main() { #[sorted] match value { "cognitive_complexity" => {} + "hello world" => {} "implicit_hasher" => {} "inefficient_to_string" => {} "integer_division" => {} From c5cb09d65129b435d02f46acd74893ef3e63eba1 Mon Sep 17 00:00:00 2001 From: Jeremy <_@jeremy.ca> Date: Tue, 14 Sep 2021 20:37:55 +0000 Subject: [PATCH 5/6] Replace `Path` with more-generic `Comparable` --- src/check.rs | 59 +++++++++++-------- src/compare.rs | 40 +++++++++++-- src/format.rs | 8 +-- ...trings-stable.rs => match-mixed-stable.rs} | 4 +- tests/ui/match-mixed-stable.stderr | 5 ++ ...gs-unstable.rs => match-mixed-unstable.rs} | 4 +- ...ble.stderr => match-mixed-unstable.stderr} | 4 +- tests/ui/match-strings-stable.stderr | 5 -- 8 files changed, 86 insertions(+), 43 deletions(-) rename tests/ui/{match-strings-stable.rs => match-mixed-stable.rs} (93%) create mode 100644 tests/ui/match-mixed-stable.stderr rename tests/ui/{match-strings-unstable.rs => match-mixed-unstable.rs} (93%) rename tests/ui/{match-strings-unstable.stderr => match-mixed-unstable.stderr} (60%) delete mode 100644 tests/ui/match-strings-stable.stderr diff --git a/src/check.rs b/src/check.rs index 6139ea9..be5023c 100644 --- a/src/check.rs +++ b/src/check.rs @@ -1,18 +1,17 @@ use quote::quote; use std::cmp::Ordering; -use syn::spanned::Spanned; -use syn::{Arm, Attribute, Ident, Result, Variant}; +use syn::{Arm, Attribute, Result, Variant}; use syn::{Error, Field, Pat, PatIdent}; -use crate::compare::{cmp, Path, UnderscoreOrder}; +use crate::compare::{cmp, Comparable, Segment, UnderscoreOrder}; use crate::format; use crate::parse::Input::{self, *}; pub fn sorted(input: &mut Input) -> Result<()> { let paths = match input { - Enum(item) => collect_paths(&mut item.variants)?, - Struct(item) => collect_paths(&mut item.fields)?, - Match(expr) | Let(expr) => collect_paths(&mut expr.arms)?, + Enum(item) => collect_comparables(&mut item.variants)?, + Struct(item) => collect_comparables(&mut item.fields)?, + Match(expr) | Let(expr) => collect_comparables(&mut expr.arms)?, }; let mode = UnderscoreOrder::First; @@ -35,7 +34,7 @@ pub fn sorted(input: &mut Input) -> Result<()> { Err(format::error(lesser, greater)) } -fn find_misordered(paths: &[Path], mode: UnderscoreOrder) -> Option { +fn find_misordered(paths: &[Comparable], mode: UnderscoreOrder) -> Option { for i in 1..paths.len() { if cmp(&paths[i], &paths[i - 1], mode) == Ordering::Less { return Some(i); @@ -45,7 +44,7 @@ fn find_misordered(paths: &[Path], mode: UnderscoreOrder) -> Option { None } -fn collect_paths<'a, I, P>(iter: I) -> Result> +fn collect_comparables<'a, I, P>(iter: I) -> Result> where I: IntoIterator, P: Sortable + 'a, @@ -75,14 +74,14 @@ fn remove_unsorted_attr(attrs: &mut Vec) -> bool { } trait Sortable { - fn to_path(&self) -> Result; + fn to_path(&self) -> Result; fn attrs(&mut self) -> &mut Vec; } impl Sortable for Variant { - fn to_path(&self) -> Result { - Ok(Path { - segments: vec![self.ident.clone()], + fn to_path(&self) -> Result { + Ok(Comparable { + segments: vec![Box::new(self.ident.clone())], }) } fn attrs(&mut self) -> &mut Vec { @@ -91,9 +90,11 @@ impl Sortable for Variant { } impl Sortable for Field { - fn to_path(&self) -> Result { - Ok(Path { - segments: vec![self.ident.clone().expect("must be named field")], + fn to_path(&self) -> Result { + Ok(Comparable { + segments: vec![Box::new( + self.ident.as_ref().expect("must be named field").clone(), + )], }) } fn attrs(&mut self) -> &mut Vec { @@ -102,31 +103,31 @@ impl Sortable for Field { } impl Sortable for Arm { - fn to_path(&self) -> Result { + fn to_path(&self) -> Result { // Sort by just the first pat. let pat = match &self.pat { Pat::Or(pat) => pat.cases.iter().next().expect("at least one pat"), _ => &self.pat, }; - let segments = match pat { + let segments: Option = match pat { Pat::Lit(pat_lit) => match pat_lit.expr.as_ref() { syn::Expr::Lit(lit) => match &lit.lit { - syn::Lit::Str(s) => Some(vec![Ident::new(&s.value(), self.span())]), + syn::Lit::Str(s) => Some(Comparable::of(s.clone())), _ => None, }, _ => None, }, - Pat::Ident(pat) if is_just_ident(pat) => Some(vec![pat.ident.clone()]), - Pat::Path(pat) => Some(idents_of_path(&pat.path)), - Pat::Struct(pat) => Some(idents_of_path(&pat.path)), - Pat::TupleStruct(pat) => Some(idents_of_path(&pat.path)), - Pat::Wild(pat) => Some(vec![Ident::from(pat.underscore_token)]), + 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::Wild(pat) => Some(Comparable::of(pat.underscore_token)), _ => None, }; if let Some(segments) = segments { - Ok(Path { segments }) + Ok(segments) } else { let msg = "unsupported by #[remain::sorted]"; Err(Error::new_spanned(pat, msg)) @@ -137,8 +138,14 @@ impl Sortable for Arm { } } -fn idents_of_path(path: &syn::Path) -> Vec { - path.segments.iter().map(|seg| seg.ident.clone()).collect() +fn comprables_of_path(path: &syn::Path) -> Comparable { + let mut segments: Vec> = vec![]; + + for seg in path.segments.iter() { + segments.push(Box::new(seg.ident.clone())); + } + + Comparable { segments } } fn is_just_ident(pat: &PatIdent) -> bool { diff --git a/src/compare.rs b/src/compare.rs index 3fa4198..9a8c935 100644 --- a/src/compare.rs +++ b/src/compare.rs @@ -1,5 +1,6 @@ use proc_macro2::Ident; use std::cmp::Ordering; +use syn::LitStr; use crate::atom::iter_atoms; @@ -9,11 +10,42 @@ pub enum UnderscoreOrder { Last, } -pub struct Path { - pub segments: Vec, +pub struct Comparable { + pub segments: Vec>, } -pub fn cmp(lhs: &Path, rhs: &Path, mode: UnderscoreOrder) -> Ordering { +impl Comparable { + pub fn of(segment: impl Segment + 'static) -> Comparable { + Comparable { + segments: vec![Box::new(segment)], + } + } +} + +pub trait Segment: quote::ToTokens { + /// The string representation of these tokens to be used for sorting. + fn to_string(&self) -> String; +} + +impl Segment for Ident { + fn to_string(&self) -> String { + ToString::to_string(&self) + } +} + +impl Segment for LitStr { + fn to_string(&self) -> String { + self.value().to_string() + } +} + +impl Segment for syn::token::Underscore { + fn to_string(&self) -> String { + "_".to_string() + } +} + +pub fn cmp(lhs: &Comparable, rhs: &Comparable, mode: UnderscoreOrder) -> Ordering { // Lexicographic ordering across path segments. for (lhs, rhs) in lhs.segments.iter().zip(&rhs.segments) { match cmp_segment(&lhs.to_string(), &rhs.to_string(), mode) { @@ -37,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); - // Path segments can't be empty. + // Comparable segments can't be empty. let mut left = lhs_atoms.next().unwrap(); let mut right = rhs_atoms.next().unwrap(); diff --git a/src/format.rs b/src/format.rs index 5832643..62bd08e 100644 --- a/src/format.rs +++ b/src/format.rs @@ -3,21 +3,21 @@ use quote::TokenStreamExt; use std::fmt::{self, Display}; use syn::Error; -use crate::compare::Path; +use crate::compare::Comparable; -impl Display for Path { +impl Display for Comparable { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { for (i, segment) in self.segments.iter().enumerate() { if i > 0 { formatter.write_str("::")?; } - segment.fmt(formatter)?; + segment.to_string().fmt(formatter)?; } Ok(()) } } -pub fn error(lesser: &Path, greater: &Path) -> Error { +pub fn error(lesser: &Comparable, greater: &Comparable) -> Error { let mut spans = TokenStream::new(); spans.append_all(&lesser.segments); diff --git a/tests/ui/match-strings-stable.rs b/tests/ui/match-mixed-stable.rs similarity index 93% rename from tests/ui/match-strings-stable.rs rename to tests/ui/match-mixed-stable.rs index 515cb4f..c5c9097 100644 --- a/tests/ui/match-strings-stable.rs +++ b/tests/ui/match-mixed-stable.rs @@ -10,9 +10,11 @@ fn main() { "inefficient_to_string" => {} "integer_division" => {} "large_digit_groups" => {} + let_it_be if false => {} "let_unit_value" => {} "manual_map" => {} "match_bool" => {} + mixed_in if false => {} "needless_pass_by_value" => {} "new_ret_no_self" => {} "nonstandard_macro_braces" => {} @@ -21,8 +23,8 @@ fn main() { "rc_buffer" => {} "string_lit_as_bytes" => {} "trivial_regex" => {} - "trivially_copy_pass_by_ref" => {} "useless_let_if_seq" => {} + "trivially_copy_pass_by_ref" => {} "unnested_or_patterns" => {} "unreadable_literal" => {} "unsafe_vector_initialization" => {} diff --git a/tests/ui/match-mixed-stable.stderr b/tests/ui/match-mixed-stable.stderr new file mode 100644 index 0000000..90c919b --- /dev/null +++ b/tests/ui/match-mixed-stable.stderr @@ -0,0 +1,5 @@ +error: trivially_copy_pass_by_ref should sort before useless_let_if_seq + --> $DIR/match-mixed-stable.rs:27:9 + | +27 | "trivially_copy_pass_by_ref" => {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/match-strings-unstable.rs b/tests/ui/match-mixed-unstable.rs similarity index 93% rename from tests/ui/match-strings-unstable.rs rename to tests/ui/match-mixed-unstable.rs index 58d2e6c..5b1d1f5 100644 --- a/tests/ui/match-strings-unstable.rs +++ b/tests/ui/match-mixed-unstable.rs @@ -13,9 +13,11 @@ fn main() { "inefficient_to_string" => {} "integer_division" => {} "large_digit_groups" => {} + let_it_be if false => {} "let_unit_value" => {} "manual_map" => {} "match_bool" => {} + mixed_in if false => {} "needless_pass_by_value" => {} "new_ret_no_self" => {} "nonstandard_macro_braces" => {} @@ -24,8 +26,8 @@ fn main() { "rc_buffer" => {} "string_lit_as_bytes" => {} "trivial_regex" => {} - "trivially_copy_pass_by_ref" => {} "useless_let_if_seq" => {} + "trivially_copy_pass_by_ref" => {} "unnested_or_patterns" => {} "unreadable_literal" => {} "unsafe_vector_initialization" => {} diff --git a/tests/ui/match-strings-unstable.stderr b/tests/ui/match-mixed-unstable.stderr similarity index 60% rename from tests/ui/match-strings-unstable.stderr rename to tests/ui/match-mixed-unstable.stderr index 116acc0..86e98cf 100644 --- a/tests/ui/match-strings-unstable.stderr +++ b/tests/ui/match-mixed-unstable.stderr @@ -1,5 +1,5 @@ -error: unnested_or_patterns should sort before useless_let_if_seq - --> $DIR/match-strings-unstable.rs:8:5 +error: trivially_copy_pass_by_ref should sort before useless_let_if_seq + --> $DIR/match-mixed-unstable.rs:8:5 | 8 | #[sorted] | ^^^^^^^^^ diff --git a/tests/ui/match-strings-stable.stderr b/tests/ui/match-strings-stable.stderr deleted file mode 100644 index 4819139..0000000 --- a/tests/ui/match-strings-stable.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: unnested_or_patterns should sort before useless_let_if_seq - --> $DIR/match-strings-stable.rs:25:9 - | -25 | "unnested_or_patterns" => {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 3e51dcf8f2a048d1f624e2076837029665d27f9a Mon Sep 17 00:00:00 2001 From: Jeremy <_@jeremy.ca> Date: Tue, 14 Sep 2021 20:51:22 +0000 Subject: [PATCH 6/6] 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();