use rustc_middle::ty::{self, TyCtxt};
use rustc_span::def_id::CRATE_DEF_INDEX;
use rustc_span::Pos;
+use rustc_target::spec::abi::Abi as RustcAbi;
use rustdoc_json_types::*;
use crate::clean::{self, ItemId};
use crate::formats::item_type::ItemType;
use crate::json::JsonRenderer;
-use std::collections::HashSet;
impl JsonRenderer<'_> {
pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
impl FromWithTcx<clean::TypeBinding> for TypeBinding {
fn from_tcx(binding: clean::TypeBinding, tcx: TyCtxt<'_>) -> Self {
- TypeBinding { name: binding.name.to_string(), binding: binding.kind.into_tcx(tcx) }
+ TypeBinding {
+ name: binding.assoc.name.to_string(),
+ args: binding.assoc.args.into_tcx(tcx),
+ binding: binding.kind.into_tcx(tcx),
+ }
}
}
AssocConstItem(ty, default) => {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: default.map(|c| c.expr(tcx)) }
}
- AssocTypeItem(g, t) => ItemEnum::AssocType {
- bounds: g.into_iter().map(|x| x.into_tcx(tcx)).collect(),
+ AssocTypeItem(g, b, t) => ItemEnum::AssocType {
+ generics: (*g).into_tcx(tcx),
+ bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
default: t.map(|x| x.into_tcx(tcx)),
},
// `convert_item` early returns `None` for striped items
}
}
-crate fn from_fn_header(header: &rustc_hir::FnHeader) -> HashSet<Qualifiers> {
- let mut v = HashSet::new();
-
- if let rustc_hir::Unsafety::Unsafe = header.unsafety {
- v.insert(Qualifiers::Unsafe);
- }
-
- if let rustc_hir::IsAsync::Async = header.asyncness {
- v.insert(Qualifiers::Async);
+crate fn from_fn_header(header: &rustc_hir::FnHeader) -> Header {
+ Header {
+ async_: header.is_async(),
+ const_: header.is_const(),
+ unsafe_: header.is_unsafe(),
+ abi: convert_abi(header.abi),
}
+}
- if let rustc_hir::Constness::Const = header.constness {
- v.insert(Qualifiers::Const);
+fn convert_abi(a: RustcAbi) -> Abi {
+ match a {
+ RustcAbi::Rust => Abi::Rust,
+ RustcAbi::C { unwind } => Abi::C { unwind },
+ RustcAbi::Cdecl { unwind } => Abi::Cdecl { unwind },
+ RustcAbi::Stdcall { unwind } => Abi::Stdcall { unwind },
+ RustcAbi::Fastcall { unwind } => Abi::Fastcall { unwind },
+ RustcAbi::Aapcs { unwind } => Abi::Aapcs { unwind },
+ RustcAbi::Win64 { unwind } => Abi::Win64 { unwind },
+ RustcAbi::SysV64 { unwind } => Abi::SysV64 { unwind },
+ RustcAbi::System { unwind } => Abi::System { unwind },
+ _ => Abi::Other(a.to_string()),
}
-
- v
}
impl FromWithTcx<clean::Function> for Function {
decl: decl.into_tcx(tcx),
generics: generics.into_tcx(tcx),
header: from_fn_header(&header),
- abi: header.abi.to_string(),
}
}
}
Lifetime { outlives } => GenericParamDefKind::Lifetime {
outlives: outlives.into_iter().map(|lt| lt.0.to_string()).collect(),
},
- Type { did: _, bounds, default, synthetic: _ } => GenericParamDefKind::Type {
+ Type { did: _, bounds, default, synthetic } => GenericParamDefKind::Type {
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
default: default.map(|x| (*x).into_tcx(tcx)),
+ synthetic,
},
Const { did: _, ty, default } => {
GenericParamDefKind::Const { ty: (*ty).into_tcx(tcx), default: default.map(|x| *x) }
mutable: mutability == ast::Mutability::Mut,
type_: Box::new((*type_).into_tcx(tcx)),
},
- QPath { name, self_type, trait_, .. } => {
+ QPath { assoc, self_type, trait_, .. } => {
// FIXME: should `trait_` be a clean::Path equivalent in JSON?
let trait_ = clean::Type::Path { path: trait_ }.into_tcx(tcx);
Type::QualifiedPath {
- name: name.to_string(),
+ name: assoc.name.to_string(),
+ args: Box::new(assoc.args.clone().into_tcx(tcx)),
self_type: Box::new((*self_type).into_tcx(tcx)),
trait_: Box::new(trait_),
}
fn from_tcx(bare_decl: clean::BareFunctionDecl, tcx: TyCtxt<'_>) -> Self {
let clean::BareFunctionDecl { unsafety, generic_params, decl, abi } = bare_decl;
FunctionPointer {
- header: if let rustc_hir::Unsafety::Unsafe = unsafety {
- let mut hs = HashSet::new();
- hs.insert(Qualifiers::Unsafe);
- hs
- } else {
- HashSet::new()
+ header: Header {
+ unsafe_: matches!(unsafety, rustc_hir::Unsafety::Unsafe),
+ const_: false,
+ async_: false,
+ abi: convert_abi(abi),
},
generic_params: generic_params.into_iter().map(|x| x.into_tcx(tcx)).collect(),
decl: decl.into_tcx(tcx),
- abi: abi.to_string(),
}
}
}
decl: decl.into_tcx(tcx),
generics: generics.into_tcx(tcx),
header: from_fn_header(&header),
- abi: header.abi.to_string(),
has_body,
}
}