simplify submod_path

This commit is contained in:
Mazdak Farrokhzad 2020-03-07 19:20:31 +01:00
parent 185c1d340c
commit 2db5d49d47

View File

@ -102,20 +102,18 @@ impl<'a> Parser<'a> {
id_sp: Span, id_sp: Span,
) -> PResult<'a, ModulePathSuccess> { ) -> PResult<'a, ModulePathSuccess> {
if let Some(path) = Parser::submod_path_from_attr(outer_attrs, &self.directory.path) { if let Some(path) = Parser::submod_path_from_attr(outer_attrs, &self.directory.path) {
return Ok(ModulePathSuccess { let directory_ownership = match path.file_name().and_then(|s| s.to_str()) {
directory_ownership: match path.file_name().and_then(|s| s.to_str()) { // All `#[path]` files are treated as though they are a `mod.rs` file.
// All `#[path]` files are treated as though they are a `mod.rs` file. // This means that `mod foo;` declarations inside `#[path]`-included
// This means that `mod foo;` declarations inside `#[path]`-included // files are siblings,
// files are siblings, //
// // Note that this will produce weirdness when a file named `foo.rs` is
// Note that this will produce weirdness when a file named `foo.rs` is // `#[path]` included and contains a `mod foo;` declaration.
// `#[path]` included and contains a `mod foo;` declaration. // If you encounter this, it's your own darn fault :P
// If you encounter this, it's your own darn fault :P Some(_) => DirectoryOwnership::Owned { relative: None },
Some(_) => DirectoryOwnership::Owned { relative: None }, _ => DirectoryOwnership::UnownedViaMod,
_ => DirectoryOwnership::UnownedViaMod, };
}, return Ok(ModulePathSuccess { directory_ownership, path });
path,
});
} }
let relative = match self.directory.ownership { let relative = match self.directory.ownership {