@@ -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
@@ -183,46 +182,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
183182 }
184183}
185184
186- /// In some cases, [`hir::ConstArg`]s that are being used in the type system
187- /// through const generics need to have their type "fed" to them
188- /// using the query system.
189- ///
190- /// Use this enum with [`Const::from_const_arg`] to instruct it with the
191- /// desired behavior.
192- #[ derive( Debug , Clone , Copy ) ]
193- pub enum FeedConstTy {
194- /// Feed the type.
195- ///
196- /// The `DefId` belongs to the const param that we are supplying
197- /// this (anon) const arg to.
198- Param ( DefId ) ,
199- /// Don't feed the type.
200- No ,
201- }
202-
203185impl < ' tcx > Const < ' tcx > {
204- /// Convert a [`hir::ConstArg`] to a [`ty::Const`](Self).
205- #[ instrument( skip( tcx) , level = "debug" ) ]
206- pub fn from_const_arg (
207- tcx : TyCtxt < ' tcx > ,
208- const_arg : & ' tcx hir:: ConstArg < ' tcx > ,
209- feed : FeedConstTy ,
210- ) -> Self {
211- if let FeedConstTy :: Param ( param_def_id) = feed
212- && let hir:: ConstArgKind :: Anon ( anon) = & const_arg. kind
213- {
214- tcx. feed_anon_const_type ( anon. def_id , tcx. type_of ( param_def_id) ) ;
215- }
216-
217- match const_arg. kind {
218- hir:: ConstArgKind :: Path ( qpath) => {
219- // FIXME(min_generic_const_args): for now only params are lowered to ConstArgKind::Path
220- Self :: from_param ( tcx, qpath, const_arg. hir_id )
221- }
222- hir:: ConstArgKind :: Anon ( anon) => Self :: from_anon_const ( tcx, anon. def_id ) ,
223- }
224- }
225-
226186 /// Literals and const generic parameters are eagerly converted to a constant, everything else
227187 /// becomes `Unevaluated`.
228188 #[ instrument( skip( tcx) , level = "debug" ) ]
@@ -249,34 +209,6 @@ impl<'tcx> Const<'tcx> {
249209 }
250210 }
251211
252- /// Lower a const param to a [`Const`].
253- ///
254- /// IMPORTANT: `qpath` must be a const param, otherwise this will panic
255- fn from_param ( tcx : TyCtxt < ' tcx > , qpath : hir:: QPath < ' tcx > , hir_id : HirId ) -> Self {
256- let hir:: QPath :: Resolved ( _, & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , def_id) , .. } ) =
257- qpath
258- else {
259- span_bug ! ( qpath. span( ) , "non-param {qpath:?} passed to Const::from_param" )
260- } ;
261-
262- match tcx. named_bound_var ( hir_id) {
263- Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
264- // Find the name and index of the const parameter by indexing the generics of
265- // the parent item and construct a `ParamConst`.
266- let item_def_id = tcx. parent ( def_id) ;
267- let generics = tcx. generics_of ( item_def_id) ;
268- let index = generics. param_def_id_to_index [ & def_id] ;
269- let name = tcx. item_name ( def_id) ;
270- ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
271- }
272- Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
273- ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
274- }
275- Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
276- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , hir_id) ,
277- }
278- }
279-
280212 #[ instrument( skip( tcx) , level = "debug" ) ]
281213 fn try_from_lit ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) -> Option < Self > {
282214 // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
@@ -527,20 +459,3 @@ impl<'tcx> Const<'tcx> {
527459 matches ! ( self . kind( ) , ty:: ConstKind :: Infer ( _) )
528460 }
529461}
530-
531- pub fn const_param_default < ' tcx > (
532- tcx : TyCtxt < ' tcx > ,
533- def_id : LocalDefId ,
534- ) -> ty:: EarlyBinder < ' tcx , Const < ' tcx > > {
535- let default_ct = match tcx. hir_node_by_def_id ( def_id) {
536- hir:: Node :: GenericParam ( hir:: GenericParam {
537- kind : hir:: GenericParamKind :: Const { default : Some ( ct) , .. } ,
538- ..
539- } ) => ct,
540- _ => span_bug ! (
541- tcx. def_span( def_id) ,
542- "`const_param_default` expected a generic parameter with a constant"
543- ) ,
544- } ;
545- ty:: EarlyBinder :: bind ( Const :: from_const_arg ( tcx, default_ct, FeedConstTy :: No ) )
546- }
0 commit comments