Skip to content

Commit

Permalink
Rollup merge of rust-lang#67877 - dtolnay:const-_, r=nagisa
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohnTitor authored Jan 7, 2020
2 parents 4ed415b + 097126e commit 74ca7c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::Node;
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;

Expand Down Expand Up @@ -514,16 +514,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();
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc/const-underscore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// compile-flags: --document-private-items

// @!has const_underscore/constant._.html
const _: () = {
#[no_mangle]
extern "C" fn implementation_detail() {}
};

0 comments on commit 74ca7c7

Please sign in to comment.