Skip to content

Commit 8b5dc95

Browse files
committed
Destabilize feature non_modrs_mods
This reverts commit 7f6b608.
1 parent fa20daa commit 8b5dc95

File tree

8 files changed

+185
-3
lines changed

8 files changed

+185
-3
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use visit::{self, FnKind, Visitor};
3737
use parse::ParseSess;
3838
use symbol::{keywords, Symbol};
3939

40-
use std::{env};
40+
use std::{env, path};
4141

4242
macro_rules! set {
4343
// The const_fn feature also enables the min_const_fn feature, because `min_const_fn` allows
@@ -403,6 +403,9 @@ declare_features! (
403403
// `extern` in paths
404404
(active, extern_in_paths, "1.23.0", Some(44660), None),
405405

406+
// `foo.rs` as an alternative to `foo/mod.rs`
407+
(active, non_modrs_mods, "1.24.0", Some(44660), Some(Edition::Edition2018)),
408+
406409
// Use `?` as the Kleene "at most one" operator
407410
(active, macro_at_most_once_rep, "1.25.0", Some(48075), None),
408411

@@ -651,8 +654,6 @@ declare_features! (
651654
(accepted, repr_transparent, "1.28.0", Some(43036), None),
652655
// Defining procedural macros in `proc-macro` crates
653656
(accepted, proc_macro, "1.29.0", Some(38356), None),
654-
// `foo.rs` as an alternative to `foo/mod.rs`
655-
(accepted, non_modrs_mods, "1.30.0", Some(44660), None),
656657
// Allows use of the :vis macro fragment specifier
657658
(accepted, macro_vis_matcher, "1.30.0", Some(41022), None),
658659
// Allows importing and reexporting macros with `use`,
@@ -1500,6 +1501,31 @@ impl<'a> PostExpansionVisitor<'a> {
15001501
}
15011502
}
15021503

1504+
impl<'a> PostExpansionVisitor<'a> {
1505+
fn whole_crate_feature_gates(&mut self, _krate: &ast::Crate) {
1506+
for &(ident, span) in &*self.context.parse_sess.non_modrs_mods.borrow() {
1507+
if !span.allows_unstable() {
1508+
let cx = &self.context;
1509+
let level = GateStrength::Hard;
1510+
let has_feature = cx.features.non_modrs_mods;
1511+
let name = "non_modrs_mods";
1512+
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}",
1513+
name, span, has_feature);
1514+
1515+
if !has_feature && !span.allows_unstable() {
1516+
leveled_feature_err(
1517+
cx.parse_sess, name, span, GateIssue::Language,
1518+
"mod statements in non-mod.rs files are unstable", level
1519+
)
1520+
.help(&format!("on stable builds, rename this file to {}{}mod.rs",
1521+
ident, path::MAIN_SEPARATOR))
1522+
.emit();
1523+
}
1524+
}
1525+
}
1526+
}
1527+
}
1528+
15031529
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
15041530
fn visit_attribute(&mut self, attr: &ast::Attribute) {
15051531
if !attr.span.allows_unstable() {
@@ -2066,6 +2092,7 @@ pub fn check_crate(krate: &ast::Crate,
20662092
};
20672093

20682094
let visitor = &mut PostExpansionVisitor { context: &ctx };
2095+
visitor.whole_crate_feature_gates(krate);
20692096
visit::walk_crate(visitor, krate);
20702097
}
20712098

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern: mod statements in non-mod.rs files are unstable
12+
13+
mod mod_file_not_owning_aux1;
14+
15+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0658]: mod statements in non-mod.rs files are unstable (see issue #44660)
2+
--> $DIR/mod_file_not_owning_aux1.rs:14:17
3+
|
4+
LL | () => { mod mod_file_not_owning_aux2; }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL | }
7+
LL | m!();
8+
| ----- in this macro invocation
9+
|
10+
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
11+
= help: on stable builds, rename this file to mod_file_not_owning_aux1/mod.rs
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern: mod statements in non-mod.rs files are unstable
12+
13+
// This is not a directory owner since the file name is not "mod.rs".
14+
#[path = "mod_file_not_owning_aux1.rs"]
15+
mod foo;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0658]: mod statements in non-mod.rs files are unstable (see issue #44660)
2+
--> $DIR/mod_file_not_owning_aux1.rs:14:17
3+
|
4+
LL | () => { mod mod_file_not_owning_aux2; }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL | }
7+
LL | m!();
8+
| ----- in this macro invocation
9+
|
10+
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
11+
= help: on stable builds, rename this file to foo/mod.rs
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
//
11+
// Tests the formatting of the feature-gate errors for non_modrs_mods
12+
//
13+
// gate-test-non_modrs_mods
14+
// ignore-windows
15+
// ignore-pretty issue #37195
16+
pub mod modrs_mod;
17+
pub mod foors_mod;
18+
19+
#[path = "some_crazy_attr_mod_dir/arbitrary_name.rs"]
20+
pub mod attr_mod;
21+
22+
pub fn main() {
23+
modrs_mod::inner_modrs_mod::innest::foo();
24+
modrs_mod::inner_foors_mod::innest::foo();
25+
foors_mod::inner_modrs_mod::innest::foo();
26+
foors_mod::inner_foors_mod::innest::foo();
27+
attr_mod::inner_modrs_mod::innest::foo();
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0658]: mod statements in non-mod.rs files are unstable (see issue #44660)
2+
--> $DIR/modrs_mod/inner_foors_mod.rs:11:9
3+
|
4+
LL | pub mod innest;
5+
| ^^^^^^
6+
|
7+
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
8+
= help: on stable builds, rename this file to inner_foors_mod/mod.rs
9+
10+
error[E0658]: mod statements in non-mod.rs files are unstable (see issue #44660)
11+
--> $DIR/foors_mod.rs:13:9
12+
|
13+
LL | pub mod inner_modrs_mod;
14+
| ^^^^^^^^^^^^^^^
15+
|
16+
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
17+
= help: on stable builds, rename this file to foors_mod/mod.rs
18+
19+
error[E0658]: mod statements in non-mod.rs files are unstable (see issue #44660)
20+
--> $DIR/foors_mod.rs:14:9
21+
|
22+
LL | pub mod inner_foors_mod;
23+
| ^^^^^^^^^^^^^^^
24+
|
25+
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
26+
= help: on stable builds, rename this file to foors_mod/mod.rs
27+
28+
error[E0658]: mod statements in non-mod.rs files are unstable (see issue #44660)
29+
--> $DIR/foors_mod/inner_foors_mod.rs:11:9
30+
|
31+
LL | pub mod innest;
32+
| ^^^^^^
33+
|
34+
= help: add #![feature(non_modrs_mods)] to the crate attributes to enable
35+
= help: on stable builds, rename this file to inner_foors_mod/mod.rs
36+
37+
error: aborting due to 4 previous errors
38+
39+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// run-pass
12+
//
13+
// ignore-pretty issue #37195
14+
#![feature(non_modrs_mods)]
15+
16+
pub mod modrs_mod;
17+
pub mod foors_mod;
18+
19+
#[path = "some_crazy_attr_mod_dir/arbitrary_name.rs"]
20+
pub mod attr_mod;
21+
22+
pub fn main() {
23+
modrs_mod::inner_modrs_mod::innest::foo();
24+
modrs_mod::inner_foors_mod::innest::foo();
25+
foors_mod::inner_modrs_mod::innest::foo();
26+
foors_mod::inner_foors_mod::innest::foo();
27+
attr_mod::inner_modrs_mod::innest::foo();
28+
}

0 commit comments

Comments
 (0)