summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/json/conversions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/json/conversions.rs')
-rw-r--r--src/librustdoc/json/conversions.rs56
1 files changed, 21 insertions, 35 deletions
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index cdf59cdd3..d7184053c 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -48,7 +48,8 @@ impl JsonRenderer<'_> {
.map(rustc_ast_pretty::pprust::attribute_to_string)
.collect();
let span = item.span(self.tcx);
- let clean::Item { name, attrs: _, kind: _, visibility, item_id, cfg: _ } = item;
+ let visibility = item.visibility(self.tcx);
+ let clean::Item { name, attrs: _, kind: _, item_id, cfg: _, .. } = item;
let inner = match *item.kind {
clean::KeywordItem => return None,
clean::StrippedItem(ref inner) => {
@@ -99,13 +100,12 @@ impl JsonRenderer<'_> {
}
}
- fn convert_visibility(&self, v: clean::Visibility) -> Visibility {
- use clean::Visibility::*;
+ fn convert_visibility(&self, v: Option<ty::Visibility<DefId>>) -> Visibility {
match v {
- Public => Visibility::Public,
- Inherited => Visibility::Default,
- Restricted(did) if did.is_crate_root() => Visibility::Crate,
- Restricted(did) => Visibility::Restricted {
+ None => Visibility::Default,
+ Some(ty::Visibility::Public) => Visibility::Public,
+ Some(ty::Visibility::Restricted(did)) if did.is_crate_root() => Visibility::Crate,
+ Some(ty::Visibility::Restricted(did)) => Visibility::Restricted {
parent: from_item_id(did.into(), self.tcx),
path: self.tcx.def_path(did).to_string_no_crate_verbose(),
},
@@ -257,12 +257,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
- FunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)),
- ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)),
+ FunctionItem(f) => ItemEnum::Function(from_function(f, true, header.unwrap(), tcx)),
+ ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, false, header.unwrap(), tcx)),
TraitItem(t) => ItemEnum::Trait((*t).into_tcx(tcx)),
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
- MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, header.unwrap(), tcx)),
- TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, header.unwrap(), tcx)),
+ MethodItem(m, _) => ItemEnum::Function(from_function(m, true, header.unwrap(), tcx)),
+ TyMethodItem(m) => ItemEnum::Function(from_function(m, false, header.unwrap(), tcx)),
ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)),
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
@@ -283,7 +283,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: Some(default.expr(tcx)) }
}
TyAssocTypeItem(g, b) => ItemEnum::AssocType {
- generics: (*g).into_tcx(tcx),
+ generics: g.into_tcx(tcx),
bounds: b.into_tcx(tcx),
default: None,
},
@@ -315,15 +315,15 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
impl FromWithTcx<clean::Struct> for Struct {
fn from_tcx(struct_: clean::Struct, tcx: TyCtxt<'_>) -> Self {
let fields_stripped = struct_.has_stripped_entries();
- let clean::Struct { struct_type, generics, fields } = struct_;
+ let clean::Struct { ctor_kind, generics, fields } = struct_;
- let kind = match struct_type {
- CtorKind::Fn => StructKind::Tuple(ids_keeping_stripped(fields, tcx)),
- CtorKind::Const => {
+ let kind = match ctor_kind {
+ Some(CtorKind::Fn) => StructKind::Tuple(ids_keeping_stripped(fields, tcx)),
+ Some(CtorKind::Const) => {
assert!(fields.is_empty());
StructKind::Unit
}
- CtorKind::Fictive => StructKind::Plain { fields: ids(fields, tcx), fields_stripped },
+ None => StructKind::Plain { fields: ids(fields, tcx), fields_stripped },
};
Struct {
@@ -485,7 +485,7 @@ impl FromWithTcx<clean::Type> for Type {
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
Tuple(t) => Type::Tuple(t.into_tcx(tcx)),
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
- Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s },
+ Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s.to_string() },
ImplTrait(g) => Type::ImplTrait(g.into_tcx(tcx)),
Infer => Type::Infer,
RawPointer(mutability, type_) => Type::RawPointer {
@@ -618,6 +618,7 @@ impl FromWithTcx<clean::Impl> for Impl {
pub(crate) fn from_function(
function: Box<clean::Function>,
+ has_body: bool,
header: rustc_hir::FnHeader,
tcx: TyCtxt<'_>,
) -> Function {
@@ -626,20 +627,6 @@ pub(crate) fn from_function(
decl: decl.into_tcx(tcx),
generics: generics.into_tcx(tcx),
header: from_fn_header(&header),
- }
-}
-
-pub(crate) fn from_function_method(
- function: Box<clean::Function>,
- has_body: bool,
- header: rustc_hir::FnHeader,
- tcx: TyCtxt<'_>,
-) -> Method {
- let clean::Function { decl, generics } = *function;
- Method {
- decl: decl.into_tcx(tcx),
- generics: generics.into_tcx(tcx),
- header: from_fn_header(&header),
has_body,
}
}
@@ -674,7 +661,7 @@ impl FromWithTcx<clean::Variant> for Variant {
impl FromWithTcx<clean::Discriminant> for Discriminant {
fn from_tcx(disr: clean::Discriminant, tcx: TyCtxt<'_>) -> Self {
Discriminant {
- // expr is only none if going throught the inlineing path, which gets
+ // expr is only none if going through the inlineing path, which gets
// `rustc_middle` types, not `rustc_hir`, but because JSON never inlines
// the expr is always some.
expr: disr.expr(tcx).unwrap(),
@@ -759,14 +746,13 @@ impl FromWithTcx<ItemType> for ItemKind {
Struct => ItemKind::Struct,
Union => ItemKind::Union,
Enum => ItemKind::Enum,
- Function => ItemKind::Function,
+ Function | TyMethod | Method => ItemKind::Function,
Typedef => ItemKind::Typedef,
OpaqueTy => ItemKind::OpaqueTy,
Static => ItemKind::Static,
Constant => ItemKind::Constant,
Trait => ItemKind::Trait,
Impl => ItemKind::Impl,
- TyMethod | Method => ItemKind::Method,
StructField => ItemKind::StructField,
Variant => ItemKind::Variant,
Macro => ItemKind::Macro,