//! Miscellaneous type-system utilities that are too small to deserve their own modules.
use crate::hir;
+use crate::hir::def::DefKind;
use crate::hir::def_id::DefId;
use crate::hir::map::DefPathData;
use crate::mir::interpret::{sign_extend, truncate};
ty::Tuple(tys) => {
if let Some((&last_ty, _)) = tys.split_last() {
- ty = last_ty;
+ ty = last_ty.expect_ty();
} else {
break;
}
(&Tuple(a_tys), &Tuple(b_tys))
if a_tys.len() == b_tys.len() => {
if let Some(a_last) = a_tys.last() {
- a = a_last;
- b = b_tys.last().unwrap();
+ a = a_last.expect_ty();
+ b = b_tys.last().unwrap().expect_ty();
} else {
break;
}
/// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`).
pub fn is_trait(self, def_id: DefId) -> bool {
- if let DefPathData::Trait(_) = self.def_key(def_id).disambiguated_data.data {
- true
- } else {
- false
- }
+ self.def_kind(def_id) == Some(DefKind::Trait)
}
/// Returns `true` if `def_id` refers to a trait alias (i.e., `trait Foo = ...;`),
/// and `false` otherwise.
pub fn is_trait_alias(self, def_id: DefId) -> bool {
- if let DefPathData::TraitAlias(_) = self.def_key(def_id).disambiguated_data.data {
- true
- } else {
- false
- }
+ self.def_kind(def_id) == Some(DefKind::TraitAlias)
}
/// Returns `true` if this `DefId` refers to the implicit constructor for
pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> SubstsRef<'tcx> {
InternalSubsts::for_item(self, item_def_id, |param, _| {
match param.kind {
- GenericParamDefKind::Lifetime => self.types.re_erased.into(),
+ GenericParamDefKind::Lifetime => self.lifetimes.re_erased.into(),
GenericParamDefKind::Type { .. } => {
bug!("empty_substs_for_def_id: {:?} has type parameters", item_def_id)
}
Tuple(ref ts) => {
// Find non representable
fold_repr(ts.iter().map(|ty| {
- is_type_structurally_recursive(tcx, sp, seen, representable_cache, ty)
+ is_type_structurally_recursive(
+ tcx,
+ sp,
+ seen,
+ representable_cache,
+ ty.expect_ty(),
+ )
}))
}
// Fixed-length vectors.
// state transformation pass
ty::Generator(..) => true,
- ty::Tuple(ref tys) => tys.iter().cloned().any(needs_drop),
+ ty::Tuple(ref tys) => tys.iter().map(|k| k.expect_ty()).any(needs_drop),
// unions don't have destructors because of the child types,
// only if they manually implement `Drop` (handled above).