//! Miscellaneous type-system utilities that are too small to deserve their own modules.
-use crate::hir::def::Def;
+use crate::hir;
+use crate::hir::def::DefKind;
use crate::hir::def_id::DefId;
use crate::hir::map::DefPathData;
-use crate::hir::{self, Node};
use crate::mir::interpret::{sign_extend, truncate};
use crate::ich::NodeIdHashingMode;
use crate::traits::{self, ObligationCause};
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)
}
})
}
- /// Returns `true` if the node pointed to by `def_id` is a static item, and its mutability.
- pub fn is_static(&self, def_id: DefId) -> Option<hir::Mutability> {
- if let Some(node) = self.hir().get_if_local(def_id) {
- match node {
- Node::Item(&hir::Item {
- node: hir::ItemKind::Static(_, mutbl, _), ..
- }) => Some(mutbl),
- Node::ForeignItem(&hir::ForeignItem {
- node: hir::ForeignItemKind::Static(_, is_mutbl), ..
- }) =>
- Some(if is_mutbl {
- hir::Mutability::MutMutable
- } else {
- hir::Mutability::MutImmutable
- }),
- _ => None
- }
- } else {
- match self.describe_def(def_id) {
- Some(Def::Static(_, is_mutbl)) =>
- Some(if is_mutbl {
- hir::Mutability::MutMutable
- } else {
- hir::Mutability::MutImmutable
- }),
- _ => None
- }
- }
+ /// Returns `true` if the node pointed to by `def_id` is a `static` item.
+ pub fn is_static(&self, def_id: DefId) -> bool {
+ self.static_mutability(def_id).is_some()
+ }
+
+ /// Returns `true` if the node pointed to by `def_id` is a mutable `static` item.
+ pub fn is_mutable_static(&self, def_id: DefId) -> bool {
+ self.static_mutability(def_id) == Some(hir::MutMutable)
}
/// Expands the given impl trait type, stopping if the type is recursive.
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).