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
This commit is contained in:
commit
e40a6fb133
7 changed files with 9 additions and 30 deletions
|
@ -5894,10 +5894,14 @@ impl<'a> Parser<'a> {
|
||||||
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 {
|
return Ok(ModulePathSuccess {
|
||||||
directory_ownership: match path.file_name().and_then(|s| s.to_str()) {
|
directory_ownership: match path.file_name().and_then(|s| s.to_str()) {
|
||||||
Some("mod.rs") => DirectoryOwnership::Owned { relative: None },
|
// All `#[path]` files are treated as though they are a `mod.rs` file.
|
||||||
Some(_) => {
|
// This means that `mod foo;` declarations inside `#[path]`-included
|
||||||
DirectoryOwnership::Owned { relative: Some(id) }
|
// 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),
|
_ => DirectoryOwnership::UnownedViaMod(true),
|
||||||
},
|
},
|
||||||
path,
|
path,
|
||||||
|
|
|
@ -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 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
|
|
|
@ -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: add #![feature(non_modrs_mods)] to the crate attributes to enable
|
||||||
= help: on stable builds, rename this file to inner_foors_mod/mod.rs
|
= 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)
|
error: aborting due to 4 previous errors
|
||||||
--> $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
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue