1
1
use rustc:: middle:: privacy:: { AccessLevels , AccessLevel } ;
2
2
use rustc:: hir:: def:: { Res , DefKind } ;
3
3
use rustc:: hir:: def_id:: { CrateNum , CRATE_DEF_INDEX , DefId } ;
4
- use rustc:: ty:: Visibility ;
4
+ use rustc:: ty:: { TyCtxt , Visibility } ;
5
5
use rustc:: util:: nodemap:: FxHashSet ;
6
6
use syntax:: symbol:: sym;
7
7
8
- use std:: cell:: RefMut ;
9
-
10
8
use crate :: clean:: { AttributesExt , NestedAttributesExt } ;
11
9
12
10
// FIXME: this may not be exhaustive, but is sufficient for rustdocs current uses
13
11
14
12
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
15
13
/// specific rustdoc annotations into account (i.e., `doc(hidden)`)
16
14
pub struct LibEmbargoVisitor < ' a , ' tcx > {
17
- cx : & ' a crate :: core :: DocContext < ' tcx > ,
15
+ tcx : TyCtxt < ' tcx > ,
18
16
// Accessibility levels for reachable nodes
19
- access_levels : RefMut < ' a , AccessLevels < DefId > > ,
17
+ access_levels : & ' a mut AccessLevels < DefId > ,
20
18
// Previous accessibility level, None means unreachable
21
19
prev_level : Option < AccessLevel > ,
22
20
// Keeps track of already visited modules, in case a module re-exports its parent
@@ -25,13 +23,13 @@ pub struct LibEmbargoVisitor<'a, 'tcx> {
25
23
26
24
impl < ' a , ' tcx > LibEmbargoVisitor < ' a , ' tcx > {
27
25
pub fn new (
28
- cx : & ' a crate :: core:: DocContext < ' tcx >
26
+ cx : & ' a mut crate :: core:: DocContext < ' tcx >
29
27
) -> LibEmbargoVisitor < ' a , ' tcx > {
30
28
LibEmbargoVisitor {
31
- cx ,
32
- access_levels : RefMut :: map ( cx. renderinfo . borrow_mut ( ) , |ri| & mut ri . access_levels ) ,
29
+ tcx : cx . tcx ,
30
+ access_levels : & mut cx. renderinfo . get_mut ( ) . access_levels ,
33
31
prev_level : Some ( AccessLevel :: Public ) ,
34
- visited_mods : FxHashSet :: default ( )
32
+ visited_mods : FxHashSet :: default ( ) ,
35
33
}
36
34
}
37
35
@@ -43,7 +41,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
43
41
44
42
// Updates node level and returns the updated level
45
43
fn update ( & mut self , did : DefId , level : Option < AccessLevel > ) -> Option < AccessLevel > {
46
- let is_hidden = self . cx . tcx . get_attrs ( did) . lists ( sym:: doc) . has_word ( sym:: hidden) ;
44
+ let is_hidden = self . tcx . get_attrs ( did) . lists ( sym:: doc) . has_word ( sym:: hidden) ;
47
45
48
46
let old_level = self . access_levels . map . get ( & did) . cloned ( ) ;
49
47
// Accessibility levels can only grow
@@ -60,9 +58,9 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
60
58
return ;
61
59
}
62
60
63
- for item in self . cx . tcx . item_children ( def_id) . iter ( ) {
61
+ for item in self . tcx . item_children ( def_id) . iter ( ) {
64
62
if let Some ( def_id) = item. res . opt_def_id ( ) {
65
- if self . cx . tcx . def_key ( def_id) . parent . map_or ( false , |d| d == def_id. index ) ||
63
+ if self . tcx . def_key ( def_id) . parent . map_or ( false , |d| d == def_id. index ) ||
66
64
item. vis == Visibility :: Public {
67
65
self . visit_item ( item. res ) ;
68
66
}
@@ -72,7 +70,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
72
70
73
71
fn visit_item ( & mut self , res : Res ) {
74
72
let def_id = res. def_id ( ) ;
75
- let vis = self . cx . tcx . visibility ( def_id) ;
73
+ let vis = self . tcx . visibility ( def_id) ;
76
74
let inherited_item_level = if vis == Visibility :: Public {
77
75
self . prev_level
78
76
} else {
0 commit comments