@@ -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:: errors:: 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} ;
@@ -695,70 +697,6 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
695697 Some ( bounds)
696698}
697699
698- /// Given a known `param_env` and a set of well formed types, can we prove that
699- /// `ty` outlives `region`.
700- fn ty_known_to_outlive < ' tcx > (
701- tcx : TyCtxt < ' tcx > ,
702- id : LocalDefId ,
703- param_env : ty:: ParamEnv < ' tcx > ,
704- wf_tys : & FxIndexSet < Ty < ' tcx > > ,
705- ty : Ty < ' tcx > ,
706- region : ty:: Region < ' tcx > ,
707- ) -> bool {
708- test_region_obligations ( tcx, id, param_env, wf_tys, |infcx| {
709- infcx. register_type_outlives_constraint_inner ( infer:: TypeOutlivesConstraint {
710- sub_region : region,
711- sup_type : ty,
712- origin : SubregionOrigin :: RelateParamBound ( DUMMY_SP , ty, None ) ,
713- } ) ;
714- } )
715- }
716-
717- /// Given a known `param_env` and a set of well formed types, can we prove that
718- /// `region_a` outlives `region_b`
719- fn region_known_to_outlive < ' tcx > (
720- tcx : TyCtxt < ' tcx > ,
721- id : LocalDefId ,
722- param_env : ty:: ParamEnv < ' tcx > ,
723- wf_tys : & FxIndexSet < Ty < ' tcx > > ,
724- region_a : ty:: Region < ' tcx > ,
725- region_b : ty:: Region < ' tcx > ,
726- ) -> bool {
727- test_region_obligations ( tcx, id, param_env, wf_tys, |infcx| {
728- infcx. sub_regions (
729- SubregionOrigin :: RelateRegionParamBound ( DUMMY_SP , None ) ,
730- region_b,
731- region_a,
732- ty:: VisibleForLeakCheck :: Unreachable ,
733- ) ;
734- } )
735- }
736-
737- /// Given a known `param_env` and a set of well formed types, set up an
738- /// `InferCtxt`, call the passed function (to e.g. set up region constraints
739- /// to be tested), then resolve region and return errors
740- fn test_region_obligations < ' tcx > (
741- tcx : TyCtxt < ' tcx > ,
742- id : LocalDefId ,
743- param_env : ty:: ParamEnv < ' tcx > ,
744- wf_tys : & FxIndexSet < Ty < ' tcx > > ,
745- add_constraints : impl FnOnce ( & InferCtxt < ' tcx > ) ,
746- ) -> bool {
747- // Unfortunately, we have to use a new `InferCtxt` each call, because
748- // region constraints get added and solved there and we need to test each
749- // call individually.
750- let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: non_body_analysis ( ) ) ;
751-
752- add_constraints ( & infcx) ;
753-
754- let errors = infcx. resolve_regions ( id, param_env, wf_tys. iter ( ) . copied ( ) ) ;
755- debug ! ( ?errors, "errors" ) ;
756-
757- // If we were able to prove that the type outlives the region without
758- // an error, it must be because of the implied or explicit bounds...
759- errors. is_empty ( )
760- }
761-
762700/// TypeVisitor that looks for uses of GATs like
763701/// `<P0 as Trait<P1..Pn>>::GAT<Pn..Pm>` and adds the arguments `P0..Pm` into
764702/// the two vectors, `regions` and `types` (depending on their kind). For each
0 commit comments