@@ -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 ) {
@@ -4027,6 +4035,71 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
4027
4035
}
4028
4036
}
4029
4037
}
4038
+
4039
+ fn explain_hrtb_projection (
4040
+ & self ,
4041
+ diag : & mut Diagnostic ,
4042
+ pred : ty:: PolyTraitPredicate < ' tcx > ,
4043
+ param_env : ty:: ParamEnv < ' tcx > ,
4044
+ cause : & ObligationCause < ' tcx > ,
4045
+ ) {
4046
+ if pred. skip_binder ( ) . has_escaping_bound_vars ( ) && pred. skip_binder ( ) . has_non_region_infer ( )
4047
+ {
4048
+ self . probe ( |_| {
4049
+ let ocx = ObligationCtxt :: new ( self ) ;
4050
+ let pred = self . instantiate_binder_with_placeholders ( pred) ;
4051
+ let pred = ocx. normalize ( & ObligationCause :: dummy ( ) , param_env, pred) ;
4052
+ ocx. register_obligation ( Obligation :: new (
4053
+ self . tcx ,
4054
+ ObligationCause :: dummy ( ) ,
4055
+ param_env,
4056
+ pred,
4057
+ ) ) ;
4058
+ if !ocx. select_where_possible ( ) . is_empty ( ) {
4059
+ // encountered errors.
4060
+ return ;
4061
+ }
4062
+
4063
+ if let ObligationCauseCode :: FunctionArgumentObligation {
4064
+ call_hir_id,
4065
+ arg_hir_id,
4066
+ parent_code : _,
4067
+ } = cause. code ( )
4068
+ {
4069
+ let arg_span = self . tcx . hir ( ) . span ( * arg_hir_id) ;
4070
+ let mut sp: MultiSpan = arg_span. into ( ) ;
4071
+
4072
+ sp. push_span_label (
4073
+ arg_span,
4074
+ "the trait solver is unable to infer the \
4075
+ generic types that should be inferred from this argument",
4076
+ ) ;
4077
+ sp. push_span_label (
4078
+ self . tcx . hir ( ) . span ( * call_hir_id) ,
4079
+ "add turbofish arguments to this call to \
4080
+ specify the types manually, even if it's redundant",
4081
+ ) ;
4082
+ diag. span_note (
4083
+ sp,
4084
+ "this is a known limitation of the trait solver that \
4085
+ will be lifted in the future",
4086
+ ) ;
4087
+ } else {
4088
+ let mut sp: MultiSpan = cause. span . into ( ) ;
4089
+ sp. push_span_label (
4090
+ cause. span ,
4091
+ "try adding turbofish arguments to this expression to \
4092
+ specify the types manually, even if it's redundant",
4093
+ ) ;
4094
+ diag. span_note (
4095
+ sp,
4096
+ "this is a known limitation of the trait solver that \
4097
+ will be lifted in the future",
4098
+ ) ;
4099
+ }
4100
+ } ) ;
4101
+ }
4102
+ }
4030
4103
}
4031
4104
4032
4105
/// Add a hint to add a missing borrow or remove an unnecessary one.
0 commit comments