@@ -73,6 +73,7 @@ bitflags! {
73
73
flags Restrictions : u8 {
74
74
const RESTRICTION_STMT_EXPR = 1 << 0 ,
75
75
const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1 ,
76
+ const NO_NONINLINE_MOD = 1 << 2 ,
76
77
}
77
78
}
78
79
@@ -3208,8 +3209,8 @@ impl<'a> Parser<'a> {
3208
3209
/// Evaluate the closure with restrictions in place.
3209
3210
///
3210
3211
/// 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
3213
3214
{
3214
3215
let old = self . restrictions ;
3215
3216
self . restrictions = r;
@@ -3767,7 +3768,9 @@ impl<'a> Parser<'a> {
3767
3768
}
3768
3769
} else {
3769
3770
// 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 ) ) ) {
3771
3774
Some ( i) => {
3772
3775
let hi = i. span . hi ;
3773
3776
let decl = P ( spanned ( lo, hi, DeclKind :: Item ( i) ) ) ;
@@ -5174,7 +5177,17 @@ impl<'a> Parser<'a> {
5174
5177
5175
5178
let paths = Parser :: default_submod_path ( id, & dir_path, self . sess . codemap ( ) ) ;
5176
5179
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 {
5178
5191
let mut err = self . diagnostic ( ) . struct_span_err ( id_sp,
5179
5192
"cannot declare a new module at this location" ) ;
5180
5193
let this_module = match self . mod_path_stack . last ( ) {
0 commit comments