use crate::core::DocContext;
use itertools::Itertools;
-use rustc::mir::interpret::{sign_extend, ConstValue, Scalar};
-use rustc::ty::subst::{GenericArgKind, SubstsRef};
-use rustc::ty::{self, DefIdTree, Ty};
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
+use rustc_middle::mir::interpret::{sign_extend, ConstValue, Scalar};
+use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
+use rustc_middle::ty::{self, DefIdTree, Ty};
use rustc_span::symbol::{kw, sym, Symbol};
use std::mem;
let args: Vec<_> = substs
.iter()
.filter_map(|kind| match kind.unpack() {
- GenericArgKind::Lifetime(lt) => lt.clean(cx).map(|lt| GenericArg::Lifetime(lt)),
+ GenericArgKind::Lifetime(lt) => lt.clean(cx).map(GenericArg::Lifetime),
GenericArgKind::Type(_) if skip_self => {
skip_self = false;
None
arg: &Type,
cx: &DocContext<'_>,
recurse: i32,
-) -> FxHashSet<Type> {
+) -> FxHashSet<(Type, TypeKind)> {
let arg_s = arg.print().to_string();
let mut res = FxHashSet::default();
if recurse >= 10 {
}) {
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
for bound in bounds.iter() {
- match *bound {
- GenericBound::TraitBound(ref poly_trait, _) => {
- for x in poly_trait.generic_params.iter() {
- if !x.is_type() {
- continue;
- }
- if let Some(ty) = x.get_type() {
- let adds = get_real_types(generics, &ty, cx, recurse + 1);
- if !adds.is_empty() {
- res.extend(adds);
- } else if !ty.is_full_generic() {
- res.insert(ty);
+ if let GenericBound::TraitBound(ref poly_trait, _) = *bound {
+ for x in poly_trait.generic_params.iter() {
+ if !x.is_type() {
+ continue;
+ }
+ if let Some(ty) = x.get_type() {
+ let adds = get_real_types(generics, &ty, cx, recurse + 1);
+ if !adds.is_empty() {
+ res.extend(adds);
+ } else if !ty.is_full_generic() {
+ if let Some(kind) =
+ ty.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
+ {
+ res.insert((ty, kind));
}
}
}
}
- _ => {}
}
}
}
if !adds.is_empty() {
res.extend(adds);
} else if !ty.is_full_generic() {
- res.insert(ty.clone());
+ if let Some(kind) =
+ ty.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
+ {
+ res.insert((ty.clone(), kind));
+ }
}
}
}
}
} else {
- res.insert(arg.clone());
+ if let Some(kind) = arg.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx)) {
+ res.insert((arg.clone(), kind));
+ }
if let Some(gens) = arg.generics() {
for gen in gens.iter() {
if gen.is_full_generic() {
if !adds.is_empty() {
res.extend(adds);
}
- } else {
- res.insert(gen.clone());
+ } else if let Some(kind) =
+ gen.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
+ {
+ res.insert((gen.clone(), kind));
}
}
}
generics: &Generics,
decl: &FnDecl,
cx: &DocContext<'_>,
-) -> (Vec<Type>, Vec<Type>) {
+) -> (Vec<(Type, TypeKind)>, Vec<(Type, TypeKind)>) {
let mut all_types = FxHashSet::default();
for arg in decl.inputs.values.iter() {
if arg.type_.is_self_type() {
if !args.is_empty() {
all_types.extend(args);
} else {
- all_types.insert(arg.type_.clone());
+ if let Some(kind) = arg.type_.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx)) {
+ all_types.insert((arg.type_.clone(), kind));
+ }
}
}
FnRetTy::Return(ref return_type) => {
let mut ret = get_real_types(generics, &return_type, cx, 0);
if ret.is_empty() {
- ret.insert(return_type.clone());
+ if let Some(kind) =
+ return_type.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
+ {
+ ret.insert((return_type.clone(), kind));
+ }
}
ret.into_iter().collect()
}
}
pub fn print_evaluated_const(cx: &DocContext<'_>, def_id: DefId) -> Option<String> {
- let value = cx.tcx.const_eval_poly(def_id).ok().and_then(|val| {
+ cx.tcx.const_eval_poly(def_id).ok().and_then(|val| {
let ty = cx.tcx.type_of(def_id);
match (val, &ty.kind) {
(_, &ty::Ref(..)) => None,
}
_ => None,
}
- });
-
- value
+ })
}
fn format_integer_with_underscore_sep(num: &str) -> String {
None
};
- snippet.unwrap_or_else(|| cx.tcx.hir().hir_to_pretty_string(body.hir_id))
+ snippet.unwrap_or_else(|| rustc_hir_pretty::id_to_string(&cx.tcx.hir(), body.hir_id))
}
/// Given a type Path, resolve it to a Type using the TyCtxt
pub fn resolve_type(cx: &DocContext<'_>, path: Path, id: hir::HirId) -> Type {
- if id == hir::DUMMY_HIR_ID {
- debug!("resolve_type({:?})", path);
- } else {
- debug!("resolve_type({:?},{:?})", path, id);
- }
+ debug!("resolve_type({:?},{:?})", path, id);
let is_generic = match path.res {
Res::PrimTy(p) => return Primitive(PrimitiveType::from(p)),
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
return Generic(format!("{:#}", path.print()));
}
- Res::SelfTy(..) | Res::Def(DefKind::TyParam, _) | Res::Def(DefKind::AssocTy, _) => true,
+ Res::SelfTy(..) | Res::Def(DefKind::TyParam | DefKind::AssocTy, _) => true,
_ => false,
};
let did = register_res(&*cx, path.res);