Skip to content

Commit 097126e

Browse files
committed
Omit underscore constants from rustdoc
1 parent cd8377d commit 097126e

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/librustdoc/visit_ast.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::ty::TyCtxt;
99
use rustc::util::nodemap::{FxHashMap, FxHashSet};
1010
use rustc_span::hygiene::MacroKind;
1111
use rustc_span::source_map::Spanned;
12-
use rustc_span::symbol::sym;
12+
use rustc_span::symbol::{kw, sym};
1313
use rustc_span::{self, Span};
1414
use syntax::ast;
1515

@@ -513,16 +513,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
513513
om.statics.push(s);
514514
}
515515
hir::ItemKind::Const(type_, expr) => {
516-
let s = Constant {
517-
type_,
518-
expr,
519-
id: item.hir_id,
520-
name: ident.name,
521-
attrs: &item.attrs,
522-
whence: item.span,
523-
vis: &item.vis,
524-
};
525-
om.constants.push(s);
516+
// Underscore constants do not correspond to a nameable item and
517+
// so are never useful in documentation.
518+
if ident.name != kw::Underscore {
519+
let s = Constant {
520+
type_,
521+
expr,
522+
id: item.hir_id,
523+
name: ident.name,
524+
attrs: &item.attrs,
525+
whence: item.span,
526+
vis: &item.vis,
527+
};
528+
om.constants.push(s);
529+
}
526530
}
527531
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
528532
let items = item_ids.iter().map(|ti| self.cx.tcx.hir().trait_item(ti.id)).collect();

src/test/rustdoc/const-underscore.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: --document-private-items
2+
3+
// @!has const_underscore/constant._.html
4+
const _: () = {
5+
#[no_mangle]
6+
extern "C" fn implementation_detail() {}
7+
};

0 commit comments

Comments
 (0)