X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Fty%2Fsty.rs;h=8bfbd8b854b03589506ff74ba39a709086a3bd58;hb=007aabae930d753742f6916d91d3fc8838db08a1;hp=5cc46b21fca1f1bf27de4e57f469d89b0ee6709b;hpb=79ac25470320717db398516ecdeda0a423371a00;p=rust.git diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 5cc46b21fca..8bfbd8b854b 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -324,7 +324,7 @@ impl<'tcx> ClosureSubsts<'tcx> { /// Divides the closure substs into their respective /// components. Single source of truth with respect to the /// ordering. - fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> SplitClosureSubsts<'tcx> { + fn split(self, def_id: DefId, tcx: TyCtxt<'_>) -> SplitClosureSubsts<'tcx> { let generics = tcx.generics_of(def_id); let parent_len = generics.parent_count; SplitClosureSubsts { @@ -335,9 +335,11 @@ fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> SplitClosureSubsts<'tc } #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> - impl Iterator> + 'tcx - { + pub fn upvar_tys( + self, + def_id: DefId, + tcx: TyCtxt<'_>, + ) -> impl Iterator> + 'tcx { let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx); upvar_kinds.iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { @@ -351,7 +353,7 @@ impl Iterator> + 'tcx /// Returns the closure kind for this closure; may return a type /// variable during inference. To get the closure kind during /// inference, use `infcx.closure_kind(def_id, substs)`. - pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { self.split(def_id, tcx).closure_kind_ty } @@ -359,7 +361,7 @@ pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> /// closure; may contain type variables during inference. To get /// the closure signature during inference, use /// `infcx.fn_sig(def_id)`. - pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { self.split(def_id, tcx).closure_sig_ty } @@ -368,7 +370,7 @@ pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> /// there are no type variables. /// /// If you have an inference context, use `infcx.closure_kind()`. - pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::ClosureKind { + pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind { self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap() } @@ -377,7 +379,7 @@ pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::Clo /// there are no type variables. /// /// If you have an inference context, use `infcx.closure_sig()`. - pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::PolyFnSig<'tcx> { + pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> { let ty = self.closure_sig_ty(def_id, tcx); match ty.sty { ty::FnPtr(sig) => sig, @@ -401,7 +403,7 @@ struct SplitGeneratorSubsts<'tcx> { } impl<'tcx> GeneratorSubsts<'tcx> { - fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> SplitGeneratorSubsts<'tcx> { + fn split(self, def_id: DefId, tcx: TyCtxt<'_>) -> SplitGeneratorSubsts<'tcx> { let generics = tcx.generics_of(def_id); let parent_len = generics.parent_count; SplitGeneratorSubsts { @@ -417,14 +419,16 @@ fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> SplitGeneratorSubsts<' /// It contains a tuple of all the types that could end up on a generator frame. /// The state transformation MIR pass may only produce layouts which mention types /// in this tuple. Upvars are not counted here. - pub fn witness(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn witness(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { self.split(def_id, tcx).witness } #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> - impl Iterator> + 'tcx - { + pub fn upvar_tys( + self, + def_id: DefId, + tcx: TyCtxt<'_>, + ) -> impl Iterator> + 'tcx { let SplitGeneratorSubsts { upvar_kinds, .. } = self.split(def_id, tcx); upvar_kinds.iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { @@ -436,12 +440,12 @@ impl Iterator> + 'tcx } /// Returns the type representing the yield type of the generator. - pub fn yield_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn yield_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { self.split(def_id, tcx).yield_ty } /// Returns the type representing the return type of the generator. - pub fn return_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn return_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { self.split(def_id, tcx).return_ty } @@ -451,13 +455,13 @@ pub fn return_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { /// N.B., some bits of the code prefers to see this wrapped in a /// binder, but it never contains bound regions. Probably this /// function should be removed. - pub fn poly_sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> PolyGenSig<'tcx> { + pub fn poly_sig(self, def_id: DefId, tcx: TyCtxt<'_>) -> PolyGenSig<'tcx> { ty::Binder::dummy(self.sig(def_id, tcx)) } /// Returns the "generator signature", which consists of its yield /// and return types. - pub fn sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> GenSig<'tcx> { + pub fn sig(self, def_id: DefId, tcx: TyCtxt<'_>) -> GenSig<'tcx> { ty::GenSig { yield_ty: self.yield_ty(def_id, tcx), return_ty: self.return_ty(def_id, tcx), @@ -465,7 +469,7 @@ pub fn sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> GenSig<'tcx> { } } -impl<'a, 'gcx, 'tcx> GeneratorSubsts<'tcx> { +impl<'tcx> GeneratorSubsts<'tcx> { /// Generator have not been resumed yet pub const UNRESUMED: usize = 0; /// Generator has returned / is completed @@ -479,7 +483,7 @@ impl<'a, 'gcx, 'tcx> GeneratorSubsts<'tcx> { /// The valid variant indices of this Generator. #[inline] - pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Range { + pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range { // FIXME requires optimized MIR let num_variants = tcx.generator_layout(def_id).variant_fields.len(); (VariantIdx::new(0)..VariantIdx::new(num_variants)) @@ -489,7 +493,10 @@ pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Range /// out of range. #[inline] pub fn discriminant_for_variant( - &self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>, variant_index: VariantIdx + &self, + def_id: DefId, + tcx: TyCtxt<'tcx>, + variant_index: VariantIdx, ) -> Discr<'tcx> { // Generators don't support explicit discriminant values, so they are // the same as the variant index. @@ -501,8 +508,10 @@ pub fn discriminant_for_variant( /// variant indices. #[inline] pub fn discriminants( - &'a self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx> - ) -> impl Iterator)> + Captures<'gcx> + 'a { + &'tcx self, + def_id: DefId, + tcx: TyCtxt<'tcx>, + ) -> impl Iterator)> + Captures<'tcx> { self.variant_range(def_id, tcx).map(move |index| { (index, Discr { val: index.as_usize() as u128, ty: self.discr_ty(tcx) }) }) @@ -522,7 +531,7 @@ pub fn variant_name(&self, v: VariantIdx) -> Cow<'static, str> { /// The type of the state discriminant used in the generator type. #[inline] - pub fn discr_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn discr_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { tcx.types.u32 } @@ -533,9 +542,11 @@ pub fn discr_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { /// The locals are grouped by their variant number. Note that some locals may /// be repeated in multiple variants. #[inline] - pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> - impl Iterator> + Captures<'gcx> + 'a> - { + pub fn state_tys( + self, + def_id: DefId, + tcx: TyCtxt<'tcx>, + ) -> impl Iterator> + Captures<'tcx>> { let layout = tcx.generator_layout(def_id); layout.variant_fields.iter().map(move |variant| { variant.iter().map(move |field| { @@ -547,9 +558,7 @@ impl Iterator> + Captures<'gcx> + 'a> /// This is the types of the fields of a generator which are not stored in a /// variant. #[inline] - pub fn prefix_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> - impl Iterator> + 'a - { + pub fn prefix_tys(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> impl Iterator> { self.upvar_tys(def_id, tcx) } } @@ -562,9 +571,11 @@ pub enum UpvarSubsts<'tcx> { impl<'tcx> UpvarSubsts<'tcx> { #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> - impl Iterator> + 'tcx - { + pub fn upvar_tys( + self, + def_id: DefId, + tcx: TyCtxt<'_>, + ) -> impl Iterator> + 'tcx { let upvar_kinds = match self { UpvarSubsts::Closure(substs) => substs.split(def_id, tcx).upvar_kinds, UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds, @@ -590,10 +601,10 @@ pub enum ExistentialPredicate<'tcx> { AutoTrait(DefId), } -impl<'a, 'gcx, 'tcx> ExistentialPredicate<'tcx> { +impl<'tcx> ExistentialPredicate<'tcx> { /// Compares via an ordering that will not change if modules are reordered or other changes are /// made to the tree. In particular, this ordering is preserved across incremental compilations. - pub fn stable_cmp(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, other: &Self) -> Ordering { + pub fn stable_cmp(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Ordering { use self::ExistentialPredicate::*; match (*self, *other) { (Trait(_), Trait(_)) => Ordering::Equal, @@ -607,12 +618,10 @@ pub fn stable_cmp(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, other: &Self) -> Ordering (AutoTrait(_), _) => Ordering::Greater, } } - } -impl<'a, 'gcx, 'tcx> Binder> { - pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self_ty: Ty<'tcx>) - -> ty::Predicate<'tcx> { +impl<'tcx> Binder> { + pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> { use crate::ty::ToPredicate; match *self.skip_binder() { ExistentialPredicate::Trait(tr) => Binder(tr).with_self_ty(tcx, self_ty).to_predicate(), @@ -744,7 +753,7 @@ pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> TraitRef<'tcx> { /// Returns a `TraitRef` of the form `P0: Foo` where `Pi` /// are the parameters defined on trait. - pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> { + pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> TraitRef<'tcx> { TraitRef { def_id, substs: InternalSubsts::identity_for_item(tcx, def_id), @@ -764,10 +773,11 @@ pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator> + self.substs.types() } - pub fn from_method(tcx: TyCtxt<'_, '_, 'tcx>, - trait_id: DefId, - substs: SubstsRef<'tcx>) - -> ty::TraitRef<'tcx> { + pub fn from_method( + tcx: TyCtxt<'tcx>, + trait_id: DefId, + substs: SubstsRef<'tcx>, + ) -> ty::TraitRef<'tcx> { let defs = tcx.generics_of(trait_id); ty::TraitRef { @@ -808,7 +818,7 @@ pub struct ExistentialTraitRef<'tcx> { pub substs: SubstsRef<'tcx>, } -impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> { +impl<'tcx> ExistentialTraitRef<'tcx> { pub fn input_types<'b>(&'b self) -> impl DoubleEndedIterator> + 'b { // Select only the "input types" from a trait-reference. For // now this is all the types that appear in the @@ -817,9 +827,10 @@ pub fn input_types<'b>(&'b self) -> impl DoubleEndedIterator> + 'b self.substs.types() } - pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>, - trait_ref: ty::TraitRef<'tcx>) - -> ty::ExistentialTraitRef<'tcx> { + pub fn erase_self_ty( + tcx: TyCtxt<'tcx>, + trait_ref: ty::TraitRef<'tcx>, + ) -> ty::ExistentialTraitRef<'tcx> { // Assert there is a Self. trait_ref.substs.type_at(0); @@ -833,8 +844,7 @@ pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>, /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self_ty: Ty<'tcx>) - -> ty::TraitRef<'tcx> { + pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::TraitRef<'tcx> { // otherwise the escaping vars would be captured by the binder // debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -856,9 +866,7 @@ pub fn def_id(&self) -> DefId { /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(&self, tcx: TyCtxt<'_, '_, 'tcx>, - self_ty: Ty<'tcx>) - -> ty::PolyTraitRef<'tcx> { + pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::PolyTraitRef<'tcx> { self.map_bound(|trait_ref| trait_ref.with_self_ty(tcx, self_ty)) } } @@ -886,7 +894,7 @@ pub fn dummy<'tcx>(value: T) -> Binder } /// Wraps `value` in a binder, binding higher-ranked vars (if any). - pub fn bind<'tcx>(value: T) -> Binder { + pub fn bind(value: T) -> Binder { Binder(value) } @@ -988,11 +996,13 @@ pub struct ProjectionTy<'tcx> { pub item_def_id: DefId, } -impl<'a, 'tcx> ProjectionTy<'tcx> { +impl<'tcx> ProjectionTy<'tcx> { /// Construct a `ProjectionTy` by searching the trait from `trait_ref` for the /// associated item named `item_name`. pub fn from_ref_and_name( - tcx: TyCtxt<'_, '_, '_>, trait_ref: ty::TraitRef<'tcx>, item_name: Ident + 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::AssocKind::Type && @@ -1008,7 +1018,7 @@ pub fn from_ref_and_name( /// Extracts the underlying trait reference from this projection. /// For example, if this is a projection of `::Item`, /// then this function would return a `T: Iterator` trait reference. - pub fn trait_ref(&self, tcx: TyCtxt<'_, '_, '_>) -> ty::TraitRef<'tcx> { + pub fn trait_ref(&self, tcx: TyCtxt<'_>) -> ty::TraitRef<'tcx> { let def_id = tcx.associated_item(self.item_def_id).container.id(); ty::TraitRef { def_id, @@ -1112,7 +1122,7 @@ pub struct ParamTy { pub name: InternedString, } -impl<'a, 'gcx, 'tcx> ParamTy { +impl<'tcx> ParamTy { pub fn new(index: u32, name: InternedString) -> ParamTy { ParamTy { index, name: name } } @@ -1125,7 +1135,7 @@ pub fn for_def(def: &ty::GenericParamDef) -> ParamTy { ParamTy::new(def.index, def.name) } - pub fn to_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { tcx.mk_ty_param(self.index, self.name) } @@ -1144,7 +1154,7 @@ pub struct ParamConst { pub name: InternedString, } -impl<'a, 'gcx, 'tcx> ParamConst { +impl<'tcx> ParamConst { pub fn new(index: u32, name: InternedString) -> ParamConst { ParamConst { index, name } } @@ -1153,7 +1163,7 @@ pub fn for_def(def: &ty::GenericParamDef) -> ParamConst { ParamConst::new(def.index, def.name) } - pub fn to_const(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, ty: Ty<'tcx>) -> &'tcx Const<'tcx> { + pub fn to_const(self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> &'tcx Const<'tcx> { tcx.mk_const_param(self.index, self.name, ty) } } @@ -1408,12 +1418,12 @@ pub struct ExistentialProjection<'tcx> { pub type PolyExistentialProjection<'tcx> = Binder>; -impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> { +impl<'tcx> ExistentialProjection<'tcx> { /// Extracts the underlying existential trait reference from this projection. /// For example, if this is a projection of `exists T. ::Item == X`, /// then this function would return a `exists T. T: Iterator` existential trait /// reference. - pub fn trait_ref(&self, tcx: TyCtxt<'_, '_, '_>) -> ty::ExistentialTraitRef<'tcx> { + pub fn trait_ref(&self, tcx: TyCtxt<'_>) -> ty::ExistentialTraitRef<'tcx> { let def_id = tcx.associated_item(self.item_def_id).container.id(); ty::ExistentialTraitRef{ def_id, @@ -1421,10 +1431,11 @@ pub fn trait_ref(&self, tcx: TyCtxt<'_, '_, '_>) -> ty::ExistentialTraitRef<'tcx } } - pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - self_ty: Ty<'tcx>) - -> ty::ProjectionPredicate<'tcx> - { + pub fn with_self_ty( + &self, + tcx: TyCtxt<'tcx>, + self_ty: Ty<'tcx>, + ) -> ty::ProjectionPredicate<'tcx> { // otherwise the escaping regions would be captured by the binders debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -1438,9 +1449,12 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, } } -impl<'a, 'tcx, 'gcx> PolyExistentialProjection<'tcx> { - pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self_ty: Ty<'tcx>) - -> ty::PolyProjectionPredicate<'tcx> { +impl<'tcx> PolyExistentialProjection<'tcx> { + pub fn with_self_ty( + &self, + tcx: TyCtxt<'tcx>, + self_ty: Ty<'tcx>, + ) -> ty::PolyProjectionPredicate<'tcx> { self.map_bound(|p| p.with_self_ty(tcx, self_ty)) } @@ -1652,7 +1666,7 @@ pub fn type_flags(&self) -> TypeFlags { /// of the impl, and for all the other highlighted regions, it /// would return the `DefId` of the function. In other cases (not shown), this /// function might return the `DefId` of a closure. - pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_, '_, '_>) -> DefId { + pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_>) -> DefId { match self { ty::ReEarlyBound(br) => { tcx.parent(br.def_id).unwrap() @@ -1664,7 +1678,8 @@ pub fn free_region_binding_scope(&self, tcx: TyCtxt<'_, '_, '_>) -> DefId { } /// Type utilities -impl<'a, 'gcx, 'tcx> TyS<'tcx> { +impl<'tcx> TyS<'tcx> { + #[inline] pub fn is_unit(&self) -> bool { match self.sty { Tuple(ref tys) => tys.is_empty(), @@ -1672,6 +1687,7 @@ pub fn is_unit(&self) -> bool { } } + #[inline] pub fn is_never(&self) -> bool { match self.sty { Never => true, @@ -1685,7 +1701,7 @@ pub fn is_never(&self) -> bool { /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty` /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero /// size, to account for partial initialisation. See #49298 for details.) - pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool { + pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'tcx>) -> bool { // FIXME(varkor): we can make this less conversative by substituting concrete // type arguments. match self.sty { @@ -1726,6 +1742,7 @@ pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) } } + #[inline] pub fn is_primitive(&self) -> bool { match self.sty { Bool | Char | Int(_) | Uint(_) | Float(_) => true, @@ -1741,6 +1758,7 @@ pub fn is_ty_var(&self) -> bool { } } + #[inline] pub fn is_ty_infer(&self) -> bool { match self.sty { Infer(_) => true, @@ -1748,6 +1766,7 @@ pub fn is_ty_infer(&self) -> bool { } } + #[inline] pub fn is_phantom_data(&self) -> bool { if let Adt(def, _) = self.sty { def.is_phantom_data() @@ -1756,8 +1775,10 @@ pub fn is_phantom_data(&self) -> bool { } } + #[inline] pub fn is_bool(&self) -> bool { self.sty == Bool } + #[inline] pub fn is_param(&self, index: u32) -> bool { match self.sty { ty::Param(ref data) => data.index == index, @@ -1765,6 +1786,7 @@ pub fn is_param(&self, index: u32) -> bool { } } + #[inline] pub fn is_self(&self) -> bool { match self.sty { Param(ref p) => p.is_self(), @@ -1772,6 +1794,7 @@ pub fn is_self(&self) -> bool { } } + #[inline] pub fn is_slice(&self) -> bool { match self.sty { RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => match ty.sty { @@ -1790,7 +1813,7 @@ pub fn is_simd(&self) -> bool { } } - pub fn sequence_element_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn sequence_element_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self.sty { Array(ty, _) | Slice(ty) => ty, Str => tcx.mk_mach_uint(ast::UintTy::U8), @@ -1798,7 +1821,7 @@ pub fn sequence_element_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { } } - pub fn simd_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn simd_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self.sty { Adt(def, substs) => { def.non_enum_variant().fields[0].ty(tcx, substs) @@ -1807,13 +1830,14 @@ pub fn simd_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { } } - pub fn simd_size(&self, _cx: TyCtxt<'_, '_, '_>) -> usize { + pub fn simd_size(&self, _cx: TyCtxt<'_>) -> usize { match self.sty { Adt(def, _) => def.non_enum_variant().fields.len(), _ => bug!("simd_size called on invalid type") } } + #[inline] pub fn is_region_ptr(&self) -> bool { match self.sty { Ref(..) => true, @@ -1821,6 +1845,7 @@ pub fn is_region_ptr(&self) -> bool { } } + #[inline] pub fn is_mutable_pointer(&self) -> bool { match self.sty { RawPtr(TypeAndMut { mutbl: hir::Mutability::MutMutable, .. }) | @@ -1829,6 +1854,7 @@ pub fn is_mutable_pointer(&self) -> bool { } } + #[inline] pub fn is_unsafe_ptr(&self) -> bool { match self.sty { RawPtr(_) => return true, @@ -1837,6 +1863,7 @@ pub fn is_unsafe_ptr(&self) -> bool { } /// Returns `true` if this type is an `Arc`. + #[inline] pub fn is_arc(&self) -> bool { match self.sty { Adt(def, _) => def.is_arc(), @@ -1845,6 +1872,7 @@ pub fn is_arc(&self) -> bool { } /// Returns `true` if this type is an `Rc`. + #[inline] pub fn is_rc(&self) -> bool { match self.sty { Adt(def, _) => def.is_rc(), @@ -1852,6 +1880,7 @@ pub fn is_rc(&self) -> bool { } } + #[inline] pub fn is_box(&self) -> bool { match self.sty { Adt(def, _) => def.is_box(), @@ -1870,6 +1899,7 @@ pub fn boxed_ty(&self) -> Ty<'tcx> { /// A scalar type is one that denotes an atomic datum, with no sub-components. /// (A RawPtr is scalar because it represents a non-managed pointer, so its /// contents are abstract to rustc.) + #[inline] pub fn is_scalar(&self) -> bool { match self.sty { Bool | Char | Int(_) | Float(_) | Uint(_) | @@ -1880,6 +1910,7 @@ pub fn is_scalar(&self) -> bool { } /// Returns `true` if this type is a floating point type. + #[inline] pub fn is_floating_point(&self) -> bool { match self.sty { Float(_) | @@ -1888,6 +1919,7 @@ pub fn is_floating_point(&self) -> bool { } } + #[inline] pub fn is_trait(&self) -> bool { match self.sty { Dynamic(..) => true, @@ -1895,6 +1927,7 @@ pub fn is_trait(&self) -> bool { } } + #[inline] pub fn is_enum(&self) -> bool { match self.sty { Adt(adt_def, _) => { @@ -1904,6 +1937,7 @@ pub fn is_enum(&self) -> bool { } } + #[inline] pub fn is_closure(&self) -> bool { match self.sty { Closure(..) => true, @@ -1911,6 +1945,7 @@ pub fn is_closure(&self) -> bool { } } + #[inline] pub fn is_generator(&self) -> bool { match self.sty { Generator(..) => true, @@ -1926,6 +1961,7 @@ pub fn is_integral(&self) -> bool { } } + #[inline] pub fn is_fresh_ty(&self) -> bool { match self.sty { Infer(FreshTy(_)) => true, @@ -1933,6 +1969,7 @@ pub fn is_fresh_ty(&self) -> bool { } } + #[inline] pub fn is_fresh(&self) -> bool { match self.sty { Infer(FreshTy(_)) => true, @@ -1942,6 +1979,7 @@ pub fn is_fresh(&self) -> bool { } } + #[inline] pub fn is_char(&self) -> bool { match self.sty { Char => true, @@ -1950,17 +1988,11 @@ pub fn is_char(&self) -> bool { } #[inline] - pub fn is_fp(&self) -> bool { - match self.sty { - Infer(FloatVar(_)) | Float(_) => true, - _ => false - } - } - pub fn is_numeric(&self) -> bool { - self.is_integral() || self.is_fp() + self.is_integral() || self.is_floating_point() } + #[inline] pub fn is_signed(&self) -> bool { match self.sty { Int(_) => true, @@ -1968,6 +2000,7 @@ pub fn is_signed(&self) -> bool { } } + #[inline] pub fn is_pointer_sized(&self) -> bool { match self.sty { Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => true, @@ -1975,6 +2008,7 @@ pub fn is_pointer_sized(&self) -> bool { } } + #[inline] pub fn is_machine(&self) -> bool { match self.sty { Int(..) | Uint(..) | Float(..) => true, @@ -1982,6 +2016,7 @@ pub fn is_machine(&self) -> bool { } } + #[inline] pub fn has_concrete_skeleton(&self) -> bool { match self.sty { Param(_) | Infer(_) | Error => false, @@ -2015,7 +2050,7 @@ pub fn builtin_index(&self) -> Option> { } } - pub fn fn_sig(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> PolyFnSig<'tcx> { + pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> { match self.sty { FnDef(def_id, substs) => { tcx.fn_sig(def_id).subst(tcx, substs) @@ -2028,6 +2063,7 @@ pub fn fn_sig(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> PolyFnSig<'tcx> { } } + #[inline] pub fn is_fn(&self) -> bool { match self.sty { FnDef(..) | FnPtr(_) => true, @@ -2043,6 +2079,7 @@ pub fn is_fn_ptr(&self) -> bool { } } + #[inline] pub fn is_impl_trait(&self) -> bool { match self.sty { Opaque(..) => true, @@ -2061,7 +2098,7 @@ pub fn ty_adt_def(&self) -> Option<&'tcx AdtDef> { /// If the type contains variants, returns the valid range of variant indices. /// FIXME This requires the optimized MIR in the case of generators. #[inline] - pub fn variant_range(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option> { + pub fn variant_range(&self, tcx: TyCtxt<'tcx>) -> Option> { match self.sty { TyKind::Adt(adt, _) => Some(adt.variant_range()), TyKind::Generator(def_id, substs, _) => Some(substs.variant_range(def_id, tcx)), @@ -2075,8 +2112,8 @@ pub fn variant_range(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option, - variant_index: VariantIdx + tcx: TyCtxt<'tcx>, + variant_index: VariantIdx, ) -> Option> { match self.sty { TyKind::Adt(adt, _) => Some(adt.discriminant_for_variant(tcx, variant_index)), @@ -2166,7 +2203,7 @@ pub fn to_opt_closure_kind(&self) -> Option { /// /// Returning true means the type is known to be sized. Returning /// `false` means nothing -- could be sized, might not be. - pub fn is_trivially_sized(&self, tcx: TyCtxt<'_, '_, 'tcx>) -> bool { + pub fn is_trivially_sized(&self, tcx: TyCtxt<'tcx>) -> bool { match self.sty { ty::Infer(ty::IntVar(_)) | ty::Infer(ty::FloatVar(_)) | ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Float(_) | @@ -2216,11 +2253,7 @@ pub struct Const<'tcx> { impl<'tcx> Const<'tcx> { #[inline] - pub fn from_scalar( - tcx: TyCtxt<'_, '_, 'tcx>, - val: Scalar, - ty: Ty<'tcx>, - ) -> &'tcx Self { + pub fn from_scalar(tcx: TyCtxt<'tcx>, val: Scalar, ty: Ty<'tcx>) -> &'tcx Self { tcx.mk_const(Self { val: ConstValue::Scalar(val), ty, @@ -2228,12 +2261,7 @@ pub fn from_scalar( } #[inline] - pub fn from_bits( - tcx: TyCtxt<'_, '_, 'tcx>, - bits: u128, - ty: ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> &'tcx Self { - let ty = tcx.lift_to_global(&ty).unwrap(); + pub fn from_bits(tcx: TyCtxt<'tcx>, bits: u128, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> &'tcx Self { let size = tcx.layout_of(ty).unwrap_or_else(|e| { panic!("could not compute layout for {:?}: {:?}", ty, e) }).size; @@ -2241,30 +2269,25 @@ pub fn from_bits( } #[inline] - pub fn zero_sized(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) -> &'tcx Self { + 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) -> &'tcx 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) -> &'tcx 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)) } #[inline] - pub fn to_bits( - &self, - tcx: TyCtxt<'_, '_, 'tcx>, - ty: ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Option { + pub fn to_bits(&self, tcx: TyCtxt<'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option { if self.ty != ty.value { return None; } - let ty = tcx.lift_to_global(&ty).unwrap(); let size = tcx.layout_of(ty).ok()?.size; self.val.try_to_bits(size) } @@ -2275,19 +2298,14 @@ pub fn to_ptr(&self) -> Option { } #[inline] - pub fn assert_bits( - &self, - tcx: TyCtxt<'_, '_, '_>, - ty: ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Option { + pub fn assert_bits(&self, tcx: TyCtxt<'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Option { assert_eq!(self.ty, ty.value); - let ty = tcx.lift_to_global(&ty).unwrap(); let size = tcx.layout_of(ty).ok()?.size; self.val.try_to_bits(size) } #[inline] - pub fn assert_bool(&self, tcx: TyCtxt<'_, '_, '_>) -> Option { + pub fn assert_bool(&self, tcx: TyCtxt<'tcx>) -> Option { self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.bool)).and_then(|v| match v { 0 => Some(false), 1 => Some(true), @@ -2296,22 +2314,18 @@ pub fn assert_bool(&self, tcx: TyCtxt<'_, '_, '_>) -> Option { } #[inline] - pub fn assert_usize(&self, tcx: TyCtxt<'_, '_, '_>) -> Option { + pub fn assert_usize(&self, tcx: TyCtxt<'tcx>) -> Option { self.assert_bits(tcx, ParamEnv::empty().and(tcx.types.usize)).map(|v| v as u64) } #[inline] - pub fn unwrap_bits( - &self, - tcx: TyCtxt<'_, '_, '_>, - ty: ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> u128 { + pub fn unwrap_bits(&self, tcx: TyCtxt<'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> u128 { self.assert_bits(tcx, ty).unwrap_or_else(|| bug!("expected bits of {}, got {:#?}", ty.value, self)) } #[inline] - pub fn unwrap_usize(&self, tcx: TyCtxt<'_, '_, '_>) -> u64 { + pub fn unwrap_usize(&self, tcx: TyCtxt<'tcx>) -> u64 { self.assert_usize(tcx).unwrap_or_else(|| bug!("expected constant usize, got {:#?}", self)) }