@@ -2,13 +2,12 @@ use either::Either;
22use rustc_data_structures:: intern:: Interned ;
33use rustc_error_messages:: MultiSpan ;
44use rustc_hir:: def:: { DefKind , Res } ;
5- use rustc_hir:: def_id:: { DefId , LocalDefId } ;
6- use rustc_hir:: { self as hir, HirId } ;
5+ use rustc_hir:: def_id:: LocalDefId ;
6+ use rustc_hir:: { self as hir} ;
77use rustc_macros:: HashStable ;
88use rustc_type_ir:: { self as ir, TypeFlags , WithCachedTypeInfo } ;
99use tracing:: { debug, instrument} ;
1010
11- use crate :: middle:: resolve_bound_vars as rbv;
1211use crate :: mir:: interpret:: { ErrorHandled , LitToConstInput , Scalar } ;
1312use crate :: ty:: { self , GenericArgs , ParamEnv , ParamEnvAnd , Ty , TyCtxt , TypeVisitableExt } ;
1413
@@ -184,46 +183,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
184183 }
185184}
186185
187- /// In some cases, [`hir::ConstArg`]s that are being used in the type system
188- /// through const generics need to have their type "fed" to them
189- /// using the query system.
190- ///
191- /// Use this enum with [`Const::from_const_arg`] to instruct it with the
192- /// desired behavior.
193- #[ derive( Debug , Clone , Copy ) ]
194- pub enum FeedConstTy {
195- /// Feed the type.
196- ///
197- /// The `DefId` belongs to the const param that we are supplying
198- /// this (anon) const arg to.
199- Param ( DefId ) ,
200- /// Don't feed the type.
201- No ,
202- }
203-
204186impl < ' tcx > Const < ' tcx > {
205- /// Convert a [`hir::ConstArg`] to a [`ty::Const`](Self).
206- #[ instrument( skip( tcx) , level = "debug" ) ]
207- pub fn from_const_arg (
208- tcx : TyCtxt < ' tcx > ,
209- const_arg : & ' tcx hir:: ConstArg < ' tcx > ,
210- feed : FeedConstTy ,
211- ) -> Self {
212- if let FeedConstTy :: Param ( param_def_id) = feed
213- && let hir:: ConstArgKind :: Anon ( anon) = & const_arg. kind
214- {
215- tcx. feed_anon_const_type ( anon. def_id , tcx. type_of ( param_def_id) ) ;
216- }
217-
218- match const_arg. kind {
219- hir:: ConstArgKind :: Path ( qpath) => {
220- // FIXME(min_generic_const_args): for now only params are lowered to ConstArgKind::Path
221- Self :: from_param ( tcx, qpath, const_arg. hir_id )
222- }
223- hir:: ConstArgKind :: Anon ( anon) => Self :: from_anon_const ( tcx, anon. def_id ) ,
224- }
225- }
226-
227187 /// Literals and const generic parameters are eagerly converted to a constant, everything else
228188 /// becomes `Unevaluated`.
229189 #[ instrument( skip( tcx) , level = "debug" ) ]
@@ -250,34 +210,6 @@ impl<'tcx> Const<'tcx> {
250210 }
251211 }
252212
253- /// Lower a const param to a [`Const`].
254- ///
255- /// IMPORTANT: `qpath` must be a const param, otherwise this will panic
256- fn from_param ( tcx : TyCtxt < ' tcx > , qpath : hir:: QPath < ' tcx > , hir_id : HirId ) -> Self {
257- let hir:: QPath :: Resolved ( _, & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , def_id) , .. } ) =
258- qpath
259- else {
260- span_bug ! ( qpath. span( ) , "non-param {qpath:?} passed to Const::from_param" )
261- } ;
262-
263- match tcx. named_bound_var ( hir_id) {
264- Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
265- // Find the name and index of the const parameter by indexing the generics of
266- // the parent item and construct a `ParamConst`.
267- let item_def_id = tcx. parent ( def_id) ;
268- let generics = tcx. generics_of ( item_def_id) ;
269- let index = generics. param_def_id_to_index [ & def_id] ;
270- let name = tcx. item_name ( def_id) ;
271- ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
272- }
273- Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
274- ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
275- }
276- Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
277- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , hir_id) ,
278- }
279- }
280-
281213 #[ instrument( skip( tcx) , level = "debug" ) ]
282214 fn try_from_lit ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) -> Option < Self > {
283215 // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
@@ -460,20 +392,3 @@ impl<'tcx> Const<'tcx> {
460392 matches ! ( self . kind( ) , ty:: ConstKind :: Infer ( _) )
461393 }
462394}
463-
464- pub fn const_param_default < ' tcx > (
465- tcx : TyCtxt < ' tcx > ,
466- def_id : LocalDefId ,
467- ) -> ty:: EarlyBinder < ' tcx , Const < ' tcx > > {
468- let default_ct = match tcx. hir_node_by_def_id ( def_id) {
469- hir:: Node :: GenericParam ( hir:: GenericParam {
470- kind : hir:: GenericParamKind :: Const { default : Some ( ct) , .. } ,
471- ..
472- } ) => ct,
473- _ => span_bug ! (
474- tcx. def_span( def_id) ,
475- "`const_param_default` expected a generic parameter with a constant"
476- ) ,
477- } ;
478- ty:: EarlyBinder :: bind ( Const :: from_const_arg ( tcx, default_ct, FeedConstTy :: No ) )
479- }
0 commit comments