Skip to content

Commit 24cbe38

Browse files
committed
rustdoc: Correctly classify enums/typedefs
Both of these items are surfaced as a DefTy, so some extra logic was needed in the decoder module to figure out whether one is actually an enum or whether it's a typedef. Closes #14757
1 parent 14668f2 commit 24cbe38

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/librustc/metadata/csearch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,8 @@ pub fn get_reachable_extern_fns(cstore: &cstore::CStore, cnum: ast::CrateNum)
321321
let cdata = cstore.get_crate_data(cnum);
322322
decoder::get_reachable_extern_fns(&*cdata)
323323
}
324+
325+
pub fn is_typedef(cstore: &cstore::CStore, did: ast::DefId) -> bool {
326+
let cdata = cstore.get_crate_data(did.krate);
327+
decoder::is_typedef(&*cdata, did.node)
328+
}

src/librustc/metadata/decoder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1339,3 +1339,11 @@ pub fn get_reachable_extern_fns(cdata: Cmd) -> Vec<ast::DefId> {
13391339
});
13401340
return ret;
13411341
}
1342+
1343+
pub fn is_typedef(cdata: Cmd, id: ast::NodeId) -> bool {
1344+
let item_doc = lookup_item(id, cdata.data());
1345+
match item_family(item_doc) {
1346+
Type => true,
1347+
_ => false,
1348+
}
1349+
}

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct {
203203
fn build_type(tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum {
204204
let t = ty::lookup_item_type(tcx, did);
205205
match ty::get(t.ty).sty {
206-
ty::ty_enum(edid, _) => {
206+
ty::ty_enum(edid, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => {
207207
return clean::EnumItem(clean::Enum {
208208
generics: t.generics.clean(),
209209
variants_stripped: false,

0 commit comments

Comments
 (0)