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::Char => callback(&move |_: DefId| {
35 ty::Int(x) => Def::PrimTy(hir::Int(x)),
36 ty::Uint(x) => Def::PrimTy(hir::Uint(x)),
37 ty::Float(x) => Def::PrimTy(hir::Float(x)),
38 ty::Str => Def::PrimTy(hir::Str),
39 ty::Bool => Def::PrimTy(hir::Bool),
40 ty::Char => Def::PrimTy(hir::Char),
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),