Correct `use` resolution for submodule use statements
authorMatt Corallo <git@bluematt.me>
Mon, 17 Jul 2023 02:19:46 +0000 (02:19 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 28 Jul 2023 23:06:00 +0000 (23:06 +0000)
Otherwise we fail to resolve a `use` that starts with a submodule
of the current module.

c-bindings-gen/src/types.rs

index 6e60f82a7a3d9e36e000da84cd6d44fb4bf35f08..398d0241c61d3b10d524e37a602a5c0a3fc3e2aa 100644 (file)
@@ -474,9 +474,12 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
                                        let crate_name_ident = format_ident!("{}", crate_name);
                                        path.push(parse_quote!(#crate_name_ident));
                                } else if partial_path == "" && !dependencies.contains(&$ident) {
-                                       new_path = format!("{}::{}{}", crate_name, $ident, $path_suffix);
-                                       let crate_name_ident = format_ident!("{}", crate_name);
-                                       path.push(parse_quote!(#crate_name_ident));
+                                       new_path = format!("{}::{}{}", module_path, $ident, $path_suffix);
+                                       for module in module_path.split("::") {
+                                               path.push(syn::PathSegment { ident: syn::Ident::new(module, Span::call_site()), arguments: syn::PathArguments::None });
+                                       }
+                                       let ident_str = format_ident!("{}", $ident);
+                                       path.push(parse_quote!(#ident_str));
                                } else if format!("{}", $ident) == "self" {
                                        let mut path_iter = partial_path.rsplitn(2, "::");
                                        path_iter.next().unwrap();