Skip to content

Commit 6698d98

Browse files
authored
Rollup merge of rust-lang#67877 - dtolnay:const-_, r=nagisa
Omit underscore constants from rustdoc Underscore constants from rust-lang/rfcs#2526 / rust-lang#54912 do not correspond to a nameable item and so are never useful in documentation. <br> #### Before: > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://user-images.githubusercontent.com/1940490/71771409-0427cc80-2eef-11ea-8b7d-d9c74a873e7e.png" width="60%"> #### After: > Not that.
2 parents a7527b5 + 097126e commit 6698d98

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/librustdoc/visit_ast.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1010
use rustc_hir::Node;
1111
use rustc_span::hygiene::MacroKind;
1212
use rustc_span::source_map::Spanned;
13-
use rustc_span::symbol::sym;
13+
use rustc_span::symbol::{kw, sym};
1414
use rustc_span::{self, Span};
1515
use syntax::ast;
1616

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

src/test/rustdoc/const-underscore.rs

Lines changed: 7 additions & 0 deletions
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)