@@ -1011,41 +1011,52 @@ pub enum BoundRegion {
10111011 BrEnv
10121012}
10131013
1014- mod primitives {
1015- use super :: TyS ;
1016-
1017- use syntax:: ast;
1014+ #[ inline]
1015+ pub fn mk_prim_t < ' tcx > ( primitive : & ' tcx TyS < ' static > ) -> Ty < ' tcx > {
1016+ // FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx.
1017+ unsafe { & * ( primitive as * const _ as * const TyS < ' tcx > ) }
1018+ }
10181019
1019- macro_rules! def_prim_ty(
1020- ( $name: ident, $sty: expr) => (
1021- pub static $name: TyS <' static > = TyS {
1020+ // Do not change these from static to const, interning types requires
1021+ // the primitives to have a significant address.
1022+ macro_rules! def_prim_tys(
1023+ ( $( $name: ident -> $sty: expr; ) * ) => (
1024+ $( #[ inline] pub fn $name<' tcx>( ) -> Ty <' tcx> {
1025+ static PRIM_TY : TyS <' static > = TyS {
10221026 sty: $sty,
1023- flags: super :: NO_TYPE_FLAGS ,
1027+ flags: NO_TYPE_FLAGS ,
10241028 region_depth: 0 ,
10251029 } ;
1026- )
1030+ mk_prim_t( & PRIM_TY )
1031+ } ) *
10271032 )
1033+ )
1034+
1035+ def_prim_tys ! {
1036+ mk_bool -> ty_bool;
1037+ mk_char -> ty_char;
1038+ mk_int -> ty_int( ast:: TyI ) ;
1039+ mk_i8 -> ty_int( ast:: TyI8 ) ;
1040+ mk_i16 -> ty_int( ast:: TyI16 ) ;
1041+ mk_i32 -> ty_int( ast:: TyI32 ) ;
1042+ mk_i64 -> ty_int( ast:: TyI64 ) ;
1043+ mk_uint -> ty_uint( ast:: TyU ) ;
1044+ mk_u8 -> ty_uint( ast:: TyU8 ) ;
1045+ mk_u16 -> ty_uint( ast:: TyU16 ) ;
1046+ mk_u32 -> ty_uint( ast:: TyU32 ) ;
1047+ mk_u64 -> ty_uint( ast:: TyU64 ) ;
1048+ mk_f32 -> ty_float( ast:: TyF32 ) ;
1049+ mk_f64 -> ty_float( ast:: TyF64 ) ;
1050+ }
10281051
1029- def_prim_ty ! ( TY_BOOL , super :: ty_bool)
1030- def_prim_ty ! ( TY_CHAR , super :: ty_char)
1031- def_prim_ty ! ( TY_INT , super :: ty_int( ast:: TyI ) )
1032- def_prim_ty ! ( TY_I8 , super :: ty_int( ast:: TyI8 ) )
1033- def_prim_ty ! ( TY_I16 , super :: ty_int( ast:: TyI16 ) )
1034- def_prim_ty ! ( TY_I32 , super :: ty_int( ast:: TyI32 ) )
1035- def_prim_ty ! ( TY_I64 , super :: ty_int( ast:: TyI64 ) )
1036- def_prim_ty ! ( TY_UINT , super :: ty_uint( ast:: TyU ) )
1037- def_prim_ty ! ( TY_U8 , super :: ty_uint( ast:: TyU8 ) )
1038- def_prim_ty ! ( TY_U16 , super :: ty_uint( ast:: TyU16 ) )
1039- def_prim_ty ! ( TY_U32 , super :: ty_uint( ast:: TyU32 ) )
1040- def_prim_ty ! ( TY_U64 , super :: ty_uint( ast:: TyU64 ) )
1041- def_prim_ty ! ( TY_F32 , super :: ty_float( ast:: TyF32 ) )
1042- def_prim_ty ! ( TY_F64 , super :: ty_float( ast:: TyF64 ) )
1043-
1044- pub static TY_ERR : TyS < ' static > = TyS {
1045- sty : super :: ty_err,
1046- flags : super :: HAS_TY_ERR ,
1052+ #[ inline]
1053+ pub fn mk_err < ' tcx > ( ) -> Ty < ' tcx > {
1054+ static TY_ERR : TyS < ' static > = TyS {
1055+ sty : ty_err,
1056+ flags : HAS_TY_ERR ,
10471057 region_depth : 0 ,
10481058 } ;
1059+ mk_prim_t ( & TY_ERR )
10491060}
10501061
10511062// NB: If you change this, you'll probably want to change the corresponding
@@ -1973,54 +1984,6 @@ impl FlagComputation {
19731984 }
19741985}
19751986
1976- #[ inline]
1977- pub fn mk_prim_t < ' tcx > ( primitive : & ' tcx TyS < ' static > ) -> Ty < ' tcx > {
1978- // FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx.
1979- unsafe { & * ( primitive as * const _ as * const TyS < ' tcx > ) }
1980- }
1981-
1982- #[ inline]
1983- pub fn mk_err < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_ERR ) }
1984-
1985- #[ inline]
1986- pub fn mk_bool < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_BOOL ) }
1987-
1988- #[ inline]
1989- pub fn mk_int < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_INT ) }
1990-
1991- #[ inline]
1992- pub fn mk_i8 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I8 ) }
1993-
1994- #[ inline]
1995- pub fn mk_i16 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I16 ) }
1996-
1997- #[ inline]
1998- pub fn mk_i32 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I32 ) }
1999-
2000- #[ inline]
2001- pub fn mk_i64 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I64 ) }
2002-
2003- #[ inline]
2004- pub fn mk_f32 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_F32 ) }
2005-
2006- #[ inline]
2007- pub fn mk_f64 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_F64 ) }
2008-
2009- #[ inline]
2010- pub fn mk_uint < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_UINT ) }
2011-
2012- #[ inline]
2013- pub fn mk_u8 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U8 ) }
2014-
2015- #[ inline]
2016- pub fn mk_u16 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U16 ) }
2017-
2018- #[ inline]
2019- pub fn mk_u32 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U32 ) }
2020-
2021- #[ inline]
2022- pub fn mk_u64 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U64 ) }
2023-
20241987pub fn mk_mach_int < ' tcx > ( tm : ast:: IntTy ) -> Ty < ' tcx > {
20251988 match tm {
20261989 ast:: TyI => mk_int ( ) ,
@@ -2048,9 +2011,6 @@ pub fn mk_mach_float<'tcx>(tm: ast::FloatTy) -> Ty<'tcx> {
20482011 }
20492012}
20502013
2051- #[ inline]
2052- pub fn mk_char < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_CHAR ) }
2053-
20542014pub fn mk_str < ' tcx > ( cx : & ctxt < ' tcx > ) -> Ty < ' tcx > {
20552015 mk_t ( cx, ty_str)
20562016}
0 commit comments