1+ use std:: mem;
2+
3+ use rustc_infer:: infer:: InferCtxt ;
4+ use rustc_infer:: traits:: { Obligation , ObligationCause } ;
5+ use rustc_middle:: hooks:: TypeErasedInfcx ;
16pub use rustc_next_trait_solver:: solve:: * ;
27
38mod delegate;
@@ -13,10 +18,13 @@ pub use normalize::{
1318 deeply_normalize, deeply_normalize_with_skipped_universes,
1419 deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals,
1520} ;
16- use rustc_middle:: query:: Providers ;
17- use rustc_middle:: ty:: TyCtxt ;
21+ use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
22+ use rustc_middle:: util:: Providers ;
23+ use rustc_span:: Span ;
1824pub use select:: InferCtxtSelectExt ;
1925
26+ use crate :: traits:: ObligationCtxt ;
27+
2028fn evaluate_root_goal_for_proof_tree_raw < ' tcx > (
2129 tcx : TyCtxt < ' tcx > ,
2230 canonical_input : CanonicalInput < TyCtxt < ' tcx > > ,
@@ -27,6 +35,46 @@ fn evaluate_root_goal_for_proof_tree_raw<'tcx>(
2735 )
2836}
2937
38+ fn try_eagerly_normalize_alias < ' a , ' tcx > (
39+ tcx : TyCtxt < ' tcx > ,
40+ type_erased_infcx : TypeErasedInfcx < ' a , ' tcx > ,
41+ param_env : ty:: ParamEnv < ' tcx > ,
42+ span : Span ,
43+ alias : ty:: AliasTy < ' tcx > ,
44+ ) -> Ty < ' tcx > {
45+ let infcx = unsafe {
46+ mem:: transmute :: < TypeErasedInfcx < ' a , ' tcx > , & ' a InferCtxt < ' tcx > > ( type_erased_infcx)
47+ } ;
48+
49+ let ocx = ObligationCtxt :: new ( infcx) ;
50+
51+ let infer_term = infcx. next_ty_var ( span) ;
52+
53+ // Dummy because we ignore the error anyway.
54+ // We do provide a span, because this span is used when registering opaque types.
55+ // For example, if we don't provide a span here, some diagnostics talking about TAIT will refer to a dummy span.
56+ let cause = ObligationCause :: dummy_with_span ( span) ;
57+ let obligation = Obligation :: new (
58+ tcx,
59+ // we ignore the error anyway
60+ ObligationCause :: dummy ( ) ,
61+ param_env,
62+ ty:: PredicateKind :: AliasRelate (
63+ alias. to_ty ( tcx) . into ( ) ,
64+ infer_term. into ( ) ,
65+ ty:: AliasRelationDirection :: Equate ,
66+ ) ,
67+ ) ;
68+
69+ ocx. register_obligation ( obligation) ;
70+
71+ // This only tries to eagerly resolve, if it errors we don't care.
72+ let _ = ocx. try_evaluate_obligations ( ) ;
73+
74+ infcx. resolve_vars_if_possible ( infer_term)
75+ }
76+
3077pub fn provide ( providers : & mut Providers ) {
31- * providers = Providers { evaluate_root_goal_for_proof_tree_raw, ..* providers } ;
78+ providers. hooks . try_eagerly_normalize_alias = try_eagerly_normalize_alias;
79+ providers. queries . evaluate_root_goal_for_proof_tree_raw = evaluate_root_goal_for_proof_tree_raw;
3280}
0 commit comments