diff options
| author | kennytm <kennytm@gmail.com> | 2018-01-13 02:26:30 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-13 02:26:30 +0800 |
| commit | e40a6fb1336bb2025b2ef348c7caf4b4f39d90cd (patch) | |
| tree | f3b9db2afc2275dae287b0b0fa27dfe4d093b22b /src/libsyntax/parse/parser.rs | |
| parent | 8aab0cc861e48590964a88fa06e1d7c6d29ecbf3 (diff) | |
| parent | 7b420cf3da1e5ff7675923cc25a2d39715d300b6 (diff) | |
| download | rust-e40a6fb1336bb2025b2ef348c7caf4b4f39d90cd.tar.gz rust-e40a6fb1336bb2025b2ef348c7caf4b4f39d90cd.zip | |
Rollup merge of #47298 - cramertj:path-as-modrs, r=nikomatsakis
Treat #[path] files as mod.rs files Fixes https://github.com/rust-lang/rust/issues/46936, cc @briansmith, @SergioBenitez, @nikomatsakis. This (insta-stable) change treats files included via `#[path = "bla.rs"] mod foo;` as though they were `mod.rs` files. Namely, it allows them to include `mod` statements and looks for the child modules in sibling directories, rather than in relative `modname/childmodule.rs` files as happens for non-`mod.rs` files. This change makes the `non_modrs_mods` feature backwards compatible with the existing usage in https://github.com/briansmith/ring, several versions of which are currently broken in beta. If we decide to merge, this change should be backported to beta. cc https://github.com/rust-lang/rust/issues/37872 r? @jseyfried
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b61c39d589b..49035203150 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5894,10 +5894,14 @@ impl<'a> Parser<'a> { if let Some(path) = Parser::submod_path_from_attr(outer_attrs, &self.directory.path) { return Ok(ModulePathSuccess { directory_ownership: match path.file_name().and_then(|s| s.to_str()) { - Some("mod.rs") => DirectoryOwnership::Owned { relative: None }, - Some(_) => { - DirectoryOwnership::Owned { relative: Some(id) } - } + // All `#[path]` files are treated as though they are a `mod.rs` file. + // This means that `mod foo;` declarations inside `#[path]`-included + // files are siblings, + // + // Note that this will produce weirdness when a file named `foo.rs` is + // `#[path]` included and contains a `mod foo;` declaration. + // If you encounter this, it's your own darn fault :P + Some(_) => DirectoryOwnership::Owned { relative: None }, _ => DirectoryOwnership::UnownedViaMod(true), }, path, |
