@@ -935,40 +935,51 @@ pub enum BoundRegion {
935
935
BrEnv
936
936
}
937
937
938
- mod primitives {
939
- use super :: TyS ;
940
-
941
- use syntax:: ast;
938
+ #[ inline]
939
+ pub fn mk_prim_t < ' tcx > ( primitive : & ' tcx TyS < ' static > ) -> Ty < ' tcx > {
940
+ // FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx.
941
+ unsafe { & * ( primitive as * const _ as * const TyS < ' tcx > ) }
942
+ }
942
943
943
- macro_rules! def_prim_ty(
944
- ( $name: ident, $sty: expr) => (
945
- pub static $name: TyS <' static > = TyS {
944
+ // Do not change these from static to const, interning types requires
945
+ // the primitives to have a significant address.
946
+ macro_rules! def_prim_tys(
947
+ ( $( $name: ident -> $sty: expr; ) * ) => (
948
+ $( #[ inline] pub fn $name<' tcx>( ) -> Ty <' tcx> {
949
+ static PRIM_TY : TyS <' static > = TyS {
946
950
sty: $sty,
947
- flags: super :: NO_TYPE_FLAGS ,
951
+ flags: NO_TYPE_FLAGS ,
948
952
} ;
949
- )
953
+ mk_prim_t( & PRIM_TY )
954
+ } ) *
950
955
)
956
+ )
957
+
958
+ def_prim_tys ! {
959
+ mk_nil -> ty_nil;
960
+ mk_bool -> ty_bool;
961
+ mk_char -> ty_char;
962
+ mk_int -> ty_int( ast:: TyI ) ;
963
+ mk_i8 -> ty_int( ast:: TyI8 ) ;
964
+ mk_i16 -> ty_int( ast:: TyI16 ) ;
965
+ mk_i32 -> ty_int( ast:: TyI32 ) ;
966
+ mk_i64 -> ty_int( ast:: TyI64 ) ;
967
+ mk_uint -> ty_uint( ast:: TyU ) ;
968
+ mk_u8 -> ty_uint( ast:: TyU8 ) ;
969
+ mk_u16 -> ty_uint( ast:: TyU16 ) ;
970
+ mk_u32 -> ty_uint( ast:: TyU32 ) ;
971
+ mk_u64 -> ty_uint( ast:: TyU64 ) ;
972
+ mk_f32 -> ty_float( ast:: TyF32 ) ;
973
+ mk_f64 -> ty_float( ast:: TyF64 ) ;
974
+ }
951
975
952
- def_prim_ty ! ( TY_NIL , super :: ty_nil)
953
- def_prim_ty ! ( TY_BOOL , super :: ty_bool)
954
- def_prim_ty ! ( TY_CHAR , super :: ty_char)
955
- def_prim_ty ! ( TY_INT , super :: ty_int( ast:: TyI ) )
956
- def_prim_ty ! ( TY_I8 , super :: ty_int( ast:: TyI8 ) )
957
- def_prim_ty ! ( TY_I16 , super :: ty_int( ast:: TyI16 ) )
958
- def_prim_ty ! ( TY_I32 , super :: ty_int( ast:: TyI32 ) )
959
- def_prim_ty ! ( TY_I64 , super :: ty_int( ast:: TyI64 ) )
960
- def_prim_ty ! ( TY_UINT , super :: ty_uint( ast:: TyU ) )
961
- def_prim_ty ! ( TY_U8 , super :: ty_uint( ast:: TyU8 ) )
962
- def_prim_ty ! ( TY_U16 , super :: ty_uint( ast:: TyU16 ) )
963
- def_prim_ty ! ( TY_U32 , super :: ty_uint( ast:: TyU32 ) )
964
- def_prim_ty ! ( TY_U64 , super :: ty_uint( ast:: TyU64 ) )
965
- def_prim_ty ! ( TY_F32 , super :: ty_float( ast:: TyF32 ) )
966
- def_prim_ty ! ( TY_F64 , super :: ty_float( ast:: TyF64 ) )
967
-
968
- pub static TY_ERR : TyS < ' static > = TyS {
969
- sty : super :: ty_err,
970
- flags : super :: HAS_TY_ERR ,
976
+ #[ inline]
977
+ pub fn mk_err < ' tcx > ( ) -> Ty < ' tcx > {
978
+ static TY_ERR : TyS < ' static > = TyS {
979
+ sty : ty_err,
980
+ flags : HAS_TY_ERR ,
971
981
} ;
982
+ mk_prim_t ( & TY_ERR )
972
983
}
973
984
974
985
// NB: If you change this, you'll probably want to change the corresponding
@@ -1755,57 +1766,6 @@ pub fn mk_t<'tcx>(cx: &ctxt<'tcx>, st: sty<'tcx>) -> Ty<'tcx> {
1755
1766
ty
1756
1767
}
1757
1768
1758
- #[ inline]
1759
- pub fn mk_prim_t < ' tcx > ( primitive : & ' tcx TyS < ' static > ) -> Ty < ' tcx > {
1760
- // FIXME(#17596) Ty<'tcx> is incorrectly invariant w.r.t 'tcx.
1761
- unsafe { & * ( primitive as * const _ as * const TyS < ' tcx > ) }
1762
- }
1763
-
1764
- #[ inline]
1765
- pub fn mk_nil < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_NIL ) }
1766
-
1767
- #[ inline]
1768
- pub fn mk_err < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_ERR ) }
1769
-
1770
- #[ inline]
1771
- pub fn mk_bool < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_BOOL ) }
1772
-
1773
- #[ inline]
1774
- pub fn mk_int < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_INT ) }
1775
-
1776
- #[ inline]
1777
- pub fn mk_i8 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I8 ) }
1778
-
1779
- #[ inline]
1780
- pub fn mk_i16 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I16 ) }
1781
-
1782
- #[ inline]
1783
- pub fn mk_i32 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I32 ) }
1784
-
1785
- #[ inline]
1786
- pub fn mk_i64 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_I64 ) }
1787
-
1788
- #[ inline]
1789
- pub fn mk_f32 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_F32 ) }
1790
-
1791
- #[ inline]
1792
- pub fn mk_f64 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_F64 ) }
1793
-
1794
- #[ inline]
1795
- pub fn mk_uint < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_UINT ) }
1796
-
1797
- #[ inline]
1798
- pub fn mk_u8 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U8 ) }
1799
-
1800
- #[ inline]
1801
- pub fn mk_u16 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U16 ) }
1802
-
1803
- #[ inline]
1804
- pub fn mk_u32 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U32 ) }
1805
-
1806
- #[ inline]
1807
- pub fn mk_u64 < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_U64 ) }
1808
-
1809
1769
pub fn mk_mach_int < ' tcx > ( tm : ast:: IntTy ) -> Ty < ' tcx > {
1810
1770
match tm {
1811
1771
ast:: TyI => mk_int ( ) ,
@@ -1833,9 +1793,6 @@ pub fn mk_mach_float<'tcx>(tm: ast::FloatTy) -> Ty<'tcx> {
1833
1793
}
1834
1794
}
1835
1795
1836
- #[ inline]
1837
- pub fn mk_char < ' tcx > ( ) -> Ty < ' tcx > { mk_prim_t ( & primitives:: TY_CHAR ) }
1838
-
1839
1796
pub fn mk_str < ' tcx > ( cx : & ctxt < ' tcx > ) -> Ty < ' tcx > {
1840
1797
mk_t ( cx, ty_str)
1841
1798
}
0 commit comments