1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
15 pub fn get_def_from_def_id<F>(cx: &DocContext,
19 where F: Fn(& dyn Fn(DefId) -> Def) -> Vec<Item> {
20 let ty = cx.tcx.type_of(def_id);
23 ty::Adt(adt, _) => callback(&match adt.adt_kind() {
24 AdtKind::Struct => Def::Struct,
25 AdtKind::Enum => Def::Enum,
26 AdtKind::Union => Def::Union,
33 ty::TyChar => callback(&move |_: DefId| {
35 ty::TyInt(x) => Def::PrimTy(hir::TyInt(x)),
36 ty::TyUint(x) => Def::PrimTy(hir::TyUint(x)),
37 ty::TyFloat(x) => Def::PrimTy(hir::TyFloat(x)),
38 ty::TyStr => Def::PrimTy(hir::TyStr),
39 ty::TyBool => Def::PrimTy(hir::TyBool),
40 ty::TyChar => Def::PrimTy(hir::TyChar),
45 debug!("Unexpected type {:?}", def_id);
51 pub fn get_def_from_node_id<F>(cx: &DocContext,
56 where F: Fn(& dyn Fn(DefId) -> Def, String) -> Vec<Item> {
57 let item = &cx.tcx.hir.expect_item(id).node;
59 callback(&match *item {
60 hir::ItemKind::Struct(_, _) => Def::Struct,
61 hir::ItemKind::Union(_, _) => Def::Union,
62 hir::ItemKind::Enum(_, _) => Def::Enum,
63 _ => panic!("Unexpected type {:?} {:?}", item, id),