@@ -73,6 +73,7 @@ bitflags! {
7373 flags Restrictions : u8 {
7474 const RESTRICTION_STMT_EXPR = 1 << 0 ,
7575 const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1 ,
76+ const NO_NONINLINE_MOD = 1 << 2 ,
7677 }
7778}
7879
@@ -3208,8 +3209,8 @@ impl<'a> Parser<'a> {
32083209 /// Evaluate the closure with restrictions in place.
32093210 ///
32103211 /// After the closure is evaluated, restrictions are reset.
3211- pub fn with_res < F > ( & mut self , r : Restrictions , f : F ) -> PResult < ' a , P < Expr > >
3212- where F : FnOnce ( & mut Self ) -> PResult < ' a , P < Expr > >
3212+ pub fn with_res < F , T > ( & mut self , r : Restrictions , f : F ) -> T
3213+ where F : FnOnce ( & mut Self ) -> T
32133214 {
32143215 let old = self . restrictions ;
32153216 self . restrictions = r;
@@ -3767,7 +3768,9 @@ impl<'a> Parser<'a> {
37673768 }
37683769 } else {
37693770 // FIXME: Bad copy of attrs
3770- match try!( self . parse_item_ ( attrs. clone ( ) , false , true ) ) {
3771+ let restrictions = self . restrictions | Restrictions :: NO_NONINLINE_MOD ;
3772+ match try!( self . with_res ( restrictions,
3773+ |this| this. parse_item_ ( attrs. clone ( ) , false , true ) ) ) {
37713774 Some ( i) => {
37723775 let hi = i. span . hi ;
37733776 let decl = P ( spanned ( lo, hi, DeclKind :: Item ( i) ) ) ;
@@ -5174,7 +5177,17 @@ impl<'a> Parser<'a> {
51745177
51755178 let paths = Parser :: default_submod_path ( id, & dir_path, self . sess . codemap ( ) ) ;
51765179
5177- if !self . owns_directory {
5180+ if self . restrictions . contains ( Restrictions :: NO_NONINLINE_MOD ) {
5181+ let msg =
5182+ "Cannot declare a non-inline module inside a block unless it has a path attribute" ;
5183+ let mut err = self . diagnostic ( ) . struct_span_err ( id_sp, msg) ;
5184+ if paths. path_exists {
5185+ let msg = format ! ( "Maybe `use` the module `{}` instead of redeclaring it" ,
5186+ paths. name) ;
5187+ err. span_note ( id_sp, & msg) ;
5188+ }
5189+ return Err ( err) ;
5190+ } else if !self . owns_directory {
51785191 let mut err = self . diagnostic ( ) . struct_span_err ( id_sp,
51795192 "cannot declare a new module at this location" ) ;
51805193 let this_module = match self . mod_path_stack . last ( ) {
0 commit comments