Skip to content

Commit

Permalink
Rollup merge of rust-lang#47298 - cramertj:path-as-modrs, r=nikomatsakis
Browse files Browse the repository at this point in the history
Treat #[path] files as mod.rs files

Fixes rust-lang#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 rust-lang#37872

r? @jseyfried
  • Loading branch information
kennytm authored Jan 12, 2018
2 parents 8aab0cc + 7b420cf commit e40a6fb
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 30 deletions.
12 changes: 8 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 0 additions & 16 deletions src/test/compile-fail/directory_ownership/backcompat-warnings.rs

This file was deleted.

11 changes: 1 addition & 10 deletions src/test/ui/non_modrs_mods/non_modrs_mods.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,5 @@ error: mod statements in non-mod.rs files are unstable (see issue #44660)
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
= help: on stable builds, rename this file to inner_foors_mod/mod.rs

error: mod statements in non-mod.rs files are unstable (see issue #44660)
--> $DIR/some_crazy_attr_mod_dir/arbitrary_name.rs:11:9
|
11 | pub mod inner_modrs_mod;
| ^^^^^^^^^^^^^^^
|
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
= help: on stable builds, rename this file to attr_mod/mod.rs

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

0 comments on commit e40a6fb

Please sign in to comment.