@@ -37,7 +37,7 @@ use visit::{self, FnKind, Visitor};
3737use parse:: ParseSess ;
3838use symbol:: { keywords, Symbol } ;
3939
40- use std:: { env} ;
40+ use std:: { env, path } ;
4141
4242macro_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+
15031529impl < ' 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
0 commit comments