]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Replace more manually-built `syn::Path` with `parse_quote!()`
authorAlekos Filini <alekos.filini@gmail.com>
Mon, 26 Apr 2021 12:20:47 +0000 (14:20 +0200)
committerAlekos Filini <alekos.filini@gmail.com>
Mon, 26 Apr 2021 12:20:47 +0000 (14:20 +0200)
c-bindings-gen/src/main.rs
c-bindings-gen/src/types.rs

index c869e327bcdcf7956c83772a88da08893caffc57..d107f3e9a6c66af726c4c84602c45c209686712c 100644 (file)
@@ -1486,20 +1486,17 @@ fn walk_ast<'a>(ast_storage: &'a FullLibraryAST, crate_types: &mut CrateTypes<'a
                                                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()));
index d27c0b96b2a209794e7ecd645c16521f704a7b10..c8b71d6b71b93cd99a302db51496b2a247f0c9c5 100644 (file)
@@ -343,11 +343,13 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
                        ($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 {
@@ -386,9 +388,8 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
 
        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 {