1 //! These from impls are used to create the JSON types which get serialized. They're very close to
2 //! the `clean` types but with some fields removed or stringified to simplify the output and not
3 //! expose unstable compiler internals.
5 #![allow(rustc::default_hash_types)]
7 use std::convert::From;
11 use rustc_hir::{def::CtorKind, def_id::DefId};
12 use rustc_middle::ty::{self, TyCtxt};
13 use rustc_span::def_id::CRATE_DEF_INDEX;
15 use rustc_target::spec::abi::Abi as RustcAbi;
17 use rustdoc_json_types::*;
19 use crate::clean::utils::print_const_expr;
20 use crate::clean::{self, ItemId};
21 use crate::formats::item_type::ItemType;
22 use crate::json::JsonRenderer;
24 impl JsonRenderer<'_> {
25 pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
26 let deprecation = item.deprecation(self.tcx);
33 .map(|clean::ItemLink { link, did, .. }| (link.clone(), from_item_id((*did).into())))
35 let docs = item.attrs.collapsed_doc_value();
40 .map(rustc_ast_pretty::pprust::attribute_to_string)
42 let span = item.span(self.tcx);
43 let clean::Item { name, attrs: _, kind: _, visibility, def_id, cfg: _ } = item;
44 let inner = match *item.kind {
45 clean::StrippedItem(_) => return None,
46 _ => from_clean_item(item, self.tcx),
49 id: from_item_id(def_id),
50 crate_id: def_id.krate().as_u32(),
51 name: name.map(|sym| sym.to_string()),
52 span: self.convert_span(span),
53 visibility: self.convert_visibility(visibility),
56 deprecation: deprecation.map(from_deprecation),
62 fn convert_span(&self, span: clean::Span) -> Option<Span> {
63 match span.filename(self.sess()) {
64 rustc_span::FileName::Real(name) => {
65 if let Some(local_path) = name.into_local_path() {
66 let hi = span.hi(self.sess());
67 let lo = span.lo(self.sess());
70 begin: (lo.line, lo.col.to_usize()),
71 end: (hi.line, hi.col.to_usize()),
81 fn convert_visibility(&self, v: clean::Visibility) -> Visibility {
82 use clean::Visibility::*;
84 Public => Visibility::Public,
85 Inherited => Visibility::Default,
86 Restricted(did) if did.index == CRATE_DEF_INDEX => Visibility::Crate,
87 Restricted(did) => Visibility::Restricted {
88 parent: from_item_id(did.into()),
89 path: self.tcx.def_path(did).to_string_no_crate_verbose(),
95 crate trait FromWithTcx<T> {
96 fn from_tcx(f: T, tcx: TyCtxt<'_>) -> Self;
99 crate trait IntoWithTcx<T> {
100 fn into_tcx(self, tcx: TyCtxt<'_>) -> T;
103 impl<T, U> IntoWithTcx<U> for T
107 fn into_tcx(self, tcx: TyCtxt<'_>) -> U {
108 U::from_tcx(self, tcx)
112 crate fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
114 let rustc_attr::Deprecation { since, note, is_since_rustc_version: _, suggestion: _ } = deprecation;
115 Deprecation { since: since.map(|s| s.to_string()), note: note.map(|s| s.to_string()) }
118 impl FromWithTcx<clean::GenericArgs> for GenericArgs {
119 fn from_tcx(args: clean::GenericArgs, tcx: TyCtxt<'_>) -> Self {
120 use clean::GenericArgs::*;
122 AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
123 args: args.into_iter().map(|a| a.into_tcx(tcx)).collect(),
124 bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
126 Parenthesized { inputs, output } => GenericArgs::Parenthesized {
127 inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
128 output: output.map(|a| (*a).into_tcx(tcx)),
134 impl FromWithTcx<clean::GenericArg> for GenericArg {
135 fn from_tcx(arg: clean::GenericArg, tcx: TyCtxt<'_>) -> Self {
136 use clean::GenericArg::*;
138 Lifetime(l) => GenericArg::Lifetime(l.0.to_string()),
139 Type(t) => GenericArg::Type(t.into_tcx(tcx)),
140 Const(box c) => GenericArg::Const(c.into_tcx(tcx)),
141 Infer => GenericArg::Infer,
146 impl FromWithTcx<clean::Constant> for Constant {
147 fn from_tcx(constant: clean::Constant, tcx: TyCtxt<'_>) -> Self {
148 let expr = constant.expr(tcx);
149 let value = constant.value(tcx);
150 let is_literal = constant.is_literal(tcx);
151 Constant { type_: constant.type_.into_tcx(tcx), expr, value, is_literal }
155 impl FromWithTcx<clean::TypeBinding> for TypeBinding {
156 fn from_tcx(binding: clean::TypeBinding, tcx: TyCtxt<'_>) -> Self {
158 name: binding.assoc.name.to_string(),
159 args: binding.assoc.args.into_tcx(tcx),
160 binding: binding.kind.into_tcx(tcx),
165 impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
166 fn from_tcx(kind: clean::TypeBindingKind, tcx: TyCtxt<'_>) -> Self {
167 use clean::TypeBindingKind::*;
169 Equality { term } => TypeBindingKind::Equality(term.into_tcx(tcx)),
170 Constraint { bounds } => {
171 TypeBindingKind::Constraint(bounds.into_iter().map(|a| a.into_tcx(tcx)).collect())
177 crate fn from_item_id(did: ItemId) -> Id {
178 struct DisplayDefId(DefId);
180 impl fmt::Display for DisplayDefId {
181 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
182 write!(f, "{}:{}", self.0.krate.as_u32(), u32::from(self.0.index))
187 ItemId::DefId(did) => Id(format!("{}", DisplayDefId(did))),
188 ItemId::Blanket { for_, impl_id } => {
189 Id(format!("b:{}-{}", DisplayDefId(impl_id), DisplayDefId(for_)))
191 ItemId::Auto { for_, trait_ } => {
192 Id(format!("a:{}-{}", DisplayDefId(trait_), DisplayDefId(for_)))
194 ItemId::Primitive(ty, krate) => Id(format!("p:{}:{}", krate.as_u32(), ty.as_sym())),
198 fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
199 use clean::ItemKind::*;
200 let name = item.name;
201 let is_crate = item.is_crate();
203 ModuleItem(m) => ItemEnum::Module(Module { is_crate, items: ids(m.items) }),
204 ImportItem(i) => ItemEnum::Import(i.into_tcx(tcx)),
205 StructItem(s) => ItemEnum::Struct(s.into_tcx(tcx)),
206 UnionItem(u) => ItemEnum::Union(u.into_tcx(tcx)),
207 StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
208 EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
209 VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
210 FunctionItem(f) => ItemEnum::Function(f.into_tcx(tcx)),
211 ForeignFunctionItem(f) => ItemEnum::Function(f.into_tcx(tcx)),
212 TraitItem(t) => ItemEnum::Trait(t.into_tcx(tcx)),
213 TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
214 MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, tcx)),
215 TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, tcx)),
216 ImplItem(i) => ItemEnum::Impl(i.into_tcx(tcx)),
217 StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
218 ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
219 ForeignTypeItem => ItemEnum::ForeignType,
220 TypedefItem(t, _) => ItemEnum::Typedef(t.into_tcx(tcx)),
221 OpaqueTyItem(t) => ItemEnum::OpaqueTy(t.into_tcx(tcx)),
222 ConstantItem(c) => ItemEnum::Constant(c.into_tcx(tcx)),
223 MacroItem(m) => ItemEnum::Macro(m.source),
224 ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)),
225 PrimitiveItem(p) => ItemEnum::PrimitiveType(p.as_sym().to_string()),
226 AssocConstItem(ty, default) => {
227 ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: default.map(|c| c.expr(tcx)) }
229 AssocTypeItem(g, b, t) => ItemEnum::AssocType {
230 generics: (*g).into_tcx(tcx),
231 bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
232 default: t.map(|x| x.into_tcx(tcx)),
234 // `convert_item` early returns `None` for striped items
235 StrippedItem(_) => unreachable!(),
237 panic!("{:?} is not supported for JSON output", item)
239 ExternCrateItem { ref src } => ItemEnum::ExternCrate {
240 name: name.as_ref().unwrap().to_string(),
241 rename: src.map(|x| x.to_string()),
246 impl FromWithTcx<clean::Struct> for Struct {
247 fn from_tcx(struct_: clean::Struct, tcx: TyCtxt<'_>) -> Self {
248 let clean::Struct { struct_type, generics, fields, fields_stripped } = struct_;
250 struct_type: from_ctor_kind(struct_type),
251 generics: generics.into_tcx(tcx),
254 impls: Vec::new(), // Added in JsonRenderer::item
259 impl FromWithTcx<clean::Union> for Union {
260 fn from_tcx(struct_: clean::Union, tcx: TyCtxt<'_>) -> Self {
261 let clean::Union { generics, fields, fields_stripped } = struct_;
263 generics: generics.into_tcx(tcx),
266 impls: Vec::new(), // Added in JsonRenderer::item
271 crate fn from_ctor_kind(struct_type: CtorKind) -> StructType {
273 CtorKind::Fictive => StructType::Plain,
274 CtorKind::Fn => StructType::Tuple,
275 CtorKind::Const => StructType::Unit,
279 crate fn from_fn_header(header: &rustc_hir::FnHeader) -> Header {
281 async_: header.is_async(),
282 const_: header.is_const(),
283 unsafe_: header.is_unsafe(),
284 abi: convert_abi(header.abi),
288 fn convert_abi(a: RustcAbi) -> Abi {
290 RustcAbi::Rust => Abi::Rust,
291 RustcAbi::C { unwind } => Abi::C { unwind },
292 RustcAbi::Cdecl { unwind } => Abi::Cdecl { unwind },
293 RustcAbi::Stdcall { unwind } => Abi::Stdcall { unwind },
294 RustcAbi::Fastcall { unwind } => Abi::Fastcall { unwind },
295 RustcAbi::Aapcs { unwind } => Abi::Aapcs { unwind },
296 RustcAbi::Win64 { unwind } => Abi::Win64 { unwind },
297 RustcAbi::SysV64 { unwind } => Abi::SysV64 { unwind },
298 RustcAbi::System { unwind } => Abi::System { unwind },
299 _ => Abi::Other(a.to_string()),
303 impl FromWithTcx<clean::Function> for Function {
304 fn from_tcx(function: clean::Function, tcx: TyCtxt<'_>) -> Self {
305 let clean::Function { decl, generics, header } = function;
307 decl: decl.into_tcx(tcx),
308 generics: generics.into_tcx(tcx),
309 header: from_fn_header(&header),
314 impl FromWithTcx<clean::Generics> for Generics {
315 fn from_tcx(generics: clean::Generics, tcx: TyCtxt<'_>) -> Self {
317 params: generics.params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
318 where_predicates: generics
321 .map(|x| x.into_tcx(tcx))
327 impl FromWithTcx<clean::GenericParamDef> for GenericParamDef {
328 fn from_tcx(generic_param: clean::GenericParamDef, tcx: TyCtxt<'_>) -> Self {
330 name: generic_param.name.to_string(),
331 kind: generic_param.kind.into_tcx(tcx),
336 impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
337 fn from_tcx(kind: clean::GenericParamDefKind, tcx: TyCtxt<'_>) -> Self {
338 use clean::GenericParamDefKind::*;
340 Lifetime { outlives } => GenericParamDefKind::Lifetime {
341 outlives: outlives.into_iter().map(|lt| lt.0.to_string()).collect(),
343 Type { did: _, bounds, default, synthetic: _ } => GenericParamDefKind::Type {
344 bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
345 default: default.map(|x| (*x).into_tcx(tcx)),
347 Const { did: _, ty, default } => {
348 GenericParamDefKind::Const { ty: (*ty).into_tcx(tcx), default: default.map(|x| *x) }
354 impl FromWithTcx<clean::WherePredicate> for WherePredicate {
355 fn from_tcx(predicate: clean::WherePredicate, tcx: TyCtxt<'_>) -> Self {
356 use clean::WherePredicate::*;
358 BoundPredicate { ty, bounds, .. } => WherePredicate::BoundPredicate {
359 ty: ty.into_tcx(tcx),
360 bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
361 // FIXME: add `bound_params` to rustdoc-json-params?
363 RegionPredicate { lifetime, bounds } => WherePredicate::RegionPredicate {
364 lifetime: lifetime.0.to_string(),
365 bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
367 EqPredicate { lhs, rhs } => {
368 WherePredicate::EqPredicate { lhs: lhs.into_tcx(tcx), rhs: rhs.into_tcx(tcx) }
374 impl FromWithTcx<clean::GenericBound> for GenericBound {
375 fn from_tcx(bound: clean::GenericBound, tcx: TyCtxt<'_>) -> Self {
376 use clean::GenericBound::*;
378 TraitBound(clean::PolyTrait { trait_, generic_params }, modifier) => {
379 // FIXME: should `trait_` be a clean::Path equivalent in JSON?
380 let trait_ = clean::Type::Path { path: trait_ }.into_tcx(tcx);
381 GenericBound::TraitBound {
383 generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
384 modifier: from_trait_bound_modifier(modifier),
387 Outlives(lifetime) => GenericBound::Outlives(lifetime.0.to_string()),
392 crate fn from_trait_bound_modifier(modifier: rustc_hir::TraitBoundModifier) -> TraitBoundModifier {
393 use rustc_hir::TraitBoundModifier::*;
395 None => TraitBoundModifier::None,
396 Maybe => TraitBoundModifier::Maybe,
397 MaybeConst => TraitBoundModifier::MaybeConst,
401 impl FromWithTcx<clean::Type> for Type {
402 fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self {
404 Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive,
405 QPath, RawPointer, Slice, Tuple,
409 clean::Type::Path { path } => Type::ResolvedPath {
410 name: path.whole_name(),
411 id: from_item_id(path.def_id().into()),
412 args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
413 param_names: Vec::new(),
415 DynTrait(mut bounds, lt) => {
416 let first_trait = bounds.remove(0).trait_;
419 name: first_trait.whole_name(),
420 id: from_item_id(first_trait.def_id().into()),
424 .map(|args| Box::new(args.clone().args.into_tcx(tcx))),
428 clean::GenericBound::TraitBound(t, rustc_hir::TraitBoundModifier::None)
430 .chain(lt.map(clean::GenericBound::Outlives))
431 .map(|bound| bound.into_tcx(tcx))
435 Generic(s) => Type::Generic(s.to_string()),
436 Primitive(p) => Type::Primitive(p.as_sym().to_string()),
437 BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
438 Tuple(t) => Type::Tuple(t.into_iter().map(|x| x.into_tcx(tcx)).collect()),
439 Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
440 Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s },
441 ImplTrait(g) => Type::ImplTrait(g.into_iter().map(|x| x.into_tcx(tcx)).collect()),
442 Infer => Type::Infer,
443 RawPointer(mutability, type_) => Type::RawPointer {
444 mutable: mutability == ast::Mutability::Mut,
445 type_: Box::new((*type_).into_tcx(tcx)),
447 BorrowedRef { lifetime, mutability, type_ } => Type::BorrowedRef {
448 lifetime: lifetime.map(|l| l.0.to_string()),
449 mutable: mutability == ast::Mutability::Mut,
450 type_: Box::new((*type_).into_tcx(tcx)),
452 QPath { assoc, self_type, trait_, .. } => {
453 // FIXME: should `trait_` be a clean::Path equivalent in JSON?
454 let trait_ = clean::Type::Path { path: trait_ }.into_tcx(tcx);
455 Type::QualifiedPath {
456 name: assoc.name.to_string(),
457 args: Box::new(assoc.args.clone().into_tcx(tcx)),
458 self_type: Box::new((*self_type).into_tcx(tcx)),
459 trait_: Box::new(trait_),
466 impl FromWithTcx<clean::Term> for Term {
467 fn from_tcx(term: clean::Term, tcx: TyCtxt<'_>) -> Term {
469 clean::Term::Type(ty) => Term::Type(FromWithTcx::from_tcx(ty, tcx)),
470 clean::Term::Constant(c) => Term::Constant(FromWithTcx::from_tcx(c, tcx)),
475 impl FromWithTcx<clean::BareFunctionDecl> for FunctionPointer {
476 fn from_tcx(bare_decl: clean::BareFunctionDecl, tcx: TyCtxt<'_>) -> Self {
477 let clean::BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl;
480 unsafe_: matches!(unsafety, rustc_hir::Unsafety::Unsafe),
483 abi: convert_abi(abi),
485 generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
486 decl: decl.into_tcx(tcx),
491 impl FromWithTcx<clean::FnDecl> for FnDecl {
492 fn from_tcx(decl: clean::FnDecl, tcx: TyCtxt<'_>) -> Self {
493 let clean::FnDecl { inputs, output, c_variadic } = decl;
498 .map(|arg| (arg.name.to_string(), arg.type_.into_tcx(tcx)))
500 output: match output {
501 clean::FnRetTy::Return(t) => Some(t.into_tcx(tcx)),
502 clean::FnRetTy::DefaultReturn => None,
509 impl FromWithTcx<clean::Trait> for Trait {
510 fn from_tcx(trait_: clean::Trait, tcx: TyCtxt<'_>) -> Self {
511 let clean::Trait { unsafety, items, generics, bounds, is_auto } = trait_;
514 is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
516 generics: generics.into_tcx(tcx),
517 bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
518 implementors: Vec::new(), // Added in JsonRenderer::item
523 impl FromWithTcx<clean::Impl> for Impl {
524 fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self {
525 let provided_trait_methods = impl_.provided_trait_methods(tcx);
526 let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_;
527 // FIXME: should `trait_` be a clean::Path equivalent in JSON?
528 let trait_ = trait_.map(|path| clean::Type::Path { path }.into_tcx(tcx));
529 // FIXME: use something like ImplKind in JSON?
530 let (synthetic, blanket_impl) = match kind {
531 clean::ImplKind::Normal => (false, None),
532 clean::ImplKind::Auto => (true, None),
533 clean::ImplKind::Blanket(ty) => (false, Some(*ty)),
535 let negative_polarity = match polarity {
536 ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => false,
537 ty::ImplPolarity::Negative => true,
540 is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
541 generics: generics.into_tcx(tcx),
542 provided_trait_methods: provided_trait_methods
544 .map(|x| x.to_string())
547 for_: for_.into_tcx(tcx),
549 negative: negative_polarity,
551 blanket_impl: blanket_impl.map(|x| x.into_tcx(tcx)),
556 crate fn from_function_method(
557 function: clean::Function,
561 let clean::Function { header, decl, generics } = function;
563 decl: decl.into_tcx(tcx),
564 generics: generics.into_tcx(tcx),
565 header: from_fn_header(&header),
570 impl FromWithTcx<clean::Enum> for Enum {
571 fn from_tcx(enum_: clean::Enum, tcx: TyCtxt<'_>) -> Self {
572 let clean::Enum { variants, generics, variants_stripped } = enum_;
574 generics: generics.into_tcx(tcx),
576 variants: ids(variants),
577 impls: Vec::new(), // Added in JsonRenderer::item
582 impl FromWithTcx<clean::VariantStruct> for Struct {
583 fn from_tcx(struct_: clean::VariantStruct, _tcx: TyCtxt<'_>) -> Self {
584 let clean::VariantStruct { struct_type, fields, fields_stripped } = struct_;
586 struct_type: from_ctor_kind(struct_type),
587 generics: Default::default(),
595 impl FromWithTcx<clean::Variant> for Variant {
596 fn from_tcx(variant: clean::Variant, tcx: TyCtxt<'_>) -> Self {
597 use clean::Variant::*;
599 CLike => Variant::Plain,
600 Tuple(fields) => Variant::Tuple(
604 if let clean::StructFieldItem(ty) = *f.kind {
612 Struct(s) => Variant::Struct(ids(s.fields)),
617 impl FromWithTcx<clean::Import> for Import {
618 fn from_tcx(import: clean::Import, _tcx: TyCtxt<'_>) -> Self {
619 use clean::ImportKind::*;
621 Simple(s) => Import {
622 source: import.source.path.whole_name(),
624 id: import.source.did.map(ItemId::from).map(from_item_id),
628 source: import.source.path.whole_name(),
629 name: import.source.path.last().to_string(),
630 id: import.source.did.map(ItemId::from).map(from_item_id),
637 impl FromWithTcx<clean::ProcMacro> for ProcMacro {
638 fn from_tcx(mac: clean::ProcMacro, _tcx: TyCtxt<'_>) -> Self {
640 kind: from_macro_kind(mac.kind),
641 helpers: mac.helpers.iter().map(|x| x.to_string()).collect(),
646 crate fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind {
647 use rustc_span::hygiene::MacroKind::*;
649 Bang => MacroKind::Bang,
650 Attr => MacroKind::Attr,
651 Derive => MacroKind::Derive,
655 impl FromWithTcx<clean::Typedef> for Typedef {
656 fn from_tcx(typedef: clean::Typedef, tcx: TyCtxt<'_>) -> Self {
657 let clean::Typedef { type_, generics, item_type: _ } = typedef;
658 Typedef { type_: type_.into_tcx(tcx), generics: generics.into_tcx(tcx) }
662 impl FromWithTcx<clean::OpaqueTy> for OpaqueTy {
663 fn from_tcx(opaque: clean::OpaqueTy, tcx: TyCtxt<'_>) -> Self {
665 bounds: opaque.bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
666 generics: opaque.generics.into_tcx(tcx),
671 impl FromWithTcx<clean::Static> for Static {
672 fn from_tcx(stat: clean::Static, tcx: TyCtxt<'_>) -> Self {
674 type_: stat.type_.into_tcx(tcx),
675 mutable: stat.mutability == ast::Mutability::Mut,
676 expr: stat.expr.map(|e| print_const_expr(tcx, e)).unwrap_or_default(),
681 impl FromWithTcx<clean::TraitAlias> for TraitAlias {
682 fn from_tcx(alias: clean::TraitAlias, tcx: TyCtxt<'_>) -> Self {
684 generics: alias.generics.into_tcx(tcx),
685 params: alias.bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
690 impl FromWithTcx<ItemType> for ItemKind {
691 fn from_tcx(kind: ItemType, _tcx: TyCtxt<'_>) -> Self {
694 Module => ItemKind::Module,
695 ExternCrate => ItemKind::ExternCrate,
696 Import => ItemKind::Import,
697 Struct => ItemKind::Struct,
698 Union => ItemKind::Union,
699 Enum => ItemKind::Enum,
700 Function => ItemKind::Function,
701 Typedef => ItemKind::Typedef,
702 OpaqueTy => ItemKind::OpaqueTy,
703 Static => ItemKind::Static,
704 Constant => ItemKind::Constant,
705 Trait => ItemKind::Trait,
706 Impl => ItemKind::Impl,
707 TyMethod | Method => ItemKind::Method,
708 StructField => ItemKind::StructField,
709 Variant => ItemKind::Variant,
710 Macro => ItemKind::Macro,
711 Primitive => ItemKind::Primitive,
712 AssocConst => ItemKind::AssocConst,
713 AssocType => ItemKind::AssocType,
714 ForeignType => ItemKind::ForeignType,
715 Keyword => ItemKind::Keyword,
716 TraitAlias => ItemKind::TraitAlias,
717 ProcAttribute => ItemKind::ProcAttribute,
718 ProcDerive => ItemKind::ProcDerive,
719 Generic => unreachable!(),
724 fn ids(items: impl IntoIterator<Item = clean::Item>) -> Vec<Id> {
725 items.into_iter().filter(|x| !x.is_stripped()).map(|i| from_item_id(i.def_id)).collect()