@@ -10,7 +10,7 @@ use rustc_middle::ty::{
1010 self , FnSig , Lift , PolyFnSig , PredicateKind , Ty , TyCtxt , TypeFoldable , Variance ,
1111} ;
1212use rustc_middle:: ty:: { ParamEnv , ParamEnvAnd , Predicate , ToPredicate } ;
13- use rustc_span:: DUMMY_SP ;
13+ use rustc_span:: { Span , DUMMY_SP } ;
1414use rustc_trait_selection:: infer:: InferCtxtBuilderExt ;
1515use rustc_trait_selection:: infer:: InferCtxtExt ;
1616use rustc_trait_selection:: traits:: query:: normalize:: AtExt ;
@@ -247,11 +247,25 @@ fn type_op_prove_predicate<'tcx>(
247247 canonicalized : Canonical < ' tcx , ParamEnvAnd < ' tcx , ProvePredicate < ' tcx > > > ,
248248) -> Result < & ' tcx Canonical < ' tcx , QueryResponse < ' tcx , ( ) > > , NoSolution > {
249249 tcx. infer_ctxt ( ) . enter_canonical_trait_query ( & canonicalized, |infcx, fulfill_cx, key| {
250- let ( param_env, ProvePredicate { predicate } ) = key. into_parts ( ) ;
251- fulfill_cx. register_predicate_obligation (
252- infcx,
253- Obligation :: new ( ObligationCause :: dummy ( ) , param_env, predicate) ,
254- ) ;
250+ type_op_prove_predicate_with_span ( infcx, fulfill_cx, key, None ) ;
255251 Ok ( ( ) )
256252 } )
257253}
254+
255+ /// The core of the `type_op_prove_predicate` query: for diagnostics purposes in NLL HRTB errors,
256+ /// this query can be re-run to better track the span of the obligation cause, and improve the error
257+ /// message. Do not call directly unless you're in that very specific context.
258+ pub fn type_op_prove_predicate_with_span < ' a , ' tcx : ' a > (
259+ infcx : & ' a InferCtxt < ' a , ' tcx > ,
260+ fulfill_cx : & ' a mut dyn TraitEngine < ' tcx > ,
261+ key : ParamEnvAnd < ' tcx , ProvePredicate < ' tcx > > ,
262+ span : Option < Span > ,
263+ ) {
264+ let cause = if let Some ( span) = span {
265+ ObligationCause :: dummy_with_span ( span)
266+ } else {
267+ ObligationCause :: dummy ( )
268+ } ;
269+ let ( param_env, ProvePredicate { predicate } ) = key. into_parts ( ) ;
270+ fulfill_cx. register_predicate_obligation ( infcx, Obligation :: new ( cause, param_env, predicate) ) ;
271+ }
0 commit comments