From 097126e2840425b7d11f269c39a22c86ef003d6b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 4 Jan 2020 12:35:23 -0800 Subject: [PATCH] Omit underscore constants from rustdoc --- src/librustdoc/visit_ast.rs | 26 +++++++++++++++----------- src/test/rustdoc/const-underscore.rs | 7 +++++++ 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/test/rustdoc/const-underscore.rs diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 959f61644d60d..53deca2180cea 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -9,7 +9,7 @@ use rustc::ty::TyCtxt; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::Spanned; -use rustc_span::symbol::sym; +use rustc_span::symbol::{kw, sym}; use rustc_span::{self, Span}; use syntax::ast; @@ -513,16 +513,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { om.statics.push(s); } hir::ItemKind::Const(type_, expr) => { - let s = Constant { - type_, - expr, - id: item.hir_id, - name: ident.name, - attrs: &item.attrs, - whence: item.span, - vis: &item.vis, - }; - om.constants.push(s); + // Underscore constants do not correspond to a nameable item and + // so are never useful in documentation. + if ident.name != kw::Underscore { + let s = Constant { + type_, + expr, + id: item.hir_id, + name: ident.name, + attrs: &item.attrs, + whence: item.span, + vis: &item.vis, + }; + om.constants.push(s); + } } hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => { let items = item_ids.iter().map(|ti| self.cx.tcx.hir().trait_item(ti.id)).collect(); diff --git a/src/test/rustdoc/const-underscore.rs b/src/test/rustdoc/const-underscore.rs new file mode 100644 index 0000000000000..0d4809409f3a2 --- /dev/null +++ b/src/test/rustdoc/const-underscore.rs @@ -0,0 +1,7 @@ +// compile-flags: --document-private-items + +// @!has const_underscore/constant._.html +const _: () = { + #[no_mangle] + extern "C" fn implementation_detail() {} +};