use crate::ty::subst::{InternalSubsts, Subst, SubstsRef, GenericArg, GenericArgKind};
use crate::ty::{self, AdtDef, Discr, DefIdTree, TypeFlags, Ty, TyCtxt, TypeFoldable};
use crate::ty::{List, TyS, ParamEnvAnd, ParamEnv};
-use crate::ty::layout::{Size, Integer, IntegerExt, VariantIdx};
+use crate::ty::layout::VariantIdx;
use crate::util::captures::Captures;
use crate::mir::interpret::{Scalar, GlobalId};
use std::ops::Range;
use rustc_target::spec::abi;
use syntax::ast::{self, Ident};
-use syntax::attr::{SignedInt, UnsignedInt};
use syntax::symbol::{kw, InternedString};
use self::InferTy::*;
/// variant indices.
#[inline]
pub fn discriminants(
- &'tcx self,
+ self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
/// Calls `f` with a reference to the name of the enumerator for the given
/// variant `v`.
#[inline]
- pub fn variant_name(&self, v: VariantIdx) -> Cow<'static, str> {
+ pub fn variant_name(self, v: VariantIdx) -> Cow<'static, str> {
match v.as_usize() {
Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME),
Self::RETURNED => Cow::from(Self::RETURNED_NAME),
#[derive(Debug, Copy, Clone)]
pub enum UpvarSubsts<'tcx> {
Closure(SubstsRef<'tcx>),
- Generator(GeneratorSubsts<'tcx>),
+ Generator(SubstsRef<'tcx>),
}
impl<'tcx> UpvarSubsts<'tcx> {
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let upvar_kinds = match self {
UpvarSubsts::Closure(substs) => substs.as_closure().split(def_id, tcx).upvar_kinds,
- UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds,
+ UpvarSubsts::Generator(substs) => substs.as_generator().split(def_id, tcx).upvar_kinds,
};
upvar_kinds.iter().map(|t| {
if let GenericArgKind::Type(ty) = t.unpack() {
ty: Ty<'tcx>,
) -> Option<u128> {
assert_eq!(self.ty, ty);
- // This is purely an optimization -- layout_of is a pretty expensive operation,
- // but if we can determine the size without calling it, we don't need all that complexity
- // (hashing, caching, etc.). As such, try to skip it.
- let size = match ty.kind {
- ty::Bool => Size::from_bytes(1),
- ty::Char => Size::from_bytes(4),
- ty::Int(ity) => {
- Integer::from_attr(&tcx, SignedInt(ity)).size()
- }
- ty::Uint(uty) => {
- Integer::from_attr(&tcx, UnsignedInt(uty)).size()
- }
- _ => tcx.layout_of(param_env.with_reveal_all().and(ty)).ok()?.size,
- };
+ let size = tcx.layout_of(param_env.with_reveal_all().and(ty)).ok()?.size;
// if `ty` does not depend on generic parameters, use an empty param_env
self.eval(tcx, param_env).val.try_to_bits(size)
}