From d4581513623f6c531e211cca436efb13151cd29c Mon Sep 17 00:00:00 2001 From: Aphek Date: Sat, 6 Jan 2024 19:36:02 -0300 Subject: [PATCH] Sort `impl` blocks by rendering the type using quote --- build-util/src/visitors.rs | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/build-util/src/visitors.rs b/build-util/src/visitors.rs index 1da02d6..d7666a5 100644 --- a/build-util/src/visitors.rs +++ b/build-util/src/visitors.rs @@ -5,12 +5,14 @@ use std::{ rc::Rc, }; -use crate::vita_headers_db::{missing_features_filter, stub_lib_name, VitaDb}; +use quote::ToTokens; use syn::{ token, visit_mut::VisitMut, AttrStyle, Attribute, ForeignItem, Ident, Item, ItemForeignMod, - MacroDelimiter, Meta, MetaList, Type, + MacroDelimiter, Meta, MetaList, }; +use crate::vita_headers_db::{missing_features_filter, stub_lib_name, VitaDb}; + type FeatureSet = BTreeSet>; const DEFINED_ELSEWHERE_FUNCTIONS: [(&str, &str); 3] = [ @@ -215,24 +217,7 @@ impl VisitMut for Sort { Item::Enum(i) => (4, i.ident.to_string()), Item::Union(i) => (4, i.ident.to_string()), Item::Impl(i) => { - let ident = - match &*i.self_ty { - Type::Path(path_type) => path_type.path.segments.iter().fold( - String::new(), - |acc, segment| { - let ident_string = segment.ident.to_string(); - if acc.is_empty() { - ident_string - } else { - acc + "::" + &ident_string - } - }, - ), - ty => { - log::warn!("impl on unexpected type {ty:?}"); - String::new() - } - }; + let ident = i.self_ty.clone().into_token_stream().to_string(); (4, ident) } Item::Const(i) => (5, i.ident.to_string()),