#![allow(usage_of_ty_tykind)]
pub use self::Variance::*;
-pub use self::AssociatedItemContainer::*;
+pub use self::AssocItemContainer::*;
pub use self::BorrowKind::*;
pub use self::IntVarValue::*;
pub use self::fold::TypeFoldable;
use crate::infer::canonical::Canonical;
use crate::middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
-use crate::mir::Mir;
+use crate::mir::Body;
use crate::mir::interpret::{GlobalId, ErrorHandled};
use crate::mir::GeneratorLayout;
use crate::session::CrateDisambiguator;
use syntax::ast::{self, Name, Ident, NodeId};
use syntax::attr;
use syntax::ext::hygiene::Mark;
-use syntax::symbol::{keywords, sym, Symbol, LocalInternedString, InternedString};
+use syntax::symbol::{kw, sym, Symbol, LocalInternedString, InternedString};
use syntax_pos::Span;
use smallvec;
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable)]
-pub enum AssociatedItemContainer {
+pub enum AssocItemContainer {
TraitContainer(DefId),
ImplContainer(DefId),
}
-impl AssociatedItemContainer {
+impl AssocItemContainer {
/// Asserts that this is the `DefId` of an associated item declared
/// in a trait, and returns the trait `DefId`.
pub fn assert_trait(&self) -> DefId {
}
#[derive(Copy, Clone, Debug, PartialEq, HashStable)]
-pub struct AssociatedItem {
+pub struct AssocItem {
pub def_id: DefId,
#[stable_hasher(project(name))]
pub ident: Ident,
- pub kind: AssociatedKind,
+ pub kind: AssocKind,
pub vis: Visibility,
pub defaultness: hir::Defaultness,
- pub container: AssociatedItemContainer,
+ pub container: AssocItemContainer,
/// Whether this is a method with an explicit self
/// as its first argument, allowing method calls.
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, RustcEncodable, RustcDecodable, HashStable)]
-pub enum AssociatedKind {
+pub enum AssocKind {
Const,
Method,
Existential,
Type
}
-impl AssociatedItem {
+impl AssocItem {
pub fn def_kind(&self) -> DefKind {
match self.kind {
- AssociatedKind::Const => DefKind::AssociatedConst,
- AssociatedKind::Method => DefKind::Method,
- AssociatedKind::Type => DefKind::AssociatedTy,
- AssociatedKind::Existential => DefKind::AssociatedExistential,
+ AssocKind::Const => DefKind::AssocConst,
+ AssocKind::Method => DefKind::Method,
+ AssocKind::Type => DefKind::AssocTy,
+ AssocKind::Existential => DefKind::AssocExistential,
}
}
/// for !
pub fn relevant_for_never<'tcx>(&self) -> bool {
match self.kind {
- AssociatedKind::Existential |
- AssociatedKind::Const |
- AssociatedKind::Type => true,
+ AssocKind::Existential |
+ AssocKind::Const |
+ AssocKind::Type => true,
// FIXME(canndrew): Be more thorough here, check if any argument is uninhabited.
- AssociatedKind::Method => !self.method_has_self_argument,
+ AssocKind::Method => !self.method_has_self_argument,
}
}
pub fn signature<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
match self.kind {
- ty::AssociatedKind::Method => {
+ ty::AssocKind::Method => {
// We skip the binder here because the binder would deanonymize all
// late-bound regions, and we don't want method signatures to show up
// `as for<'r> fn(&'r MyType)`. Pretty-printing handles late-bound
// regions just fine, showing `fn(&MyType)`.
tcx.fn_sig(self.def_id).skip_binder().to_string()
}
- ty::AssociatedKind::Type => format!("type {};", self.ident),
- ty::AssociatedKind::Existential => format!("existential type {};", self.ident),
- ty::AssociatedKind::Const => {
+ ty::AssocKind::Type => format!("type {};", self.ident),
+ ty::AssocKind::Existential => format!("existential type {};", self.ident),
+ ty::AssocKind::Const => {
format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id))
}
}
// `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 {
/// Does this early bound region have a name? Early bound regions normally
/// always have names except when using anonymous lifetimes (`'_`).
pub fn has_name(&self) -> bool {
- self.name != keywords::UnderscoreLifetime.name().as_interned_str()
+ self.name != kw::UnderscoreLifetime.as_interned_str()
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)]
pub enum Predicate<'tcx> {
- /// Corresponds to `where Foo: Bar<A,B,C>`. `Foo` here would be
+ /// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
/// the `Self` type of the trait reference and `A`, `B`, and `C`
/// would be the type parameters.
Trait(PolyTraitPredicate<'tcx>),
- /// where `'a: 'b`
+ /// `where 'a: 'b`
RegionOutlives(PolyRegionOutlivesPredicate<'tcx>),
- /// where `T: 'a`
+ /// `where T: 'a`
TypeOutlives(PolyTypeOutlivesPredicate<'tcx>),
- /// where `<T as TraitRef>::Name == X`, approximately.
+ /// `where <T as TraitRef>::Name == X`, approximately.
/// See the `ProjectionPredicate` struct for details.
Projection(PolyProjectionPredicate<'tcx>),
/// no syntax: `T` well-formed
WellFormed(Ty<'tcx>),
- /// trait must be object-safe
+ /// Trait must be object-safe.
ObjectSafe(DefId),
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
self.trait_ref.def_id
}
- pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {
+ pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'a {
self.trait_ref.input_types()
}
}
#[inline]
- pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Lrc<GenericPredicates<'gcx>> {
+ pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> &'tcx GenericPredicates<'gcx> {
tcx.predicates_of(self.did)
}
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::Def(DefKind::TyAlias, _) | Res::Def(DefKind::AssocTy, _) | Res::SelfTy(..) |
Res::SelfCtor(..) => self.non_enum_variant(),
_ => bug!("unexpected res {:?} in variant_of_res", res)
}
pub fn discriminants(
&'a self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
- ) -> impl Iterator<Item=(VariantIdx, Discr<'tcx>)> + Captures<'gcx> + 'a {
+ ) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'gcx> + 'a {
let repr_type = self.repr.discr_type();
let initial = repr_type.initial_discriminant(tcx.global_tcx());
let mut prev_discr = None::<Discr<'tcx>>;
}
}
- pub fn provided_trait_methods(self, id: DefId) -> Vec<AssociatedItem> {
+ pub fn provided_trait_methods(self, id: DefId) -> Vec<AssocItem> {
self.associated_items(id)
- .filter(|item| item.kind == AssociatedKind::Method && item.defaultness.has_value())
+ .filter(|item| item.kind == AssocKind::Method && item.defaultness.has_value())
.collect()
}
})
}
- pub fn opt_associated_item(self, def_id: DefId) -> Option<AssociatedItem> {
+ pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
let is_associated_item = if let Some(hir_id) = self.hir().as_local_hir_id(def_id) {
match self.hir().get_by_hir_id(hir_id) {
Node::TraitItem(_) | Node::ImplItem(_) => true,
}
} else {
match self.def_kind(def_id).expect("no def for def-id") {
- DefKind::AssociatedConst
+ DefKind::AssocConst
| DefKind::Method
- | DefKind::AssociatedTy => true,
+ | DefKind::AssocTy => true,
_ => false,
}
};
parent_def_id: DefId,
parent_vis: &hir::Visibility,
trait_item_ref: &hir::TraitItemRef)
- -> AssociatedItem {
+ -> AssocItem {
let def_id = self.hir().local_def_id_from_hir_id(trait_item_ref.id.hir_id);
let (kind, has_self) = match trait_item_ref.kind {
- hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
- hir::AssociatedItemKind::Method { has_self } => {
- (ty::AssociatedKind::Method, has_self)
+ hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
+ hir::AssocItemKind::Method { has_self } => {
+ (ty::AssocKind::Method, has_self)
}
- hir::AssociatedItemKind::Type => (ty::AssociatedKind::Type, false),
- hir::AssociatedItemKind::Existential => bug!("only impls can have existentials"),
+ hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
+ hir::AssocItemKind::Existential => bug!("only impls can have existentials"),
};
- AssociatedItem {
+ AssocItem {
ident: trait_item_ref.ident,
kind,
// Visibility of trait items is inherited from their traits.
fn associated_item_from_impl_item_ref(self,
parent_def_id: DefId,
impl_item_ref: &hir::ImplItemRef)
- -> AssociatedItem {
+ -> AssocItem {
let def_id = self.hir().local_def_id_from_hir_id(impl_item_ref.id.hir_id);
let (kind, has_self) = match impl_item_ref.kind {
- hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
- hir::AssociatedItemKind::Method { has_self } => {
- (ty::AssociatedKind::Method, has_self)
+ hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
+ hir::AssocItemKind::Method { has_self } => {
+ (ty::AssocKind::Method, has_self)
}
- hir::AssociatedItemKind::Type => (ty::AssociatedKind::Type, false),
- hir::AssociatedItemKind::Existential => (ty::AssociatedKind::Existential, false),
+ hir::AssocItemKind::Type => (ty::AssocKind::Type, false),
+ hir::AssocItemKind::Existential => (ty::AssocKind::Existential, false),
};
- AssociatedItem {
+ AssocItem {
ident: impl_item_ref.ident,
kind,
// Visibility of trait impl items doesn't matter.
pub fn associated_items(
self,
def_id: DefId,
- ) -> AssociatedItemsIterator<'a, 'gcx, 'tcx> {
+ ) -> AssocItemsIterator<'a, 'gcx, 'tcx> {
// Ideally, we would use `-> impl Iterator` here, but it falls
// afoul of the conservative "capture [restrictions]" we put
// in place, so we use a hand-written iterator.
//
// [restrictions]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
- AssociatedItemsIterator {
+ AssocItemsIterator {
tcx: self,
def_ids: self.associated_item_def_ids(def_id),
next_index: 0,
}
}
- pub fn item_name(self, id: DefId) -> InternedString {
+ pub fn item_name(self, id: DefId) -> Symbol {
if id.index == CRATE_DEF_INDEX {
- self.original_crate_name(id.krate).as_interned_str()
+ self.original_crate_name(id.krate)
} else {
let def_key = self.def_key(id);
match def_key.disambiguated_data.data {
}),
_ => def_key.disambiguated_data.data.get_opt_name().unwrap_or_else(|| {
bug!("item_name: no name for {:?}", self.def_path(id));
- }),
+ }).as_symbol(),
}
}
}
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
pub fn instance_mir(self, instance: ty::InstanceDef<'gcx>)
- -> &'gcx Mir<'gcx>
+ -> &'gcx Body<'gcx>
{
match instance {
ty::InstanceDef::Item(did) => {
}
}
-pub struct AssociatedItemsIterator<'a, 'gcx: 'tcx, 'tcx: 'a> {
+pub struct AssocItemsIterator<'a, 'gcx: 'tcx, 'tcx: 'a> {
tcx: TyCtxt<'a, 'gcx, 'tcx>,
- def_ids: Lrc<Vec<DefId>>,
+ def_ids: &'gcx [DefId],
next_index: usize,
}
-impl Iterator for AssociatedItemsIterator<'_, '_, '_> {
- type Item = AssociatedItem;
+impl Iterator for AssocItemsIterator<'_, '_, '_> {
+ type Item = AssocItem;
- fn next(&mut self) -> Option<AssociatedItem> {
+ fn next(&mut self) -> Option<AssocItem> {
let def_id = self.def_ids.get(self.next_index)?;
self.next_index += 1;
Some(self.tcx.associated_item(*def_id))
}
}
-fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> AssociatedItem {
+fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> AssocItem {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let parent_id = tcx.hir().get_parent_item(id);
let parent_def_id = tcx.hir().local_def_id_from_hir_id(parent_id);
fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
- -> Lrc<Vec<DefId>> {
+ -> &'tcx [DefId] {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item = tcx.hir().expect_item_by_hir_id(id);
- let vec: Vec<_> = match item.node {
+ match item.node {
hir::ItemKind::Trait(.., ref trait_item_refs) => {
- trait_item_refs.iter()
- .map(|trait_item_ref| trait_item_ref.id)
- .map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
- .collect()
+ tcx.arena.alloc_from_iter(
+ trait_item_refs.iter()
+ .map(|trait_item_ref| trait_item_ref.id)
+ .map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
+ )
}
hir::ItemKind::Impl(.., ref impl_item_refs) => {
- impl_item_refs.iter()
- .map(|impl_item_ref| impl_item_ref.id)
- .map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
- .collect()
+ tcx.arena.alloc_from_iter(
+ impl_item_refs.iter()
+ .map(|impl_item_ref| impl_item_ref.id)
+ .map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
+ )
}
- hir::ItemKind::TraitAlias(..) => vec![],
+ hir::ItemKind::TraitAlias(..) => &[],
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait")
- };
- Lrc::new(vec)
+ }
}
fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span {
/// (constructing this map requires touching the entire crate).
#[derive(Clone, Debug, Default, HashStable)]
pub struct CrateInherentImpls {
- pub inherent_impls: DefIdMap<Lrc<Vec<DefId>>>,
+ pub inherent_impls: DefIdMap<Vec<DefId>>,
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)]
impl SymbolName {
pub fn new(name: &str) -> SymbolName {
SymbolName {
- name: Symbol::intern(name).as_interned_str()
+ name: InternedString::intern(name)
}
}