@@ -117,6 +117,7 @@ pub struct Crate {
117
117
// These are later on moved into `CACHEKEY`, leaving the map empty.
118
118
// Only here so that they can be filtered through the rustdoc passes.
119
119
pub external_traits : FxHashMap < DefId , Trait > ,
120
+ pub masked_crates : FxHashSet < CrateNum > ,
120
121
}
121
122
122
123
impl < ' a , ' tcx > Clean < Crate > for visit_ast:: RustdocVisitor < ' a , ' tcx > {
@@ -141,6 +142,18 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
141
142
// Clean the crate, translating the entire libsyntax AST to one that is
142
143
// understood by rustdoc.
143
144
let mut module = self . module . clean ( cx) ;
145
+ let mut masked_crates = FxHashSet ( ) ;
146
+
147
+ match module. inner {
148
+ ModuleItem ( ref module) => {
149
+ for it in & module. items {
150
+ if it. is_extern_crate ( ) && it. attrs . has_doc_masked ( ) {
151
+ masked_crates. insert ( it. def_id . krate ) ;
152
+ }
153
+ }
154
+ }
155
+ _ => unreachable ! ( ) ,
156
+ }
144
157
145
158
let ExternalCrate { name, src, primitives, .. } = LOCAL_CRATE . clean ( cx) ;
146
159
{
@@ -173,6 +186,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
173
186
primitives,
174
187
access_levels : Arc :: new ( mem:: replace ( & mut access_levels, Default :: default ( ) ) ) ,
175
188
external_traits : mem:: replace ( & mut external_traits, Default :: default ( ) ) ,
189
+ masked_crates,
176
190
}
177
191
}
178
192
}
@@ -326,6 +340,9 @@ impl Item {
326
340
pub fn is_import ( & self ) -> bool {
327
341
self . type_ ( ) == ItemType :: Import
328
342
}
343
+ pub fn is_extern_crate ( & self ) -> bool {
344
+ self . type_ ( ) == ItemType :: ExternCrate
345
+ }
329
346
330
347
pub fn is_stripped ( & self ) -> bool {
331
348
match self . inner { StrippedItem ( ..) => true , _ => false }
@@ -571,6 +588,20 @@ impl Attributes {
571
588
None
572
589
}
573
590
591
+ pub fn has_doc_masked ( & self ) -> bool {
592
+ for attr in & self . other_attrs {
593
+ if !attr. check_name ( "doc" ) { continue ; }
594
+
595
+ if let Some ( items) = attr. meta_item_list ( ) {
596
+ if items. iter ( ) . filter_map ( |i| i. meta_item ( ) ) . any ( |it| it. check_name ( "masked" ) ) {
597
+ return true ;
598
+ }
599
+ }
600
+ }
601
+
602
+ false
603
+ }
604
+
574
605
pub fn from_ast ( diagnostic : & :: errors:: Handler , attrs : & [ ast:: Attribute ] ) -> Attributes {
575
606
let mut doc_strings = vec ! [ ] ;
576
607
let mut sp = None ;
@@ -1651,6 +1682,16 @@ impl GetDefId for Type {
1651
1682
fn def_id ( & self ) -> Option < DefId > {
1652
1683
match * self {
1653
1684
ResolvedPath { did, .. } => Some ( did) ,
1685
+ Primitive ( p) => :: html:: render:: cache ( ) . primitive_locations . get ( & p) . cloned ( ) ,
1686
+ BorrowedRef { type_ : box Generic ( ..) , .. } =>
1687
+ Primitive ( PrimitiveType :: Reference ) . def_id ( ) ,
1688
+ BorrowedRef { ref type_, .. } => type_. def_id ( ) ,
1689
+ Tuple ( ..) => Primitive ( PrimitiveType :: Tuple ) . def_id ( ) ,
1690
+ BareFunction ( ..) => Primitive ( PrimitiveType :: Fn ) . def_id ( ) ,
1691
+ Slice ( ..) => Primitive ( PrimitiveType :: Slice ) . def_id ( ) ,
1692
+ Array ( ..) => Primitive ( PrimitiveType :: Array ) . def_id ( ) ,
1693
+ RawPointer ( ..) => Primitive ( PrimitiveType :: RawPointer ) . def_id ( ) ,
1694
+ QPath { ref self_type, .. } => self_type. def_id ( ) ,
1654
1695
_ => None ,
1655
1696
}
1656
1697
}
0 commit comments