@@ -13,8 +13,8 @@ use rustc_hir::def::{DefKind, Res};
1313use rustc_hir:: def_id:: { DefId , LocalDefId } ;
1414use rustc_hir:: lang_items:: LangItem ;
1515use rustc_hir:: { AmbigArg , ItemKind , find_attr} ;
16+ use rustc_infer:: infer:: TyCtxtInferExt ;
1617use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
17- use rustc_infer:: infer:: { self , InferCtxt , SubregionOrigin , TyCtxtInferExt } ;
1818use rustc_infer:: traits:: PredicateObligations ;
1919use rustc_lint_defs:: builtin:: SHADOWING_SUPERTRAIT_ITEMS ;
2020use rustc_macros:: Diagnostic ;
@@ -30,7 +30,9 @@ use rustc_middle::{bug, span_bug};
3030use rustc_session:: parse:: feature_err;
3131use rustc_span:: { DUMMY_SP , Span , sym} ;
3232use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
33- use rustc_trait_selection:: regions:: { InferCtxtRegionExt , OutlivesEnvironmentBuildExt } ;
33+ use rustc_trait_selection:: regions:: {
34+ InferCtxtRegionExt , OutlivesEnvironmentBuildExt , region_known_to_outlive, ty_known_to_outlive,
35+ } ;
3436use rustc_trait_selection:: traits:: misc:: {
3537 ConstParamTyImplementationError , type_allowed_to_implement_const_param_ty,
3638} ;
@@ -694,69 +696,6 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
694696 Some ( bounds)
695697}
696698
697- /// Given a known `param_env` and a set of well formed types, can we prove that
698- /// `ty` outlives `region`.
699- fn ty_known_to_outlive < ' tcx > (
700- tcx : TyCtxt < ' tcx > ,
701- id : LocalDefId ,
702- param_env : ty:: ParamEnv < ' tcx > ,
703- wf_tys : & FxIndexSet < Ty < ' tcx > > ,
704- ty : Ty < ' tcx > ,
705- region : ty:: Region < ' tcx > ,
706- ) -> bool {
707- test_region_obligations ( tcx, id, param_env, wf_tys, |infcx| {
708- infcx. register_type_outlives_constraint_inner ( infer:: TypeOutlivesConstraint {
709- sub_region : region,
710- sup_type : ty,
711- origin : SubregionOrigin :: RelateParamBound ( DUMMY_SP , ty, None ) ,
712- } ) ;
713- } )
714- }
715-
716- /// Given a known `param_env` and a set of well formed types, can we prove that
717- /// `region_a` outlives `region_b`
718- fn region_known_to_outlive < ' tcx > (
719- tcx : TyCtxt < ' tcx > ,
720- id : LocalDefId ,
721- param_env : ty:: ParamEnv < ' tcx > ,
722- wf_tys : & FxIndexSet < Ty < ' tcx > > ,
723- region_a : ty:: Region < ' tcx > ,
724- region_b : ty:: Region < ' tcx > ,
725- ) -> bool {
726- test_region_obligations ( tcx, id, param_env, wf_tys, |infcx| {
727- infcx. sub_regions (
728- SubregionOrigin :: RelateRegionParamBound ( DUMMY_SP , None ) ,
729- region_b,
730- region_a,
731- ) ;
732- } )
733- }
734-
735- /// Given a known `param_env` and a set of well formed types, set up an
736- /// `InferCtxt`, call the passed function (to e.g. set up region constraints
737- /// to be tested), then resolve region and return errors
738- fn test_region_obligations < ' tcx > (
739- tcx : TyCtxt < ' tcx > ,
740- id : LocalDefId ,
741- param_env : ty:: ParamEnv < ' tcx > ,
742- wf_tys : & FxIndexSet < Ty < ' tcx > > ,
743- add_constraints : impl FnOnce ( & InferCtxt < ' tcx > ) ,
744- ) -> bool {
745- // Unfortunately, we have to use a new `InferCtxt` each call, because
746- // region constraints get added and solved there and we need to test each
747- // call individually.
748- let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: non_body_analysis ( ) ) ;
749-
750- add_constraints ( & infcx) ;
751-
752- let errors = infcx. resolve_regions ( id, param_env, wf_tys. iter ( ) . copied ( ) ) ;
753- debug ! ( ?errors, "errors" ) ;
754-
755- // If we were able to prove that the type outlives the region without
756- // an error, it must be because of the implied or explicit bounds...
757- errors. is_empty ( )
758- }
759-
760699/// TypeVisitor that looks for uses of GATs like
761700/// `<P0 as Trait<P1..Pn>>::GAT<Pn..Pm>` and adds the arguments `P0..Pm` into
762701/// the two vectors, `regions` and `types` (depending on their kind). For each
0 commit comments