@@ -25,10 +25,9 @@ use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
2525use rustc_hir:: { Expr , HirId } ;
2626use rustc_infer:: infer:: error_reporting:: TypeErrCtxt ;
2727use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
28- use rustc_infer:: infer:: { InferOk , LateBoundRegionConversionTime } ;
28+ use rustc_infer:: infer:: { DefineOpaqueTypes , InferOk , LateBoundRegionConversionTime } ;
2929use rustc_middle:: hir:: map;
3030use rustc_middle:: ty:: error:: TypeError :: { self , Sorts } ;
31- use rustc_middle:: ty:: relate:: TypeRelation ;
3231use rustc_middle:: ty:: {
3332 self , suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind ,
3433 GeneratorDiagnosticData , GeneratorInteriorTypeCause , Infer , InferTy , InternalSubsts ,
@@ -39,9 +38,9 @@ use rustc_span::def_id::LocalDefId;
3938use rustc_span:: symbol:: { sym, Ident , Symbol } ;
4039use rustc_span:: { BytePos , DesugaringKind , ExpnKind , MacroKind , Span , DUMMY_SP } ;
4140use rustc_target:: spec:: abi;
41+ use std:: iter;
4242use std:: ops:: Deref ;
4343
44- use super :: method_chain:: CollectAllMismatches ;
4544use super :: InferCtxtPrivExt ;
4645use crate :: infer:: InferCtxtExt as _;
4746use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -319,6 +318,7 @@ pub trait TypeErrCtxtExt<'tcx> {
319318
320319 fn note_obligation_cause_code < T > (
321320 & self ,
321+ body_id : LocalDefId ,
322322 err : & mut Diagnostic ,
323323 predicate : T ,
324324 param_env : ty:: ParamEnv < ' tcx > ,
@@ -359,8 +359,9 @@ pub trait TypeErrCtxtExt<'tcx> {
359359 ) ;
360360 fn note_function_argument_obligation (
361361 & self ,
362- arg_hir_id : HirId ,
362+ body_id : LocalDefId ,
363363 err : & mut Diagnostic ,
364+ arg_hir_id : HirId ,
364365 parent_code : & ObligationCauseCode < ' tcx > ,
365366 param_env : ty:: ParamEnv < ' tcx > ,
366367 predicate : ty:: Predicate < ' tcx > ,
@@ -2742,6 +2743,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
27422743 // bound that introduced the obligation (e.g. `T: Send`).
27432744 debug ! ( ?next_code) ;
27442745 self . note_obligation_cause_code (
2746+ obligation. cause . body_id ,
27452747 err,
27462748 obligation. predicate ,
27472749 obligation. param_env ,
@@ -2753,6 +2755,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
27532755
27542756 fn note_obligation_cause_code < T > (
27552757 & self ,
2758+ body_id : LocalDefId ,
27562759 err : & mut Diagnostic ,
27572760 predicate : T ,
27582761 param_env : ty:: ParamEnv < ' tcx > ,
@@ -3152,6 +3155,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31523155 // #74711: avoid a stack overflow
31533156 ensure_sufficient_stack ( || {
31543157 self . note_obligation_cause_code (
3158+ body_id,
31553159 err,
31563160 parent_predicate,
31573161 param_env,
@@ -3163,6 +3167,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31633167 } else {
31643168 ensure_sufficient_stack ( || {
31653169 self . note_obligation_cause_code (
3170+ body_id,
31663171 err,
31673172 parent_predicate,
31683173 param_env,
@@ -3292,6 +3297,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
32923297 // #74711: avoid a stack overflow
32933298 ensure_sufficient_stack ( || {
32943299 self . note_obligation_cause_code (
3300+ body_id,
32953301 err,
32963302 parent_predicate,
32973303 param_env,
@@ -3307,6 +3313,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
33073313 // #74711: avoid a stack overflow
33083314 ensure_sufficient_stack ( || {
33093315 self . note_obligation_cause_code (
3316+ body_id,
33103317 err,
33113318 parent_predicate,
33123319 param_env,
@@ -3323,15 +3330,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
33233330 ..
33243331 } => {
33253332 self . note_function_argument_obligation (
3326- arg_hir_id ,
3333+ body_id ,
33273334 err,
3335+ arg_hir_id,
33283336 parent_code,
33293337 param_env,
33303338 predicate,
33313339 call_hir_id,
33323340 ) ;
33333341 ensure_sufficient_stack ( || {
33343342 self . note_obligation_cause_code (
3343+ body_id,
33353344 err,
33363345 predicate,
33373346 param_env,
@@ -3553,8 +3562,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
35533562 }
35543563 fn note_function_argument_obligation (
35553564 & self ,
3556- arg_hir_id : HirId ,
3565+ body_id : LocalDefId ,
35573566 err : & mut Diagnostic ,
3567+ arg_hir_id : HirId ,
35583568 parent_code : & ObligationCauseCode < ' tcx > ,
35593569 param_env : ty:: ParamEnv < ' tcx > ,
35603570 failed_pred : ty:: Predicate < ' tcx > ,
@@ -3587,7 +3597,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
35873597 // to an associated type (as seen from `trait_pred`) in the predicate. Like in
35883598 // trait_pred `S: Sum<<Self as Iterator>::Item>` and predicate `i32: Sum<&()>`
35893599 let mut type_diffs = vec ! [ ] ;
3590-
35913600 if let ObligationCauseCode :: ExprBindingObligation ( def_id, _, _, idx) = parent_code. deref ( )
35923601 && let Some ( node_substs) = typeck_results. node_substs_opt ( call_hir_id)
35933602 && let where_clauses = self . tcx . predicates_of ( def_id) . instantiate ( self . tcx , node_substs)
@@ -3596,14 +3605,26 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
35963605 if let Some ( where_pred) = where_pred. to_opt_poly_trait_pred ( )
35973606 && let Some ( failed_pred) = failed_pred. to_opt_poly_trait_pred ( )
35983607 {
3599- let mut c = CollectAllMismatches {
3600- infcx : self . infcx ,
3601- param_env,
3602- errors : vec ! [ ] ,
3608+ let where_pred = self . instantiate_binder_with_placeholders ( where_pred) ;
3609+ let failed_pred = self . instantiate_binder_with_fresh_vars (
3610+ expr. span ,
3611+ LateBoundRegionConversionTime :: FnCall ,
3612+ failed_pred
3613+ ) ;
3614+
3615+ let zipped =
3616+ iter:: zip ( where_pred. trait_ref . substs , failed_pred. trait_ref . substs ) ;
3617+ for ( expected, actual) in zipped {
3618+ self . probe ( |_| {
3619+ match self
3620+ . at ( & ObligationCause :: misc ( expr. span , body_id) , param_env)
3621+ . eq ( DefineOpaqueTypes :: No , expected, actual)
3622+ {
3623+ Ok ( _) => ( ) , // We ignore nested obligations here for now.
3624+ Err ( err) => type_diffs. push ( err) ,
3625+ }
3626+ } )
36033627 } ;
3604- if let Ok ( _) = c. relate ( where_pred, failed_pred) {
3605- type_diffs = c. errors ;
3606- }
36073628 } else if let Some ( where_pred) = where_pred. to_opt_poly_projection_pred ( )
36083629 && let Some ( failed_pred) = failed_pred. to_opt_poly_projection_pred ( )
36093630 && let Some ( found) = failed_pred. skip_binder ( ) . term . ty ( )
0 commit comments