@@ -406,6 +406,14 @@ pub trait TypeErrCtxtExt<'tcx> {
406
406
candidate_impls : & [ ImplCandidate < ' tcx > ] ,
407
407
span : Span ,
408
408
) ;
409
+
410
+ fn explain_hrtb_projection (
411
+ & self ,
412
+ diag : & mut Diagnostic ,
413
+ pred : ty:: PolyTraitPredicate < ' tcx > ,
414
+ param_env : ty:: ParamEnv < ' tcx > ,
415
+ cause : & ObligationCause < ' tcx > ,
416
+ ) ;
409
417
}
410
418
411
419
fn predicate_constraint ( generics : & hir:: Generics < ' _ > , pred : ty:: Predicate < ' _ > ) -> ( Span , String ) {
@@ -4014,6 +4022,71 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
4014
4022
}
4015
4023
}
4016
4024
}
4025
+
4026
+ fn explain_hrtb_projection (
4027
+ & self ,
4028
+ diag : & mut Diagnostic ,
4029
+ pred : ty:: PolyTraitPredicate < ' tcx > ,
4030
+ param_env : ty:: ParamEnv < ' tcx > ,
4031
+ cause : & ObligationCause < ' tcx > ,
4032
+ ) {
4033
+ if pred. skip_binder ( ) . has_escaping_bound_vars ( ) && pred. skip_binder ( ) . has_non_region_infer ( )
4034
+ {
4035
+ self . probe ( |_| {
4036
+ let ocx = ObligationCtxt :: new ( self ) ;
4037
+ let pred = self . instantiate_binder_with_placeholders ( pred) ;
4038
+ let pred = ocx. normalize ( & ObligationCause :: dummy ( ) , param_env, pred) ;
4039
+ ocx. register_obligation ( Obligation :: new (
4040
+ self . tcx ,
4041
+ ObligationCause :: dummy ( ) ,
4042
+ param_env,
4043
+ pred,
4044
+ ) ) ;
4045
+ if !ocx. select_where_possible ( ) . is_empty ( ) {
4046
+ // encountered errors.
4047
+ return ;
4048
+ }
4049
+
4050
+ if let ObligationCauseCode :: FunctionArgumentObligation {
4051
+ call_hir_id,
4052
+ arg_hir_id,
4053
+ parent_code : _,
4054
+ } = cause. code ( )
4055
+ {
4056
+ let arg_span = self . tcx . hir ( ) . span ( * arg_hir_id) ;
4057
+ let mut sp: MultiSpan = arg_span. into ( ) ;
4058
+
4059
+ sp. push_span_label (
4060
+ arg_span,
4061
+ "the trait solver is unable to infer the \
4062
+ generic types that should be inferred from this argument",
4063
+ ) ;
4064
+ sp. push_span_label (
4065
+ self . tcx . hir ( ) . span ( * call_hir_id) ,
4066
+ "add turbofish arguments to this call to \
4067
+ specify the types manually, even if it's redundant",
4068
+ ) ;
4069
+ diag. span_note (
4070
+ sp,
4071
+ "this is a known limitation of the trait solver that \
4072
+ will be lifted in the future",
4073
+ ) ;
4074
+ } else {
4075
+ let mut sp: MultiSpan = cause. span . into ( ) ;
4076
+ sp. push_span_label (
4077
+ cause. span ,
4078
+ "try adding turbofish arguments to this expression to \
4079
+ specify the types manually, even if it's redundant",
4080
+ ) ;
4081
+ diag. span_note (
4082
+ sp,
4083
+ "this is a known limitation of the trait solver that \
4084
+ will be lifted in the future",
4085
+ ) ;
4086
+ }
4087
+ } ) ;
4088
+ }
4089
+ }
4017
4090
}
4018
4091
4019
4092
/// Add a hint to add a missing borrow or remove an unnecessary one.
0 commit comments