1 use proc_macro2::TokenStream; 2 use quote::TokenStreamExt; 3 use std::fmt::{self, Display}; 4 use syn::Error; 5 6 use crate::compare::Path; 7 8 impl Display for Path { fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result9 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 10 for (i, segment) in self.segments.iter().enumerate() { 11 if i > 0 { 12 formatter.write_str("::")?; 13 } 14 segment.fmt(formatter)?; 15 } 16 Ok(()) 17 } 18 } 19 error(lesser: &Path, greater: &Path) -> Error20pub fn error(lesser: &Path, greater: &Path) -> Error { 21 let mut spans = TokenStream::new(); 22 spans.append_all(&lesser.segments); 23 24 let msg = format!("{} should sort before {}", lesser, greater); 25 26 Error::new_spanned(spans, msg) 27 } 28