@@ -72,6 +72,7 @@ bitflags! {
72
72
flags Restrictions : u8 {
73
73
const RESTRICTION_STMT_EXPR = 1 << 0 ,
74
74
const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1 ,
75
+ const NO_NONINLINE_MOD = 1 << 2 ,
75
76
}
76
77
}
77
78
@@ -3301,8 +3302,8 @@ impl<'a> Parser<'a> {
3301
3302
/// Evaluate the closure with restrictions in place.
3302
3303
///
3303
3304
/// After the closure is evaluated, restrictions are reset.
3304
- pub fn with_res < F > ( & mut self , r : Restrictions , f : F ) -> PResult < ' a , P < Expr > >
3305
- where F : FnOnce ( & mut Self ) -> PResult < ' a , P < Expr > >
3305
+ pub fn with_res < F , T > ( & mut self , r : Restrictions , f : F ) -> T
3306
+ where F : FnOnce ( & mut Self ) -> T
3306
3307
{
3307
3308
let old = self . restrictions ;
3308
3309
self . restrictions = r;
@@ -3926,7 +3927,9 @@ impl<'a> Parser<'a> {
3926
3927
}
3927
3928
} else {
3928
3929
// FIXME: Bad copy of attrs
3929
- match try!( self . parse_item_ ( attrs. clone ( ) , false , true ) ) {
3930
+ let restrictions = self . restrictions | Restrictions :: NO_NONINLINE_MOD ;
3931
+ match try!( self . with_res ( restrictions,
3932
+ |this| this. parse_item_ ( attrs. clone ( ) , false , true ) ) ) {
3930
3933
Some ( i) => {
3931
3934
let hi = i. span . hi ;
3932
3935
let decl = P ( spanned ( lo, hi, DeclKind :: Item ( i) ) ) ;
@@ -5257,11 +5260,8 @@ impl<'a> Parser<'a> {
5257
5260
self . push_mod_path ( id, outer_attrs) ;
5258
5261
try!( self . expect ( & token:: OpenDelim ( token:: Brace ) ) ) ;
5259
5262
let mod_inner_lo = self . span . lo ;
5260
- let old_owns_directory = self . owns_directory ;
5261
- self . owns_directory = true ;
5262
5263
let attrs = try!( self . parse_inner_attributes ( ) ) ;
5263
5264
let m = try!( self . parse_mod_items ( & token:: CloseDelim ( token:: Brace ) , mod_inner_lo) ) ;
5264
- self . owns_directory = old_owns_directory;
5265
5265
self . pop_mod_path ( ) ;
5266
5266
Ok ( ( id, ItemKind :: Mod ( m) , Some ( attrs) ) )
5267
5267
}
@@ -5338,7 +5338,17 @@ impl<'a> Parser<'a> {
5338
5338
5339
5339
let paths = Parser :: default_submod_path ( id, & dir_path, self . sess . codemap ( ) ) ;
5340
5340
5341
- if !self . owns_directory {
5341
+ if self . restrictions . contains ( Restrictions :: NO_NONINLINE_MOD ) {
5342
+ let msg =
5343
+ "Cannot declare a non-inline module inside a block unless it has a path attribute" ;
5344
+ let mut err = self . diagnostic ( ) . struct_span_err ( id_sp, msg) ;
5345
+ if paths. path_exists {
5346
+ let msg = format ! ( "Maybe `use` the module `{}` instead of redeclaring it" ,
5347
+ paths. name) ;
5348
+ err. span_note ( id_sp, & msg) ;
5349
+ }
5350
+ return Err ( err) ;
5351
+ } else if !self . owns_directory {
5342
5352
let mut err = self . diagnostic ( ) . struct_span_err ( id_sp,
5343
5353
"cannot declare a new module at this location" ) ;
5344
5354
let this_module = match self . mod_path_stack . last ( ) {
0 commit comments