@@ -335,7 +335,7 @@ pub trait TypeErrCtxtExt<'tcx> {
335335 err : & mut Diagnostic ,
336336 trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
337337 ) ;
338- fn function_argument_obligation (
338+ fn note_function_argument_obligation (
339339 & self ,
340340 arg_hir_id : HirId ,
341341 err : & mut Diagnostic ,
@@ -2909,7 +2909,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29092909 ref parent_code,
29102910 ..
29112911 } => {
2912- self . function_argument_obligation (
2912+ self . note_function_argument_obligation (
29132913 arg_hir_id,
29142914 err,
29152915 parent_code,
@@ -3141,23 +3141,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31413141 ) ;
31423142 }
31433143 }
3144- fn function_argument_obligation (
3144+ fn note_function_argument_obligation (
31453145 & self ,
31463146 arg_hir_id : HirId ,
31473147 err : & mut Diagnostic ,
31483148 parent_code : & ObligationCauseCode < ' tcx > ,
31493149 param_env : ty:: ParamEnv < ' tcx > ,
3150- predicate : ty:: Predicate < ' tcx > ,
3150+ failed_pred : ty:: Predicate < ' tcx > ,
31513151 call_hir_id : HirId ,
31523152 ) {
31533153 let tcx = self . tcx ;
31543154 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+ {
31613158 if let hir:: Expr { kind : hir:: ExprKind :: Block ( ..) , .. } = expr {
31623159 let expr = expr. peel_blocks ( ) ;
31633160 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> {
31823179 let mut type_diffs = vec ! [ ] ;
31833180
31843181 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)
31873185 {
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 ( )
31963188 {
31973189 let mut c = CollectAllMismatches {
31983190 infcx : self . infcx ,
31993191 param_env,
32003192 errors : vec ! [ ] ,
32013193 } ;
3202- if let Ok ( _) = c. relate ( trait_pred , trait_predicate ) {
3194+ if let Ok ( _) = c. relate ( where_pred , failed_pred ) {
32033195 type_diffs = c. errors ;
32043196 }
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 ( )
32113200 {
32123201 type_diffs = vec ! [
32133202 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,
32163205 } ) ,
32173206 ] ;
32183207 }
@@ -3227,9 +3216,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
32273216 // If the expression we're calling on is a binding, we want to point at the
32283217 // `let` when talking about the type. Otherwise we'll point at every part
32293218 // 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) ;
32313220 } 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) ;
32333222 }
32343223 }
32353224 let call_node = hir. find ( call_hir_id) ;
0 commit comments