1515//! crate as a kind of pass. This should eventually be factored away.
1616
1717use std:: cell:: Cell ;
18- use std:: ops:: ControlFlow ;
1918use std:: { assert_matches, iter} ;
2019
2120use rustc_abi:: { ExternAbi , Size } ;
@@ -24,13 +23,12 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2423use rustc_errors:: {
2524 Applicability , Diag , DiagCtxtHandle , Diagnostic , E0228 , ErrorGuaranteed , Level , StashKey ,
2625} ;
27- use rustc_hir:: def:: { DefKind , Res } ;
26+ use rustc_hir:: def:: DefKind ;
2827use rustc_hir:: def_id:: { DefId , LocalDefId } ;
29- use rustc_hir:: intravisit:: { self , InferKind , Visitor , VisitorExt } ;
28+ use rustc_hir:: intravisit:: { InferKind , Visitor , VisitorExt } ;
3029use rustc_hir:: { self as hir, GenericParamKind , HirId , Node , PreciseCapturingArgKind , find_attr} ;
3130use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
3231use rustc_infer:: traits:: { DynCompatibilityViolation , ObligationCause } ;
33- use rustc_middle:: hir:: nested_filter;
3432use rustc_middle:: query:: Providers ;
3533use rustc_middle:: ty:: util:: { Discr , IntTypeExt } ;
3634use rustc_middle:: ty:: {
@@ -1636,20 +1634,6 @@ fn anon_const_kind<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ty::AnonConstKin
16361634 let parent_hir_node = tcx. hir_node ( tcx. parent_hir_id ( const_arg_id) ) ;
16371635 if tcx. features ( ) . generic_const_exprs ( ) {
16381636 ty:: AnonConstKind :: GCE
1639- } else if tcx. features ( ) . generic_const_args ( ) {
1640- // Only anon consts that are the RHS of a const item can be GCA.
1641- // Note: We can't just check tcx.parent because it needs to be EXACTLY
1642- // the RHS, not just part of the RHS.
1643- if !is_anon_const_rhs_of_const_item ( tcx, def) {
1644- return ty:: AnonConstKind :: MCG ;
1645- }
1646-
1647- let body = tcx. hir_body_owned_by ( def) ;
1648- let mut visitor = GCAParamVisitor ( tcx) ;
1649- match visitor. visit_body ( body) {
1650- ControlFlow :: Break ( UsesParam ) => ty:: AnonConstKind :: GCA ,
1651- ControlFlow :: Continue ( ( ) ) => ty:: AnonConstKind :: MCG ,
1652- }
16531637 } else if tcx. features ( ) . min_generic_const_args ( ) {
16541638 ty:: AnonConstKind :: MCG
16551639 } else if let hir:: Node :: Expr ( hir:: Expr {
@@ -1667,49 +1651,6 @@ fn anon_const_kind<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ty::AnonConstKin
16671651 }
16681652}
16691653
1670- fn is_anon_const_rhs_of_const_item < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> bool {
1671- let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
1672- let Some ( ( _, grandparent_node) ) = tcx. hir_parent_iter ( hir_id) . nth ( 1 ) else { return false } ;
1673- let ( Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Const ( _, _, _, ct_rhs) , .. } )
1674- | Node :: ImplItem ( hir:: ImplItem { kind : hir:: ImplItemKind :: Const ( _, ct_rhs) , .. } )
1675- | Node :: TraitItem ( hir:: TraitItem {
1676- kind : hir:: TraitItemKind :: Const ( _, Some ( ct_rhs) ) , ..
1677- } ) ) = grandparent_node
1678- else {
1679- return false ;
1680- } ;
1681- let hir:: ConstItemRhs :: TypeConst ( hir:: ConstArg {
1682- kind : hir:: ConstArgKind :: Anon ( rhs_anon) , ..
1683- } ) = ct_rhs
1684- else {
1685- return false ;
1686- } ;
1687- def_id == rhs_anon. def_id
1688- }
1689-
1690- struct GCAParamVisitor < ' tcx > ( TyCtxt < ' tcx > ) ;
1691-
1692- struct UsesParam ;
1693-
1694- impl < ' tcx > Visitor < ' tcx > for GCAParamVisitor < ' tcx > {
1695- type NestedFilter = nested_filter:: OnlyBodies ;
1696- type Result = ControlFlow < UsesParam > ;
1697-
1698- fn maybe_tcx ( & mut self ) -> TyCtxt < ' tcx > {
1699- self . 0
1700- }
1701-
1702- fn visit_path ( & mut self , path : & hir:: Path < ' tcx > , _id : HirId ) -> ControlFlow < UsesParam > {
1703- if let Res :: Def ( DefKind :: TyParam | DefKind :: ConstParam | DefKind :: LifetimeParam , _) =
1704- path. res
1705- {
1706- return ControlFlow :: Break ( UsesParam ) ;
1707- }
1708-
1709- intravisit:: walk_path ( self , path)
1710- }
1711- }
1712-
17131654#[ instrument( level = "debug" , skip( tcx) , ret) ]
17141655fn const_of_item < ' tcx > (
17151656 tcx : TyCtxt < ' tcx > ,
0 commit comments