From 7b420cf3da1e5ff7675923cc25a2d39715d300b6 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 9 Jan 2018 10:54:13 -0800 Subject: [PATCH] Treat #[path] files as mod.rs files --- src/libsyntax/parse/parser.rs | 12 ++++++++---- .../directory_ownership/backcompat-warnings.rs | 16 ---------------- .../{attr_mod => }/inner_modrs_mod/innest.rs | 0 .../{attr_mod => }/inner_modrs_mod/mod.rs | 0 src/test/ui/non_modrs_mods/non_modrs_mods.stderr | 11 +---------- .../{attr_mod => }/inner_modrs_mod/innest.rs | 0 .../{attr_mod => }/inner_modrs_mod/mod.rs | 0 7 files changed, 9 insertions(+), 30 deletions(-) delete mode 100644 src/test/compile-fail/directory_ownership/backcompat-warnings.rs rename src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/{attr_mod => }/inner_modrs_mod/innest.rs (100%) rename src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/{attr_mod => }/inner_modrs_mod/mod.rs (100%) rename src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/{attr_mod => }/inner_modrs_mod/innest.rs (100%) rename src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/{attr_mod => }/inner_modrs_mod/mod.rs (100%) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 812e3c4967a..0d517a221da 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5876,10 +5876,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, diff --git a/src/test/compile-fail/directory_ownership/backcompat-warnings.rs b/src/test/compile-fail/directory_ownership/backcompat-warnings.rs deleted file mode 100644 index 2da07a2cc72..00000000000 --- a/src/test/compile-fail/directory_ownership/backcompat-warnings.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern: mod statements in non-mod.rs files are unstable - -#[path="mod_file_not_owning_aux3.rs"] -mod foo; - -fn main() {} diff --git a/src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/innest.rs b/src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/innest.rs similarity index 100% rename from src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/innest.rs rename to src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/innest.rs diff --git a/src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/mod.rs b/src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/mod.rs similarity index 100% rename from src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/mod.rs rename to src/test/run-pass/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/mod.rs diff --git a/src/test/ui/non_modrs_mods/non_modrs_mods.stderr b/src/test/ui/non_modrs_mods/non_modrs_mods.stderr index b4b524786cd..95a2539ed64 100644 --- a/src/test/ui/non_modrs_mods/non_modrs_mods.stderr +++ b/src/test/ui/non_modrs_mods/non_modrs_mods.stderr @@ -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 diff --git a/src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/innest.rs b/src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/innest.rs similarity index 100% rename from src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/innest.rs rename to src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/innest.rs diff --git a/src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/mod.rs b/src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/mod.rs similarity index 100% rename from src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/attr_mod/inner_modrs_mod/mod.rs rename to src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/mod.rs