@@ -13,7 +13,7 @@ use std::num::NonZero;
1313use std:: { fmt, io} ;
1414
1515use rustc_abi:: { AddressSpace , Align , Endian , HasDataLayout , Size } ;
16- use rustc_ast:: { LitKind , Mutability } ;
16+ use rustc_ast:: Mutability ;
1717use rustc_data_structures:: fx:: FxHashMap ;
1818use rustc_data_structures:: sharded:: ShardedHashMap ;
1919use rustc_data_structures:: sync:: { AtomicU64 , Lock } ;
@@ -73,55 +73,6 @@ impl<'tcx> GlobalId<'tcx> {
7373 }
7474}
7575
76- /// Input argument for `tcx.lit_to_const`.
77- #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , HashStable ) ]
78- pub struct LitToConstInput < ' tcx > {
79- /// The absolute value of the resultant constant.
80- pub lit : LitKind ,
81- /// The type of the constant.
82- pub ty : Ty < ' tcx > ,
83- /// If the constant is negative.
84- pub neg : bool ,
85- }
86-
87- pub fn const_lit_matches_ty < ' tcx > (
88- tcx : TyCtxt < ' tcx > ,
89- kind : & LitKind ,
90- ty : Ty < ' tcx > ,
91- neg : bool ,
92- ) -> bool {
93- match ( * kind, ty. kind ( ) ) {
94- ( LitKind :: Str ( ..) , ty:: Ref ( _, inner_ty, _) ) if inner_ty. is_str ( ) => true ,
95- ( LitKind :: Str ( ..) , ty:: Str ) if tcx. features ( ) . deref_patterns ( ) => true ,
96- ( LitKind :: ByteStr ( ..) , ty:: Ref ( _, inner_ty, _) )
97- if let ty:: Slice ( ty) | ty:: Array ( ty, _) = inner_ty. kind ( )
98- && matches ! ( ty. kind( ) , ty:: Uint ( ty:: UintTy :: U8 ) ) =>
99- {
100- true
101- }
102- ( LitKind :: ByteStr ( ..) , ty:: Slice ( inner_ty) | ty:: Array ( inner_ty, _) )
103- if tcx. features ( ) . deref_patterns ( )
104- && matches ! ( inner_ty. kind( ) , ty:: Uint ( ty:: UintTy :: U8 ) ) =>
105- {
106- true
107- }
108- ( LitKind :: Byte ( ..) , ty:: Uint ( ty:: UintTy :: U8 ) ) => true ,
109- ( LitKind :: CStr ( ..) , ty:: Ref ( _, inner_ty, _) )
110- if matches ! ( inner_ty. kind( ) , ty:: Adt ( def, _)
111- if tcx. is_lang_item( def. did( ) , rustc_hir:: LangItem :: CStr ) ) =>
112- {
113- true
114- }
115- ( LitKind :: Int ( ..) , ty:: Uint ( _) ) if !neg => true ,
116- ( LitKind :: Int ( ..) , ty:: Int ( _) ) => true ,
117- ( LitKind :: Bool ( ..) , ty:: Bool ) => true ,
118- ( LitKind :: Float ( ..) , ty:: Float ( _) ) => true ,
119- ( LitKind :: Char ( ..) , ty:: Char ) => true ,
120- ( LitKind :: Err ( ..) , _) => true ,
121- _ => false ,
122- }
123- }
124-
12576#[ derive( Copy , Clone , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
12677pub struct AllocId ( pub NonZero < u64 > ) ;
12778
0 commit comments