pub use self::TyParamBound::*;
pub use self::SelfTy::*;
pub use self::FunctionRetTy::*;
-pub use self::Visibility::*;
+pub use self::Visibility::{Public, Inherited};
use syntax;
use rustc_target::spec::abi::Abi;
}
}
-impl<'tcx> Clean<TyParam> for ty::TypeParamDef {
+impl<'tcx> Clean<TyParam> for ty::GenericParamDef {
fn clean(&self, cx: &DocContext) -> TyParam {
cx.renderinfo.borrow_mut().external_typarams.insert(self.def_id, self.name.clean(cx));
+ let has_default = match self.kind {
+ ty::GenericParamDefKind::Type(ty) => ty.has_default,
+ _ => panic!("tried to convert a non-type GenericParamDef as a type")
+ };
TyParam {
name: self.name.clean(cx),
did: self.def_id,
bounds: vec![], // these are filled in from the where-clauses
- default: if self.has_default {
+ default: if has_default {
Some(cx.tcx.type_of(self.def_id).clean(cx))
} else {
None
}
}
-impl Clean<Lifetime> for ty::RegionParamDef {
- fn clean(&self, _: &DocContext) -> Lifetime {
+impl<'tcx> Clean<Lifetime> for ty::GenericParamDef {
+ fn clean(&self, _cx: &DocContext) -> Lifetime {
Lifetime(self.name.to_string())
}
}
impl GenericParamDef {
pub fn is_synthetic_type_param(&self) -> bool {
- if let GenericParamDef::Type(ref t) = *self {
- t.synthetic.is_some()
- } else {
- false
+ match self {
+ GenericParamDef::Type(ty) => ty.synthetic.is_some(),
+ GenericParamDef::Lifetime(_) => false,
}
}
}
let mut params = Vec::with_capacity(self.params.len());
for p in &self.params {
let p = p.clean(cx);
- if let GenericParam::Type(ref tp) = p {
+ if let GenericParamDef::Type(ref tp) = p {
if tp.synthetic == Some(hir::SyntheticTyParamKind::ImplTrait) {
cx.impl_trait_bounds.borrow_mut().insert(tp.did, tp.bounds.clone());
}
// predicates field (see rustc_typeck::collect::ty_generics), so remove
// them.
let stripped_typarams = gens.params.iter().filter_map(|param| {
- if let ty::GenericParamDef::Type(ty) = param {
- if ty.name == keywords::SelfType.name().as_str() {
- assert_eq!(ty.index, 0);
+ if let ty::GenericParamDefKind::Type(_) = param.kind {
+ if param.name == keywords::SelfType.name().as_str() {
+ assert_eq!(param.index, 0);
None
} else {
- Some(ty.clean(cx))
+ Some(param.clean(cx))
}
} else {
None
}
- }).collect::<Vec<_>>();
+ }).collect::<Vec<TyParam>>();
let mut where_predicates = preds.predicates.to_vec().clean(cx);
params: gens.params
.iter()
.flat_map(|param| {
- if let ty::GenericParamDef::Lifetime(lt) = param {
- Some(GenericParamDef::Lifetime(lt.clean(cx)))
+ if let ty::GenericParamDefKind::Lifetime = param.kind {
+ Some(GenericParamDef::Lifetime(param.clean(cx)))
} else {
None
}
pub enum Visibility {
Public,
Inherited,
+ Crate,
+ Restricted(DefId, Path),
}
impl Clean<Option<Visibility>> for hir::Visibility {
- fn clean(&self, _: &DocContext) -> Option<Visibility> {
- Some(if *self == hir::Visibility::Public { Public } else { Inherited })
+ fn clean(&self, cx: &DocContext) -> Option<Visibility> {
+ Some(match *self {
+ hir::Visibility::Public => Visibility::Public,
+ hir::Visibility::Inherited => Visibility::Inherited,
+ hir::Visibility::Crate => Visibility::Crate,
+ hir::Visibility::Restricted { ref path, .. } => {
+ let path = path.clean(cx);
+ let did = register_def(cx, path.def);
+ Visibility::Restricted(did, path)
+ }
+ })
}
}