lang/syn: Fix module path resolution in crate parsing (#530)

This commit is contained in:
suscd 2021-07-18 01:03:36 -07:00 committed by GitHub
parent 2c80042ef5
commit fee6f3b3e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 5 deletions

View File

@ -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<Self> {
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,
)
}
})
}