Skip to content

Commit 0323654

Browse files
authored
Rollup merge of rust-lang#47298 - cramertj:path-as-modrs, r=nikomatsakis
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
2 parents 55d27c8 + 7b420cf commit 0323654

File tree

7 files changed

+9
-30
lines changed

7 files changed

+9
-30
lines changed

src/libsyntax/parse/parser.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -5894,10 +5894,14 @@ impl<'a> Parser<'a> {
58945894
if let Some(path) = Parser::submod_path_from_attr(outer_attrs, &self.directory.path) {
58955895
return Ok(ModulePathSuccess {
58965896
directory_ownership: match path.file_name().and_then(|s| s.to_str()) {
5897-
Some("mod.rs") => DirectoryOwnership::Owned { relative: None },
5898-
Some(_) => {
5899-
DirectoryOwnership::Owned { relative: Some(id) }
5900-
}
5897+
// All `#[path]` files are treated as though they are a `mod.rs` file.
5898+
// This means that `mod foo;` declarations inside `#[path]`-included
5899+
// files are siblings,
5900+
//
5901+
// Note that this will produce weirdness when a file named `foo.rs` is
5902+
// `#[path]` included and contains a `mod foo;` declaration.
5903+
// If you encounter this, it's your own darn fault :P
5904+
Some(_) => DirectoryOwnership::Owned { relative: None },
59015905
_ => DirectoryOwnership::UnownedViaMod(true),
59025906
},
59035907
path,

src/test/compile-fail/directory_ownership/backcompat-warnings.rs

-16
This file was deleted.

src/test/ui/non_modrs_mods/non_modrs_mods.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,5 @@ error: mod statements in non-mod.rs files are unstable (see issue #44660)
3434
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
3535
= help: on stable builds, rename this file to inner_foors_mod/mod.rs
3636

37-
error: mod statements in non-mod.rs files are unstable (see issue #44660)
38-
--> $DIR/some_crazy_attr_mod_dir/arbitrary_name.rs:11:9
39-
|
40-
11 | pub mod inner_modrs_mod;
41-
| ^^^^^^^^^^^^^^^
42-
|
43-
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
44-
= help: on stable builds, rename this file to attr_mod/mod.rs
45-
46-
error: aborting due to 5 previous errors
37+
error: aborting due to 4 previous errors
4738

0 commit comments

Comments
 (0)