@@ -38,7 +38,7 @@ use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds};
38
38
use ast:: { ViewPath , ViewPathGlob , ViewPathList , ViewPathSimple } ;
39
39
use ast:: { Visibility , WhereClause } ;
40
40
use ast:: { BinOpKind , UnOp } ;
41
- use ast;
41
+ use { ast, attr } ;
42
42
use codemap:: { self , CodeMap , Spanned , spanned, respan} ;
43
43
use syntax_pos:: { self , Span , BytePos , mk_sp} ;
44
44
use errors:: { self , DiagnosticBuilder } ;
@@ -243,6 +243,7 @@ pub struct ModulePath {
243
243
pub struct ModulePathSuccess {
244
244
pub path : PathBuf ,
245
245
pub directory_ownership : DirectoryOwnership ,
246
+ warn : bool ,
246
247
}
247
248
248
249
pub struct ModulePathError {
@@ -5268,10 +5269,25 @@ impl<'a> Parser<'a> {
5268
5269
self . bump ( ) ;
5269
5270
if in_cfg {
5270
5271
// This mod is in an external file. Let's go get it!
5271
- let ModulePathSuccess { path, directory_ownership } =
5272
+ let ModulePathSuccess { path, directory_ownership, warn } =
5272
5273
self . submod_path ( id, & outer_attrs, id_span) ?;
5273
- let ( module, attrs) =
5274
+ let ( module, mut attrs) =
5274
5275
self . eval_src_mod ( path, directory_ownership, id. to_string ( ) , id_span) ?;
5276
+ if warn {
5277
+ let attr = ast:: Attribute {
5278
+ id : attr:: mk_attr_id ( ) ,
5279
+ style : ast:: AttrStyle :: Outer ,
5280
+ value : ast:: MetaItem {
5281
+ name : Symbol :: intern ( "warn_directory_ownership" ) ,
5282
+ node : ast:: MetaItemKind :: Word ,
5283
+ span : syntax_pos:: DUMMY_SP ,
5284
+ } ,
5285
+ is_sugared_doc : false ,
5286
+ span : syntax_pos:: DUMMY_SP ,
5287
+ } ;
5288
+ attr:: mark_known ( & attr) ;
5289
+ attrs. push ( attr) ;
5290
+ }
5275
5291
Ok ( ( id, module, Some ( attrs) ) )
5276
5292
} else {
5277
5293
let placeholder = ast:: Mod { inner : syntax_pos:: DUMMY_SP , items : Vec :: new ( ) } ;
@@ -5290,7 +5306,7 @@ impl<'a> Parser<'a> {
5290
5306
}
5291
5307
5292
5308
fn push_directory ( & mut self , id : Ident , attrs : & [ Attribute ] ) {
5293
- if let Some ( path) = :: attr:: first_attr_value_str_by_name ( attrs, "path" ) {
5309
+ if let Some ( path) = attr:: first_attr_value_str_by_name ( attrs, "path" ) {
5294
5310
self . directory . path . push ( & * path. as_str ( ) ) ;
5295
5311
self . directory . ownership = DirectoryOwnership :: Owned ;
5296
5312
} else {
@@ -5299,7 +5315,7 @@ impl<'a> Parser<'a> {
5299
5315
}
5300
5316
5301
5317
pub fn submod_path_from_attr ( attrs : & [ ast:: Attribute ] , dir_path : & Path ) -> Option < PathBuf > {
5302
- :: attr:: first_attr_value_str_by_name ( attrs, "path" ) . map ( |d| dir_path. join ( & * d. as_str ( ) ) )
5318
+ attr:: first_attr_value_str_by_name ( attrs, "path" ) . map ( |d| dir_path. join ( & * d. as_str ( ) ) )
5303
5319
}
5304
5320
5305
5321
/// Returns either a path to a module, or .
@@ -5316,11 +5332,13 @@ impl<'a> Parser<'a> {
5316
5332
let result = match ( default_exists, secondary_exists) {
5317
5333
( true , false ) => Ok ( ModulePathSuccess {
5318
5334
path : default_path,
5319
- directory_ownership : DirectoryOwnership :: UnownedViaMod ,
5335
+ directory_ownership : DirectoryOwnership :: UnownedViaMod ( false ) ,
5336
+ warn : false ,
5320
5337
} ) ,
5321
5338
( false , true ) => Ok ( ModulePathSuccess {
5322
5339
path : secondary_path,
5323
5340
directory_ownership : DirectoryOwnership :: Owned ,
5341
+ warn : false ,
5324
5342
} ) ,
5325
5343
( false , false ) => Err ( ModulePathError {
5326
5344
err_msg : format ! ( "file not found for module `{}`" , mod_name) ,
@@ -5353,9 +5371,10 @@ impl<'a> Parser<'a> {
5353
5371
return Ok ( ModulePathSuccess {
5354
5372
directory_ownership : match path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
5355
5373
Some ( "mod.rs" ) => DirectoryOwnership :: Owned ,
5356
- _ => DirectoryOwnership :: UnownedViaMod ,
5374
+ _ => DirectoryOwnership :: UnownedViaMod ( true ) ,
5357
5375
} ,
5358
5376
path : path,
5377
+ warn : false ,
5359
5378
} ) ;
5360
5379
}
5361
5380
@@ -5371,7 +5390,12 @@ impl<'a> Parser<'a> {
5371
5390
err. span_note ( id_sp, & msg) ;
5372
5391
}
5373
5392
return Err ( err) ;
5374
- } else if let DirectoryOwnership :: UnownedViaMod = self . directory . ownership {
5393
+ } else if let DirectoryOwnership :: UnownedViaMod ( warn) = self . directory . ownership {
5394
+ if warn {
5395
+ if let Ok ( result) = paths. result {
5396
+ return Ok ( ModulePathSuccess { warn : true , ..result } ) ;
5397
+ }
5398
+ }
5375
5399
let mut err = self . diagnostic ( ) . struct_span_err ( id_sp,
5376
5400
"cannot declare a new module at this location" ) ;
5377
5401
let this_module = match self . directory . path . file_name ( ) {
@@ -5387,8 +5411,10 @@ impl<'a> Parser<'a> {
5387
5411
& format ! ( "... or maybe `use` the module `{}` instead \
5388
5412
of possibly redeclaring it",
5389
5413
paths. name) ) ;
5390
- }
5391
- return Err ( err) ;
5414
+ return Err ( err) ;
5415
+ } else {
5416
+ return Err ( err) ;
5417
+ } ;
5392
5418
}
5393
5419
5394
5420
match paths. result {
0 commit comments