Implement RFC 1861: Extern types
This commit is contained in:
parent
bed9a85c40
commit
77f7e85d7f
81 changed files with 737 additions and 120 deletions
|
|
@ -419,6 +419,8 @@ pub enum ItemEnum {
|
|||
ForeignFunctionItem(Function),
|
||||
/// `static`s from an extern block
|
||||
ForeignStaticItem(Static),
|
||||
/// `type`s from an extern block
|
||||
ForeignTypeItem,
|
||||
MacroItem(Macro),
|
||||
PrimitiveItem(PrimitiveType),
|
||||
AssociatedConstItem(Type, Option<String>),
|
||||
|
|
@ -1646,6 +1648,7 @@ pub enum TypeKind {
|
|||
Trait,
|
||||
Variant,
|
||||
Typedef,
|
||||
Foreign,
|
||||
}
|
||||
|
||||
pub trait GetDefId {
|
||||
|
|
@ -2027,6 +2030,17 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
|||
is_generic: false,
|
||||
}
|
||||
}
|
||||
ty::TyForeign(did) => {
|
||||
inline::record_extern_fqn(cx, did, TypeKind::Foreign);
|
||||
let path = external_path(cx, &cx.tcx.item_name(did),
|
||||
None, false, vec![], Substs::empty());
|
||||
ResolvedPath {
|
||||
path: path,
|
||||
typarams: None,
|
||||
did: did,
|
||||
is_generic: false,
|
||||
}
|
||||
}
|
||||
ty::TyDynamic(ref obj, ref reg) => {
|
||||
if let Some(principal) = obj.principal() {
|
||||
let did = principal.def_id();
|
||||
|
|
@ -2840,6 +2854,9 @@ impl Clean<Item> for hir::ForeignItem {
|
|||
expr: "".to_string(),
|
||||
})
|
||||
}
|
||||
hir::ForeignItemType => {
|
||||
ForeignTypeItem
|
||||
}
|
||||
};
|
||||
Item {
|
||||
name: Some(self.name.clean(cx)),
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ pub enum ItemType {
|
|||
Constant = 17,
|
||||
AssociatedConst = 18,
|
||||
Union = 19,
|
||||
ForeignType = 20,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -82,6 +83,7 @@ impl<'a> From<&'a clean::Item> for ItemType {
|
|||
clean::AssociatedConstItem(..) => ItemType::AssociatedConst,
|
||||
clean::AssociatedTypeItem(..) => ItemType::AssociatedType,
|
||||
clean::DefaultImplItem(..) => ItemType::Impl,
|
||||
clean::ForeignTypeItem => ItemType::ForeignType,
|
||||
clean::StrippedItem(..) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
@ -100,6 +102,7 @@ impl From<clean::TypeKind> for ItemType {
|
|||
clean::TypeKind::Const => ItemType::Constant,
|
||||
clean::TypeKind::Variant => ItemType::Variant,
|
||||
clean::TypeKind::Typedef => ItemType::Typedef,
|
||||
clean::TypeKind::Foreign => ItemType::ForeignType,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,6 +130,7 @@ impl ItemType {
|
|||
ItemType::AssociatedType => "associatedtype",
|
||||
ItemType::Constant => "constant",
|
||||
ItemType::AssociatedConst => "associatedconstant",
|
||||
ItemType::ForeignType => "foreigntype",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +143,8 @@ impl ItemType {
|
|||
ItemType::Typedef |
|
||||
ItemType::Trait |
|
||||
ItemType::Primitive |
|
||||
ItemType::AssociatedType => NameSpace::Type,
|
||||
ItemType::AssociatedType |
|
||||
ItemType::ForeignType => NameSpace::Type,
|
||||
|
||||
ItemType::ExternCrate |
|
||||
ItemType::Import |
|
||||
|
|
|
|||
|
|
@ -2044,6 +2044,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
|||
ItemType::Primitive => ("primitives", "Primitive Types"),
|
||||
ItemType::AssociatedType => ("associated-types", "Associated Types"),
|
||||
ItemType::AssociatedConst => ("associated-consts", "Associated Constants"),
|
||||
ItemType::ForeignType => ("foreign-types", "Foreign Types"),
|
||||
};
|
||||
write!(w, "<h2 id='{id}' class='section-header'>\
|
||||
<a href=\"#{id}\">{name}</a></h2>\n<table>",
|
||||
|
|
@ -3679,7 +3680,7 @@ fn sidebar_module(fmt: &mut fmt::Formatter, _it: &clean::Item,
|
|||
ItemType::Enum, ItemType::Constant, ItemType::Static, ItemType::Trait,
|
||||
ItemType::Function, ItemType::Typedef, ItemType::Union, ItemType::Impl,
|
||||
ItemType::TyMethod, ItemType::Method, ItemType::StructField, ItemType::Variant,
|
||||
ItemType::AssociatedType, ItemType::AssociatedConst] {
|
||||
ItemType::AssociatedType, ItemType::AssociatedConst, ItemType::ForeignType] {
|
||||
if items.iter().any(|it| {
|
||||
if let clean::DefaultImplItem(..) = it.inner {
|
||||
false
|
||||
|
|
@ -3708,6 +3709,7 @@ fn sidebar_module(fmt: &mut fmt::Formatter, _it: &clean::Item,
|
|||
ItemType::Primitive => ("primitives", "Primitive Types"),
|
||||
ItemType::AssociatedType => ("associated-types", "Associated Types"),
|
||||
ItemType::AssociatedConst => ("associated-consts", "Associated Constants"),
|
||||
ItemType::ForeignType => ("foreign-types", "Foreign Types"),
|
||||
};
|
||||
sidebar.push_str(&format!("<li><a href=\"#{id}\">{name}</a></li>",
|
||||
id = short,
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
clean::VariantItem(..) | clean::MethodItem(..) |
|
||||
clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) |
|
||||
clean::ConstantItem(..) | clean::UnionItem(..) |
|
||||
clean::AssociatedConstItem(..) => {
|
||||
clean::AssociatedConstItem(..) | clean::ForeignTypeItem => {
|
||||
if i.def_id.is_local() {
|
||||
if !self.access_levels.is_exported(i.def_id) {
|
||||
return None;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue