if process_alias {
match &*t.ty {
syn::Type::Path(p) => {
+ let t_ident = &t.ident;
+
// If its a path with no generics, assume we don't map the aliased type and map it opaque
- let mut segments = syn::punctuated::Punctuated::new();
- segments.push(syn::PathSegment {
- ident: t.ident.clone(),
- arguments: syn::PathArguments::None,
- });
- let path_obj = syn::Path { leading_colon: None, segments };
+ let path_obj = parse_quote!(#t_ident);
let args_obj = p.path.segments.last().unwrap().arguments.clone();
match crate_types.reverse_alias_map.entry(import_resolver.maybe_resolve_path(&p.path, None).unwrap()) {
hash_map::Entry::Occupied(mut e) => { e.get_mut().push((path_obj, args_obj)); },
hash_map::Entry::Vacant(e) => { e.insert(vec![(path_obj, args_obj)]); },
}
- crate_types.opaques.insert(type_path.clone(), &t.ident);
+ crate_types.opaques.insert(type_path, t_ident);
},
_ => {
crate_types.type_aliases.insert(type_path, import_resolver.resolve_imported_refs((*t.ty).clone()));
($ident: expr, $path_suffix: expr) => {
if partial_path == "" && !dependencies.contains(&$ident) {
new_path = format!("{}::{}{}", crate_name, $ident, $path_suffix);
- path.push(syn::PathSegment { ident: format_ident!("{}", crate_name), arguments: syn::PathArguments::None });
+ let crate_name_ident = format_ident!("{}", crate_name);
+ path.push(parse_quote!(#crate_name_ident));
} else {
new_path = format!("{}{}{}", partial_path, $ident, $path_suffix);
}
- path.push(syn::PathSegment { ident: $ident.clone(), arguments: syn::PathArguments::None });
+ let ident = &$ident;
+ path.push(parse_quote!(#ident));
}
}
match u {
fn insert_primitive(imports: &mut HashMap<syn::Ident, (String, syn::Path)>, id: &str) {
let ident = format_ident!("{}", id);
- let mut path = syn::punctuated::Punctuated::new();
- path.push(syn::PathSegment { ident: ident.clone(), arguments: syn::PathArguments::None });
- imports.insert(ident, (id.to_owned(), syn::Path { leading_colon: None, segments: path }));
+ let path = parse_quote!(#ident);
+ imports.insert(ident, (id.to_owned(), path));
}
pub fn new(crate_name: &'mod_lifetime str, dependencies: &'mod_lifetime HashSet<syn::Ident>, module_path: &'mod_lifetime str, contents: &'crate_lft [syn::Item]) -> Self {