From fee6f3b3e395546c2dc6731649ce1f27a9dce901 Mon Sep 17 00:00:00 2001 From: suscd Date: Sun, 18 Jul 2021 01:03:36 -0700 Subject: [PATCH] lang/syn: Fix module path resolution in crate parsing (#530) --- lang/syn/src/parser/context.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lang/syn/src/parser/context.rs b/lang/syn/src/parser/context.rs index 6801e8b5b..7c54b4ca3 100644 --- a/lang/syn/src/parser/context.rs +++ b/lang/syn/src/parser/context.rs @@ -97,7 +97,7 @@ impl ParsedModule { item: item.clone(), file: module.file.clone(), path: module.path.clone(), - name: name.clone(), + name: item.ident.to_string(), })); modules.insert(name.clone(), module); } @@ -112,12 +112,15 @@ impl ParsedModule { parent_path: &str, item: syn::ItemMod, ) -> ParseResult { - let path = format!("{}::{}", parent_path, item.ident); - Ok(match item.content { Some((_, items)) => { // The module content is within the parent file being parsed - Self::new(path, parent_file.to_owned(), item.ident.to_string(), items) + Self::new( + parent_path.to_owned(), + parent_file.to_owned(), + item.ident.to_string(), + items, + ) } None => { // The module is referencing some other file, so we need to load that @@ -141,7 +144,12 @@ impl ParsedModule { .map_err(|_| ParseError::new_spanned(&item, "could not read file"))?; let mod_file = syn::parse_file(&mod_file_content)?; - Self::new(path, mod_file_path, item.ident.to_string(), mod_file.items) + Self::new( + parent_path.to_owned(), + mod_file_path, + item.ident.to_string(), + mod_file.items, + ) } }) }