X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Fty%2Fsty.rs;h=ddc4bd3f9f6c3c057cd918147a6eef1937be875e;hb=8f34a50cc5bb94f7d3381ec00ed273af68724a4b;hp=e8f3bad4d3ee32832666fd66f72f4cc502707da8;hpb=1c4582c1ffb441e2b55871e14c1b755e85a2f78f;p=rust.git diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index e8f3bad4d3e..ddc4bd3f9f6 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -3,7 +3,7 @@ use crate::hir; use crate::hir::def_id::DefId; use crate::infer::canonical::Canonical; -use crate::mir::interpret::{ConstValue, truncate}; +use crate::mir::interpret::ConstValue; use crate::middle::region; use polonius_engine::Atom; use rustc_data_structures::indexed_vec::Idx; @@ -22,7 +22,7 @@ use std::ops::Range; use rustc_target::spec::abi; use syntax::ast::{self, Ident}; -use syntax::symbol::{keywords, InternedString}; +use syntax::symbol::{kw, InternedString}; use serialize; use self::InferTy::*; @@ -56,9 +56,6 @@ pub enum BoundRegion { /// the event of shadowing. BrNamed(DefId, InternedString), - /// Fresh bound identifiers created during GLB computations. - BrFresh(u32), - /// Anonymous region for the implicit env pointer parameter /// to a closure BrEnv, @@ -998,7 +995,7 @@ pub fn from_ref_and_name( tcx: TyCtxt<'_, '_, '_>, trait_ref: ty::TraitRef<'tcx>, item_name: Ident ) -> ProjectionTy<'tcx> { let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| { - item.kind == ty::AssociatedKind::Type && + item.kind == ty::AssocKind::Type && tcx.hygienic_eq(item_name, item.ident, trait_ref.def_id) }).unwrap().def_id; @@ -1121,7 +1118,7 @@ pub fn new(index: u32, name: InternedString) -> ParamTy { } pub fn for_self() -> ParamTy { - ParamTy::new(0, keywords::SelfUpper.name().as_interned_str()) + ParamTy::new(0, kw::SelfUpper.as_interned_str()) } pub fn for_def(def: &ty::GenericParamDef) -> ParamTy { @@ -1136,7 +1133,7 @@ pub fn is_self(&self) -> bool { // FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere, // but this should only be possible when using `-Z continue-parse-after-error` like // `compile-fail/issue-36638.rs`. - self.name.as_symbol() == keywords::SelfUpper.name() && self.index == 0 + self.name.as_symbol() == kw::SelfUpper && self.index == 0 } } @@ -2207,18 +2204,19 @@ pub struct Const<'tcx> { } #[cfg(target_arch = "x86_64")] -static_assert_size!(Const<'_>, 48); +static_assert_size!(Const<'_>, 40); impl<'tcx> Const<'tcx> { #[inline] pub fn from_scalar( + tcx: TyCtxt<'_, '_, 'tcx>, val: Scalar, ty: Ty<'tcx>, - ) -> Self { - Self { + ) -> &'tcx Self { + tcx.mk_const(Self { val: ConstValue::Scalar(val), ty, - } + }) } #[inline] @@ -2226,28 +2224,26 @@ pub fn from_bits( tcx: TyCtxt<'_, '_, 'tcx>, bits: u128, ty: ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Self { + ) -> &'tcx Self { let ty = tcx.lift_to_global(&ty).unwrap(); let size = tcx.layout_of(ty).unwrap_or_else(|e| { panic!("could not compute layout for {:?}: {:?}", ty, e) }).size; - let truncated = truncate(bits, size); - assert_eq!(truncated, bits, "from_bits called with untruncated value"); - Self::from_scalar(Scalar::Bits { bits, size: size.bytes() as u8 }, ty.value) + Self::from_scalar(tcx, Scalar::from_uint(bits, size), ty.value) } #[inline] - pub fn zero_sized(ty: Ty<'tcx>) -> Self { - Self::from_scalar(Scalar::Bits { bits: 0, size: 0 }, ty) + pub fn zero_sized(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) -> &'tcx Self { + Self::from_scalar(tcx, Scalar::zst(), ty) } #[inline] - pub fn from_bool(tcx: TyCtxt<'_, '_, 'tcx>, v: bool) -> Self { + pub fn from_bool(tcx: TyCtxt<'_, '_, 'tcx>, v: bool) -> &'tcx Self { Self::from_bits(tcx, v as u128, ParamEnv::empty().and(tcx.types.bool)) } #[inline] - pub fn from_usize(tcx: TyCtxt<'_, '_, 'tcx>, n: u64) -> Self { + pub fn from_usize(tcx: TyCtxt<'_, '_, 'tcx>, n: u64) -> &'tcx Self { Self::from_bits(tcx, n as u128, ParamEnv::empty().and(tcx.types.usize)) }