@@ -28,7 +28,7 @@ extern crate syntax_pos;
28
28
29
29
use rustc:: hir:: { self , PatKind } ;
30
30
use rustc:: hir:: def:: Def ;
31
- use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , LOCAL_CRATE , CrateNum , DefId } ;
31
+ use rustc:: hir:: def_id:: { LOCAL_CRATE , CrateNum , DefId } ;
32
32
use rustc:: hir:: intravisit:: { self , Visitor , NestedVisitorMap } ;
33
33
use rustc:: hir:: itemlikevisit:: DeepVisitor ;
34
34
use rustc:: lint;
@@ -37,7 +37,8 @@ use rustc::ty::{self, TyCtxt, Ty, TypeFoldable};
37
37
use rustc:: ty:: fold:: TypeVisitor ;
38
38
use rustc:: ty:: maps:: Providers ;
39
39
use rustc:: util:: nodemap:: NodeSet ;
40
- use syntax:: ast;
40
+ use syntax:: ast:: { self , CRATE_NODE_ID , Ident } ;
41
+ use syntax:: symbol:: keywords;
41
42
use syntax_pos:: Span ;
42
43
43
44
use std:: cmp;
@@ -344,7 +345,35 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
344
345
}
345
346
346
347
fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef ) {
347
- self . update ( md. id , Some ( AccessLevel :: Public ) ) ;
348
+ if md. legacy {
349
+ self . update ( md. id , Some ( AccessLevel :: Public ) ) ;
350
+ return
351
+ }
352
+
353
+ let module_did = ty:: DefIdTree :: parent ( self . tcx , self . tcx . hir . local_def_id ( md. id ) ) . unwrap ( ) ;
354
+ let mut module_id = self . tcx . hir . as_local_node_id ( module_did) . unwrap ( ) ;
355
+ let level = if md. vis == hir:: Public { self . get ( module_id) } else { None } ;
356
+ let level = self . update ( md. id , level) ;
357
+ if level. is_none ( ) {
358
+ return
359
+ }
360
+
361
+ loop {
362
+ let module = if module_id == ast:: CRATE_NODE_ID {
363
+ & self . tcx . hir . krate ( ) . module
364
+ } else if let hir:: ItemMod ( ref module) = self . tcx . hir . expect_item ( module_id) . node {
365
+ module
366
+ } else {
367
+ unreachable ! ( )
368
+ } ;
369
+ for id in & module. item_ids {
370
+ self . update ( id. id , level) ;
371
+ }
372
+ if module_id == ast:: CRATE_NODE_ID {
373
+ break
374
+ }
375
+ module_id = self . tcx . hir . get_parent_node ( module_id) ;
376
+ }
348
377
}
349
378
350
379
fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty ) {
@@ -425,13 +454,15 @@ impl<'b, 'a, 'tcx> TypeVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'b
425
454
struct NamePrivacyVisitor < ' a , ' tcx : ' a > {
426
455
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
427
456
tables : & ' a ty:: TypeckTables < ' tcx > ,
428
- current_item : DefId ,
457
+ current_item : ast :: NodeId ,
429
458
}
430
459
431
460
impl < ' a , ' tcx > NamePrivacyVisitor < ' a , ' tcx > {
432
461
// Checks that a field is accessible.
433
462
fn check_field ( & mut self , span : Span , def : & ' tcx ty:: AdtDef , field : & ' tcx ty:: FieldDef ) {
434
- if !def. is_enum ( ) && !field. vis . is_accessible_from ( self . current_item , self . tcx ) {
463
+ let ident = Ident { ctxt : span. ctxt . modern ( ) , ..keywords:: Invalid . ident ( ) } ;
464
+ let def_id = self . tcx . adjust_ident ( ident, def. did , self . current_item ) . 1 ;
465
+ if !def. is_enum ( ) && !field. vis . is_accessible_from ( def_id, self . tcx ) {
435
466
struct_span_err ! ( self . tcx. sess, span, E0451 , "field `{}` of {} `{}` is private" ,
436
467
field. name, def. variant_descr( ) , self . tcx. item_path_str( def. did) )
437
468
. span_label ( span, format ! ( "field `{}` is private" , field. name) )
@@ -455,7 +486,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
455
486
}
456
487
457
488
fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
458
- let orig_current_item = replace ( & mut self . current_item , self . tcx . hir . local_def_id ( item. id ) ) ;
489
+ let orig_current_item = replace ( & mut self . current_item , item. id ) ;
459
490
intravisit:: walk_item ( self , item) ;
460
491
self . current_item = orig_current_item;
461
492
}
@@ -1182,7 +1213,7 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1182
1213
let mut visitor = NamePrivacyVisitor {
1183
1214
tcx : tcx,
1184
1215
tables : & ty:: TypeckTables :: empty ( ) ,
1185
- current_item : DefId :: local ( CRATE_DEF_INDEX ) ,
1216
+ current_item : CRATE_NODE_ID ,
1186
1217
} ;
1187
1218
intravisit:: walk_crate ( & mut visitor, krate) ;
1188
1219
0 commit comments