#[derive(Clone, Debug)]
pub struct Crate {
pub name: String,
+ pub version: Option<String>,
pub src: PathBuf,
pub module: Option<Item>,
pub externs: Vec<(CrateNum, ExternalCrate)>,
Crate {
name,
+ version: None,
src,
module: Some(module),
externs,
if prim.is_some() {
break;
}
+ // FIXME: should warn on unknown primitives?
}
}
}
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>),
AssociatedTypeItem(Vec<TyParamBound>, Option<Type>),
- DefaultImplItem(DefaultImpl),
+ AutoImplItem(AutoImpl),
/// An item that has been stripped by a rustdoc pass
StrippedItem(Box<ItemEnum>),
}
pub abi: Abi,
}
-impl<'a> Clean<Method> for (&'a hir::MethodSig, hir::BodyId) {
+impl<'a> Clean<Method> for (&'a hir::MethodSig, &'a hir::Generics, hir::BodyId) {
fn clean(&self, cx: &DocContext) -> Method {
Method {
- generics: self.0.generics.clean(cx),
+ generics: self.1.clean(cx),
unsafety: self.0.unsafety,
constness: self.0.constness,
- decl: (&*self.0.decl, self.1).clean(cx),
+ decl: (&*self.0.decl, self.2).clean(cx),
abi: self.0.abi
}
}
default.map(|e| print_const_expr(cx, e)))
}
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
- MethodItem((sig, body).clean(cx))
+ MethodItem((sig, &self.generics, body).clean(cx))
}
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref names)) => {
TyMethodItem(TyMethod {
unsafety: sig.unsafety.clone(),
decl: (&*sig.decl, &names[..]).clean(cx),
- generics: sig.generics.clean(cx),
+ generics: self.generics.clean(cx),
abi: sig.abi
})
}
Some(print_const_expr(cx, expr)))
}
hir::ImplItemKind::Method(ref sig, body) => {
- MethodItem((sig, body).clean(cx))
+ MethodItem((sig, &self.generics, body).clean(cx))
}
hir::ImplItemKind::Type(ref ty) => TypedefItem(Typedef {
type_: ty.clean(cx),
Slice,
Array,
Tuple,
+ Unit,
RawPointer,
Reference,
Fn,
Trait,
Variant,
Typedef,
+ Foreign,
}
pub trait GetDefId {
Primitive(p) | BorrowedRef { type_: box Primitive(p), ..} => Some(p),
Slice(..) | BorrowedRef { type_: box Slice(..), .. } => Some(PrimitiveType::Slice),
Array(..) | BorrowedRef { type_: box Array(..), .. } => Some(PrimitiveType::Array),
- Tuple(..) => Some(PrimitiveType::Tuple),
+ Tuple(ref tys) => if tys.is_empty() {
+ Some(PrimitiveType::Unit)
+ } else {
+ Some(PrimitiveType::Tuple)
+ },
RawPointer(..) => Some(PrimitiveType::RawPointer),
BorrowedRef { type_: box Generic(..), .. } => Some(PrimitiveType::Reference),
BareFunction(..) => Some(PrimitiveType::Fn),
_ => false
}
}
+
+ pub fn generics(&self) -> Option<&[Type]> {
+ match *self {
+ ResolvedPath { ref path, .. } => {
+ path.segments.last().and_then(|seg| {
+ if let PathParameters::AngleBracketed { ref types, .. } = seg.params {
+ Some(&**types)
+ } else {
+ None
+ }
+ })
+ }
+ _ => None,
+ }
+ }
}
impl GetDefId for Type {
BorrowedRef { type_: box Generic(..), .. } =>
Primitive(PrimitiveType::Reference).def_id(),
BorrowedRef { ref type_, .. } => type_.def_id(),
- Tuple(..) => Primitive(PrimitiveType::Tuple).def_id(),
+ Tuple(ref tys) => if tys.is_empty() {
+ Primitive(PrimitiveType::Unit).def_id()
+ } else {
+ Primitive(PrimitiveType::Tuple).def_id()
+ },
BareFunction(..) => Primitive(PrimitiveType::Fn).def_id(),
Slice(..) => Primitive(PrimitiveType::Slice).def_id(),
Array(..) => Primitive(PrimitiveType::Array).def_id(),
"array" => Some(PrimitiveType::Array),
"slice" => Some(PrimitiveType::Slice),
"tuple" => Some(PrimitiveType::Tuple),
+ "unit" => Some(PrimitiveType::Unit),
"pointer" => Some(PrimitiveType::RawPointer),
"reference" => Some(PrimitiveType::Reference),
"fn" => Some(PrimitiveType::Fn),
Array => "array",
Slice => "slice",
Tuple => "tuple",
+ Unit => "unit",
RawPointer => "pointer",
Reference => "reference",
Fn => "fn",
}
}
TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
- TyImplTrait(ref bounds) => ImplTrait(bounds.clean(cx)),
+ TyImplTraitExistential(ref bounds) |
+ TyImplTraitUniversal(_, ref bounds) =>
+ ImplTrait(bounds.clean(cx)),
TyInfer | TyErr => Infer,
TyTypeof(..) => panic!("Unimplemented type {:?}", self.node),
}
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();
Slice => tcx.lang_items().slice_impl(),
Array => tcx.lang_items().slice_impl(),
Tuple => None,
+ Unit => None,
RawPointer => tcx.lang_items().const_ptr_impl(),
Reference => None,
Fn => None,
}
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
-pub struct DefaultImpl {
+pub struct AutoImpl {
pub unsafety: hir::Unsafety,
pub trait_: Type,
}
-impl Clean<Item> for doctree::DefaultImpl {
+impl Clean<Item> for doctree::AutoImpl {
fn clean(&self, cx: &DocContext) -> Item {
Item {
name: None,
visibility: Some(Public),
stability: None,
deprecation: None,
- inner: DefaultImplItem(DefaultImpl {
+ inner: AutoImplItem(AutoImpl {
unsafety: self.unsafety,
trait_: self.trait_.clean(cx),
}),
expr: "".to_string(),
})
}
+ hir::ForeignItemType => {
+ ForeignTypeItem
+ }
};
Item {
name: Some(self.name.clean(cx)),