@@ -335,7 +335,7 @@ pub trait TypeErrCtxtExt<'tcx> {
335
335
err : & mut Diagnostic ,
336
336
trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
337
337
) ;
338
- fn function_argument_obligation (
338
+ fn note_function_argument_obligation (
339
339
& self ,
340
340
arg_hir_id : HirId ,
341
341
err : & mut Diagnostic ,
@@ -2909,7 +2909,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2909
2909
ref parent_code,
2910
2910
..
2911
2911
} => {
2912
- self . function_argument_obligation (
2912
+ self . note_function_argument_obligation (
2913
2913
arg_hir_id,
2914
2914
err,
2915
2915
parent_code,
@@ -3141,23 +3141,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3141
3141
) ;
3142
3142
}
3143
3143
}
3144
- fn function_argument_obligation (
3144
+ fn note_function_argument_obligation (
3145
3145
& self ,
3146
3146
arg_hir_id : HirId ,
3147
3147
err : & mut Diagnostic ,
3148
3148
parent_code : & ObligationCauseCode < ' tcx > ,
3149
3149
param_env : ty:: ParamEnv < ' tcx > ,
3150
- predicate : ty:: Predicate < ' tcx > ,
3150
+ failed_pred : ty:: Predicate < ' tcx > ,
3151
3151
call_hir_id : HirId ,
3152
3152
) {
3153
3153
let tcx = self . tcx ;
3154
3154
let hir = tcx. hir ( ) ;
3155
- if let Some ( Node :: Expr ( expr) ) = hir. find ( arg_hir_id) {
3156
- let parent_id = hir. get_parent_item ( arg_hir_id) ;
3157
- let typeck_results: & TypeckResults < ' tcx > = match & self . typeck_results {
3158
- Some ( t) if t. hir_owner == parent_id => t,
3159
- _ => self . tcx . typeck ( parent_id. def_id ) ,
3160
- } ;
3155
+ if let Some ( Node :: Expr ( expr) ) = hir. find ( arg_hir_id)
3156
+ && let Some ( typeck_results) = & self . typeck_results
3157
+ {
3161
3158
if let hir:: Expr { kind : hir:: ExprKind :: Block ( ..) , .. } = expr {
3162
3159
let expr = expr. peel_blocks ( ) ;
3163
3160
let ty = typeck_results. expr_ty_adjusted_opt ( expr) . unwrap_or ( tcx. ty_error ( ) ) ;
@@ -3182,37 +3179,29 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3182
3179
let mut type_diffs = vec ! [ ] ;
3183
3180
3184
3181
if let ObligationCauseCode :: ExprBindingObligation ( def_id, _, _, idx) = parent_code. deref ( )
3185
- && let predicates = self . tcx . predicates_of ( def_id) . instantiate_identity ( self . tcx )
3186
- && let Some ( pred) = predicates. predicates . get ( * idx)
3182
+ && let Some ( node_substs) = typeck_results. node_substs_opt ( call_hir_id)
3183
+ && let where_clauses = self . tcx . predicates_of ( def_id) . instantiate ( self . tcx , node_substs)
3184
+ && let Some ( where_pred) = where_clauses. predicates . get ( * idx)
3187
3185
{
3188
- if let Ok ( trait_pred) = pred. kind ( ) . try_map_bound ( |pred| match pred {
3189
- ty:: PredicateKind :: Clause ( ty:: Clause :: Trait ( trait_pred) ) => Ok ( trait_pred) ,
3190
- _ => Err ( ( ) ) ,
3191
- } )
3192
- && let Ok ( trait_predicate) = predicate. kind ( ) . try_map_bound ( |pred| match pred {
3193
- ty:: PredicateKind :: Clause ( ty:: Clause :: Trait ( trait_pred) ) => Ok ( trait_pred) ,
3194
- _ => Err ( ( ) ) ,
3195
- } )
3186
+ if let Some ( where_pred) = where_pred. to_opt_poly_trait_pred ( )
3187
+ && let Some ( failed_pred) = failed_pred. to_opt_poly_trait_pred ( )
3196
3188
{
3197
3189
let mut c = CollectAllMismatches {
3198
3190
infcx : self . infcx ,
3199
3191
param_env,
3200
3192
errors : vec ! [ ] ,
3201
3193
} ;
3202
- if let Ok ( _) = c. relate ( trait_pred , trait_predicate ) {
3194
+ if let Ok ( _) = c. relate ( where_pred , failed_pred ) {
3203
3195
type_diffs = c. errors ;
3204
3196
}
3205
- } else if let ty:: PredicateKind :: Clause (
3206
- ty:: Clause :: Projection ( proj)
3207
- ) = pred. kind ( ) . skip_binder ( )
3208
- && let ty:: PredicateKind :: Clause (
3209
- ty:: Clause :: Projection ( projection)
3210
- ) = predicate. kind ( ) . skip_binder ( )
3197
+ } else if let Some ( where_pred) = where_pred. to_opt_poly_projection_pred ( )
3198
+ && let Some ( failed_pred) = failed_pred. to_opt_poly_projection_pred ( )
3199
+ && let Some ( found) = failed_pred. skip_binder ( ) . term . ty ( )
3211
3200
{
3212
3201
type_diffs = vec ! [
3213
3202
Sorts ( ty:: error:: ExpectedFound {
3214
- expected: self . tcx. mk_ty( ty:: Alias ( ty:: Projection , proj . projection_ty) ) ,
3215
- found: projection . term . ty ( ) . unwrap ( ) ,
3203
+ expected: self . tcx. mk_ty( ty:: Alias ( ty:: Projection , where_pred . skip_binder ( ) . projection_ty) ) ,
3204
+ found,
3216
3205
} ) ,
3217
3206
] ;
3218
3207
}
@@ -3227,9 +3216,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3227
3216
// If the expression we're calling on is a binding, we want to point at the
3228
3217
// `let` when talking about the type. Otherwise we'll point at every part
3229
3218
// of the method chain with the type.
3230
- self . point_at_chain ( binding_expr, typeck_results, type_diffs, param_env, err) ;
3219
+ self . point_at_chain ( binding_expr, & typeck_results, type_diffs, param_env, err) ;
3231
3220
} else {
3232
- self . point_at_chain ( expr, typeck_results, type_diffs, param_env, err) ;
3221
+ self . point_at_chain ( expr, & typeck_results, type_diffs, param_env, err) ;
3233
3222
}
3234
3223
}
3235
3224
let call_node = hir. find ( call_hir_id) ;
0 commit comments