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 {
@@ -1688,29 +1672,6 @@ fn is_anon_const_rhs_of_const_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId)
16881672 def_id == rhs_anon. def_id
16891673}
16901674
1691- struct GCAParamVisitor < ' tcx > ( TyCtxt < ' tcx > ) ;
1692-
1693- struct UsesParam ;
1694-
1695- impl < ' tcx > Visitor < ' tcx > for GCAParamVisitor < ' tcx > {
1696- type NestedFilter = nested_filter:: OnlyBodies ;
1697- type Result = ControlFlow < UsesParam > ;
1698-
1699- fn maybe_tcx ( & mut self ) -> TyCtxt < ' tcx > {
1700- self . 0
1701- }
1702-
1703- fn visit_path ( & mut self , path : & hir:: Path < ' tcx > , _id : HirId ) -> ControlFlow < UsesParam > {
1704- if let Res :: Def ( DefKind :: TyParam | DefKind :: ConstParam | DefKind :: LifetimeParam , _) =
1705- path. res
1706- {
1707- return ControlFlow :: Break ( UsesParam ) ;
1708- }
1709-
1710- intravisit:: walk_path ( self , path)
1711- }
1712- }
1713-
17141675#[ instrument( level = "debug" , skip( tcx) , ret) ]
17151676fn const_of_item < ' tcx > (
17161677 tcx : TyCtxt < ' tcx > ,
0 commit comments