Fix handling of modules in non_modrs_mods style
We need to keep track of the module relative to which we're resolving paths, instead of always passing None. Fixes #2673.
This commit is contained in:
parent
3762d80d68
commit
cf573e8157
1 changed files with 26 additions and 11 deletions
|
|
@ -14,7 +14,7 @@ use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::codemap::{self, FileName};
|
use syntax::codemap::{self, FileName};
|
||||||
use syntax::parse::parser;
|
use syntax::parse::{parser, DirectoryOwnership};
|
||||||
|
|
||||||
use utils::contains_skip;
|
use utils::contains_skip;
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ pub fn list_files<'a>(
|
||||||
FileName::Real(ref path) => path.parent().unwrap(),
|
FileName::Real(ref path) => path.parent().unwrap(),
|
||||||
_ => Path::new(""),
|
_ => Path::new(""),
|
||||||
};
|
};
|
||||||
list_submodules(&krate.module, parent, codemap, &mut result)?;
|
list_submodules(&krate.module, parent, None, codemap, &mut result)?;
|
||||||
}
|
}
|
||||||
result.insert(root_filename, &krate.module);
|
result.insert(root_filename, &krate.module);
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|
@ -41,6 +41,7 @@ pub fn list_files<'a>(
|
||||||
fn list_submodules<'a>(
|
fn list_submodules<'a>(
|
||||||
module: &'a ast::Mod,
|
module: &'a ast::Mod,
|
||||||
search_dir: &Path,
|
search_dir: &Path,
|
||||||
|
relative: Option<ast::Ident>,
|
||||||
codemap: &codemap::CodeMap,
|
codemap: &codemap::CodeMap,
|
||||||
result: &mut BTreeMap<FileName, &'a ast::Mod>,
|
result: &mut BTreeMap<FileName, &'a ast::Mod>,
|
||||||
) -> Result<(), io::Error> {
|
) -> Result<(), io::Error> {
|
||||||
|
|
@ -50,15 +51,16 @@ fn list_submodules<'a>(
|
||||||
if !contains_skip(&item.attrs) {
|
if !contains_skip(&item.attrs) {
|
||||||
let is_internal =
|
let is_internal =
|
||||||
codemap.span_to_filename(item.span) == codemap.span_to_filename(sub_mod.inner);
|
codemap.span_to_filename(item.span) == codemap.span_to_filename(sub_mod.inner);
|
||||||
let dir_path = if is_internal {
|
let (dir_path, relative) = if is_internal {
|
||||||
search_dir.join(&item.ident.to_string())
|
(search_dir.join(&item.ident.to_string()), None)
|
||||||
} else {
|
} else {
|
||||||
let mod_path = module_file(item.ident, &item.attrs, search_dir, codemap)?;
|
let (mod_path, relative) =
|
||||||
|
module_file(item.ident, &item.attrs, search_dir, relative, codemap)?;
|
||||||
let dir_path = mod_path.parent().unwrap().to_owned();
|
let dir_path = mod_path.parent().unwrap().to_owned();
|
||||||
result.insert(FileName::Real(mod_path), sub_mod);
|
result.insert(FileName::Real(mod_path), sub_mod);
|
||||||
dir_path
|
(dir_path, relative)
|
||||||
};
|
};
|
||||||
list_submodules(sub_mod, &dir_path, codemap, result)?;
|
list_submodules(sub_mod, &dir_path, relative, codemap, result)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,14 +72,27 @@ fn module_file(
|
||||||
id: ast::Ident,
|
id: ast::Ident,
|
||||||
attrs: &[ast::Attribute],
|
attrs: &[ast::Attribute],
|
||||||
dir_path: &Path,
|
dir_path: &Path,
|
||||||
|
relative: Option<ast::Ident>,
|
||||||
codemap: &codemap::CodeMap,
|
codemap: &codemap::CodeMap,
|
||||||
) -> Result<PathBuf, io::Error> {
|
) -> Result<(PathBuf, Option<ast::Ident>), io::Error> {
|
||||||
|
eprintln!("module_file {:?} {:?} {:?}", id, attrs, dir_path);
|
||||||
if let Some(path) = parser::Parser::submod_path_from_attr(attrs, dir_path) {
|
if let Some(path) = parser::Parser::submod_path_from_attr(attrs, dir_path) {
|
||||||
return Ok(path);
|
return Ok((path, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
match parser::Parser::default_submod_path(id, None, dir_path, codemap).result {
|
match parser::Parser::default_submod_path(id, relative, dir_path, codemap).result {
|
||||||
Ok(parser::ModulePathSuccess { path, .. }) => Ok(path),
|
Ok(parser::ModulePathSuccess {
|
||||||
|
path,
|
||||||
|
directory_ownership,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
|
let relative = if let DirectoryOwnership::Owned { relative } = directory_ownership {
|
||||||
|
relative
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
Ok((path, relative))
|
||||||
|
}
|
||||||
Err(_) => Err(io::Error::new(
|
Err(_) => Err(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
format!("Couldn't find module {}", id),
|
format!("Couldn't find module {}", id),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue