@@ -38,7 +38,7 @@ use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds};
3838use ast:: { ViewPath , ViewPathGlob , ViewPathList , ViewPathSimple } ;
3939use ast:: { Visibility , WhereClause } ;
4040use ast:: { BinOpKind , UnOp } ;
41- use ast;
41+ use { ast, attr } ;
4242use codemap:: { self , CodeMap , Spanned , spanned, respan} ;
4343use syntax_pos:: { self , Span , BytePos , mk_sp} ;
4444use errors:: { self , DiagnosticBuilder } ;
@@ -243,6 +243,7 @@ pub struct ModulePath {
243243pub struct ModulePathSuccess {
244244 pub path : PathBuf ,
245245 pub directory_ownership : DirectoryOwnership ,
246+ warn : bool ,
246247}
247248
248249pub struct ModulePathError {
@@ -5268,10 +5269,25 @@ impl<'a> Parser<'a> {
52685269 self . bump ( ) ;
52695270 if in_cfg {
52705271 // 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 } =
52725273 self . submod_path ( id, & outer_attrs, id_span) ?;
5273- let ( module, attrs) =
5274+ let ( module, mut attrs) =
52745275 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+ }
52755291 Ok ( ( id, module, Some ( attrs) ) )
52765292 } else {
52775293 let placeholder = ast:: Mod { inner : syntax_pos:: DUMMY_SP , items : Vec :: new ( ) } ;
@@ -5290,7 +5306,7 @@ impl<'a> Parser<'a> {
52905306 }
52915307
52925308 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" ) {
52945310 self . directory . path . push ( & * path. as_str ( ) ) ;
52955311 self . directory . ownership = DirectoryOwnership :: Owned ;
52965312 } else {
@@ -5299,7 +5315,7 @@ impl<'a> Parser<'a> {
52995315 }
53005316
53015317 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 ( ) ) )
53035319 }
53045320
53055321 /// Returns either a path to a module, or .
@@ -5316,11 +5332,13 @@ impl<'a> Parser<'a> {
53165332 let result = match ( default_exists, secondary_exists) {
53175333 ( true , false ) => Ok ( ModulePathSuccess {
53185334 path : default_path,
5319- directory_ownership : DirectoryOwnership :: UnownedViaMod ,
5335+ directory_ownership : DirectoryOwnership :: UnownedViaMod ( false ) ,
5336+ warn : false ,
53205337 } ) ,
53215338 ( false , true ) => Ok ( ModulePathSuccess {
53225339 path : secondary_path,
53235340 directory_ownership : DirectoryOwnership :: Owned ,
5341+ warn : false ,
53245342 } ) ,
53255343 ( false , false ) => Err ( ModulePathError {
53265344 err_msg : format ! ( "file not found for module `{}`" , mod_name) ,
@@ -5353,9 +5371,10 @@ impl<'a> Parser<'a> {
53535371 return Ok ( ModulePathSuccess {
53545372 directory_ownership : match path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
53555373 Some ( "mod.rs" ) => DirectoryOwnership :: Owned ,
5356- _ => DirectoryOwnership :: UnownedViaMod ,
5374+ _ => DirectoryOwnership :: UnownedViaMod ( true ) ,
53575375 } ,
53585376 path : path,
5377+ warn : false ,
53595378 } ) ;
53605379 }
53615380
@@ -5371,7 +5390,12 @@ impl<'a> Parser<'a> {
53715390 err. span_note ( id_sp, & msg) ;
53725391 }
53735392 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+ }
53755399 let mut err = self . diagnostic ( ) . struct_span_err ( id_sp,
53765400 "cannot declare a new module at this location" ) ;
53775401 let this_module = match self . directory . path . file_name ( ) {
@@ -5387,8 +5411,10 @@ impl<'a> Parser<'a> {
53875411 & format ! ( "... or maybe `use` the module `{}` instead \
53885412 of possibly redeclaring it",
53895413 paths. name) ) ;
5390- }
5391- return Err ( err) ;
5414+ return Err ( err) ;
5415+ } else {
5416+ return Err ( err) ;
5417+ } ;
53925418 }
53935419
53945420 match paths. result {
0 commit comments