pub use self::IntVarValue::*;
pub use self::fold::TypeFoldable;
-use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
-use crate::hir::{HirId, Node};
-use crate::hir::def::{Def, CtorOf, CtorKind, ExportMap};
+use crate::hir::{map as hir_map, UpvarMap, GlobMap, TraitMap};
+use crate::hir::Node;
+use crate::hir::def::{Res, DefKind, CtorOf, CtorKind, ExportMap};
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_data_structures::svh::Svh;
use rustc_macros::HashStable;
use rustc_data_structures::sync::{self, Lrc, ParallelIterator, par_iter};
use std::slice;
use std::{mem, ptr};
+use std::ops::Range;
use syntax::ast::{self, Name, Ident, NodeId};
use syntax::attr;
use syntax::ext::hygiene::Mark;
-use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
+use syntax::symbol::{keywords, sym, Symbol, LocalInternedString, InternedString};
use syntax_pos::Span;
use smallvec;
#[derive(Clone)]
pub struct Resolutions {
- pub freevars: FreevarMap,
+ pub upvars: UpvarMap,
pub trait_map: TraitMap,
pub maybe_unused_trait_imports: NodeSet,
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
}
impl AssociatedItem {
- pub fn def(&self) -> Def {
+ pub fn def_kind(&self) -> DefKind {
match self.kind {
- AssociatedKind::Const => Def::AssociatedConst(self.def_id),
- AssociatedKind::Method => Def::Method(self.def_id),
- AssociatedKind::Type => Def::AssociatedTy(self.def_id),
- AssociatedKind::Existential => Def::AssociatedExistential(self.def_id),
+ AssociatedKind::Const => DefKind::AssociatedConst,
+ AssociatedKind::Method => DefKind::Method,
+ AssociatedKind::Type => DefKind::AssociatedTy,
+ AssociatedKind::Existential => DefKind::AssociatedExistential,
}
}
match visibility.node {
hir::VisibilityKind::Public => Visibility::Public,
hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
- hir::VisibilityKind::Restricted { ref path, .. } => match path.def {
+ hir::VisibilityKind::Restricted { ref path, .. } => match path.res {
// If there is no resolution, `resolve` will have already reported an error, so
// assume that the visibility is public to avoid reporting more privacy errors.
- Def::Err => Visibility::Public,
+ Res::Err => Visibility::Public,
def => Visibility::Restricted(def.def_id()),
},
hir::VisibilityKind::Inherited => {
// `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
-static_assert!(MEM_SIZE_OF_TY_S: ::std::mem::size_of::<TyS<'_>>() == 32);
+static_assert_size!(TyS<'_>, 32);
impl<'tcx> Ord for TyS<'tcx> {
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
#[derive(Copy, Clone)]
pub struct ClosureUpvar<'tcx> {
- pub def: Def,
+ pub res: Res,
pub span: Span,
pub ty: Ty<'tcx>,
}
param: &ParamTy,
tcx: TyCtxt<'a, 'gcx, 'tcx>)
-> &'tcx GenericParamDef {
- if let Some(index) = param.idx.checked_sub(self.parent_count as u32) {
+ if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
let param = &self.params[index as usize];
match param.kind {
GenericParamDefKind::Type { .. } => param,
);
let mut flags = VariantFlags::NO_VARIANT_FLAGS;
- if adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, "non_exhaustive") {
+ if adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive) {
debug!("found non-exhaustive field list for {:?}", parent_did);
flags = flags | VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
} else if let Some(variant_did) = variant_did {
- if tcx.has_attr(variant_did, "non_exhaustive") {
+ if tcx.has_attr(variant_did, sym::non_exhaustive) {
debug!("found non-exhaustive field list for {:?}", variant_did);
flags = flags | VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
}
debug!("AdtDef::new({:?}, {:?}, {:?}, {:?})", did, kind, variants, repr);
let mut flags = AdtFlags::NO_ADT_FLAGS;
- if kind == AdtKind::Enum && tcx.has_attr(did, "non_exhaustive") {
+ if kind == AdtKind::Enum && tcx.has_attr(did, sym::non_exhaustive) {
debug!("found non-exhaustive variant list for {:?}", did);
flags = flags | AdtFlags::IS_VARIANT_LIST_NON_EXHAUSTIVE;
}
}
let attrs = tcx.get_attrs(did);
- if attr::contains_name(&attrs, "fundamental") {
+ if attr::contains_name(&attrs, sym::fundamental) {
flags |= AdtFlags::IS_FUNDAMENTAL;
}
if Some(did) == tcx.lang_items().phantom_data() {
.expect("variant_index_with_ctor_id: unknown variant").0
}
- pub fn variant_of_def(&self, def: Def) -> &VariantDef {
- match def {
- Def::Variant(vid) => self.variant_with_id(vid),
- Def::Ctor(cid, ..) => self.variant_with_ctor_id(cid),
- Def::Struct(..) | Def::Union(..) |
- Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) |
- Def::SelfCtor(..) => self.non_enum_variant(),
- _ => bug!("unexpected def {:?} in variant_of_def", def)
+ pub fn variant_of_res(&self, res: Res) -> &VariantDef {
+ match res {
+ Res::Def(DefKind::Variant, vid) => self.variant_with_id(vid),
+ Res::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid),
+ Res::Def(DefKind::Struct, _) | Res::Def(DefKind::Union, _) |
+ Res::Def(DefKind::TyAlias, _) | Res::Def(DefKind::AssociatedTy, _) | Res::SelfTy(..) |
+ Res::SelfCtor(..) => self.non_enum_variant(),
+ _ => bug!("unexpected res {:?} in variant_of_res", res)
}
}
})
}
+ #[inline]
+ pub fn variant_range(&self) -> Range<VariantIdx> {
+ (VariantIdx::new(0)..VariantIdx::new(self.variants.len()))
+ }
+
/// Computes the discriminant value used by a specific variant.
/// Unlike `discriminants`, this is (amortized) constant-time,
/// only doing at most one query for evaluating an explicit
/// discriminant (the last one before the requested variant),
/// assuming there are no constant-evaluation errors there.
+ #[inline]
pub fn discriminant_for_variant(&self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
variant_index: VariantIdx)
_ => false,
}
} else {
- match self.describe_def(def_id).expect("no def for def-id") {
- Def::AssociatedConst(_) | Def::Method(_) | Def::AssociatedTy(_) => true,
+ match self.def_kind(def_id).expect("no def for def-id") {
+ DefKind::AssociatedConst
+ | DefKind::Method
+ | DefKind::AssociatedTy => true,
_ => false,
}
};
}
}
- /// Returns `ty::VariantDef` if `def` refers to a struct,
+ /// Returns `ty::VariantDef` if `res` refers to a struct,
/// or variant or their constructors, panics otherwise.
- pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
- match def {
- Def::Variant(did) => {
+ pub fn expect_variant_res(self, res: Res) -> &'tcx VariantDef {
+ match res {
+ Res::Def(DefKind::Variant, did) => {
let enum_did = self.parent(did).unwrap();
self.adt_def(enum_did).variant_with_id(did)
}
- Def::Struct(did) | Def::Union(did) => {
+ Res::Def(DefKind::Struct, did) | Res::Def(DefKind::Union, did) => {
self.adt_def(did).non_enum_variant()
}
- Def::Ctor(variant_ctor_did, CtorOf::Variant, ..) => {
+ Res::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
let variant_did = self.parent(variant_ctor_did).unwrap();
let enum_did = self.parent(variant_did).unwrap();
self.adt_def(enum_did).variant_with_ctor_id(variant_ctor_did)
}
- Def::Ctor(ctor_did, CtorOf::Struct, ..) => {
+ Res::Def(DefKind::Ctor(CtorOf::Struct, ..), ctor_did) => {
let struct_did = self.parent(ctor_did).expect("struct ctor has no parent");
self.adt_def(struct_did).non_enum_variant()
}
- _ => bug!("expect_variant_def used with unexpected def {:?}", def)
+ _ => bug!("expect_variant_res used with unexpected res {:?}", res)
}
}
}
/// Determines whether an item is annotated with an attribute.
- pub fn has_attr(self, did: DefId, attr: &str) -> bool {
+ pub fn has_attr(self, did: DefId, attr: Symbol) -> bool {
attr::contains_name(&self.get_attrs(did), attr)
}
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
let item = if def_id.krate != LOCAL_CRATE {
- if let Some(Def::Method(_)) = self.describe_def(def_id) {
+ if let Some(DefKind::Method) = self.def_kind(def_id) {
Some(self.associated_item(def_id))
} else {
None
}
}
-impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
- pub fn with_freevars<T, F>(self, fid: HirId, f: F) -> T where
- F: FnOnce(&[hir::Freevar]) -> T,
- {
- let def_id = self.hir().local_def_id_from_hir_id(fid);
- match self.freevars(def_id) {
- None => f(&[]),
- Some(d) => f(&d),
- }
- }
-}
-
fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> AssociatedItem {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let parent_id = tcx.hir().get_parent_item(id);
impl SymbolName {
pub fn new(name: &str) -> SymbolName {
SymbolName {
- name: Symbol::intern(name).as_interned_str()
+ name: InternedString::intern(name)
}
}