@@ -25,10 +25,9 @@ use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
25
25
use rustc_hir:: { Expr , HirId } ;
26
26
use rustc_infer:: infer:: error_reporting:: TypeErrCtxt ;
27
27
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
28
- use rustc_infer:: infer:: { InferOk , LateBoundRegionConversionTime } ;
28
+ use rustc_infer:: infer:: { DefineOpaqueTypes , InferOk , LateBoundRegionConversionTime } ;
29
29
use rustc_middle:: hir:: map;
30
30
use rustc_middle:: ty:: error:: TypeError :: { self , Sorts } ;
31
- use rustc_middle:: ty:: relate:: TypeRelation ;
32
31
use rustc_middle:: ty:: {
33
32
self , suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind ,
34
33
GeneratorDiagnosticData , GeneratorInteriorTypeCause , Infer , InferTy , InternalSubsts ,
@@ -39,9 +38,9 @@ use rustc_span::def_id::LocalDefId;
39
38
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
40
39
use rustc_span:: { BytePos , DesugaringKind , ExpnKind , MacroKind , Span , DUMMY_SP } ;
41
40
use rustc_target:: spec:: abi;
41
+ use std:: iter;
42
42
use std:: ops:: Deref ;
43
43
44
- use super :: method_chain:: CollectAllMismatches ;
45
44
use super :: InferCtxtPrivExt ;
46
45
use crate :: infer:: InferCtxtExt as _;
47
46
use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -319,6 +318,7 @@ pub trait TypeErrCtxtExt<'tcx> {
319
318
320
319
fn note_obligation_cause_code < T > (
321
320
& self ,
321
+ body_id : LocalDefId ,
322
322
err : & mut Diagnostic ,
323
323
predicate : T ,
324
324
param_env : ty:: ParamEnv < ' tcx > ,
@@ -359,8 +359,9 @@ pub trait TypeErrCtxtExt<'tcx> {
359
359
) ;
360
360
fn note_function_argument_obligation (
361
361
& self ,
362
- arg_hir_id : HirId ,
362
+ body_id : LocalDefId ,
363
363
err : & mut Diagnostic ,
364
+ arg_hir_id : HirId ,
364
365
parent_code : & ObligationCauseCode < ' tcx > ,
365
366
param_env : ty:: ParamEnv < ' tcx > ,
366
367
predicate : ty:: Predicate < ' tcx > ,
@@ -2742,6 +2743,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2742
2743
// bound that introduced the obligation (e.g. `T: Send`).
2743
2744
debug ! ( ?next_code) ;
2744
2745
self . note_obligation_cause_code (
2746
+ obligation. cause . body_id ,
2745
2747
err,
2746
2748
obligation. predicate ,
2747
2749
obligation. param_env ,
@@ -2753,6 +2755,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2753
2755
2754
2756
fn note_obligation_cause_code < T > (
2755
2757
& self ,
2758
+ body_id : LocalDefId ,
2756
2759
err : & mut Diagnostic ,
2757
2760
predicate : T ,
2758
2761
param_env : ty:: ParamEnv < ' tcx > ,
@@ -3152,6 +3155,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3152
3155
// #74711: avoid a stack overflow
3153
3156
ensure_sufficient_stack ( || {
3154
3157
self . note_obligation_cause_code (
3158
+ body_id,
3155
3159
err,
3156
3160
parent_predicate,
3157
3161
param_env,
@@ -3163,6 +3167,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3163
3167
} else {
3164
3168
ensure_sufficient_stack ( || {
3165
3169
self . note_obligation_cause_code (
3170
+ body_id,
3166
3171
err,
3167
3172
parent_predicate,
3168
3173
param_env,
@@ -3292,6 +3297,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3292
3297
// #74711: avoid a stack overflow
3293
3298
ensure_sufficient_stack ( || {
3294
3299
self . note_obligation_cause_code (
3300
+ body_id,
3295
3301
err,
3296
3302
parent_predicate,
3297
3303
param_env,
@@ -3307,6 +3313,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3307
3313
// #74711: avoid a stack overflow
3308
3314
ensure_sufficient_stack ( || {
3309
3315
self . note_obligation_cause_code (
3316
+ body_id,
3310
3317
err,
3311
3318
parent_predicate,
3312
3319
param_env,
@@ -3323,15 +3330,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3323
3330
..
3324
3331
} => {
3325
3332
self . note_function_argument_obligation (
3326
- arg_hir_id ,
3333
+ body_id ,
3327
3334
err,
3335
+ arg_hir_id,
3328
3336
parent_code,
3329
3337
param_env,
3330
3338
predicate,
3331
3339
call_hir_id,
3332
3340
) ;
3333
3341
ensure_sufficient_stack ( || {
3334
3342
self . note_obligation_cause_code (
3343
+ body_id,
3335
3344
err,
3336
3345
predicate,
3337
3346
param_env,
@@ -3553,8 +3562,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3553
3562
}
3554
3563
fn note_function_argument_obligation (
3555
3564
& self ,
3556
- arg_hir_id : HirId ,
3565
+ body_id : LocalDefId ,
3557
3566
err : & mut Diagnostic ,
3567
+ arg_hir_id : HirId ,
3558
3568
parent_code : & ObligationCauseCode < ' tcx > ,
3559
3569
param_env : ty:: ParamEnv < ' tcx > ,
3560
3570
failed_pred : ty:: Predicate < ' tcx > ,
@@ -3587,7 +3597,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3587
3597
// to an associated type (as seen from `trait_pred`) in the predicate. Like in
3588
3598
// trait_pred `S: Sum<<Self as Iterator>::Item>` and predicate `i32: Sum<&()>`
3589
3599
let mut type_diffs = vec ! [ ] ;
3590
-
3591
3600
if let ObligationCauseCode :: ExprBindingObligation ( def_id, _, _, idx) = parent_code. deref ( )
3592
3601
&& let Some ( node_substs) = typeck_results. node_substs_opt ( call_hir_id)
3593
3602
&& 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> {
3596
3605
if let Some ( where_pred) = where_pred. to_opt_poly_trait_pred ( )
3597
3606
&& let Some ( failed_pred) = failed_pred. to_opt_poly_trait_pred ( )
3598
3607
{
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
+ } )
3603
3627
} ;
3604
- if let Ok ( _) = c. relate ( where_pred, failed_pred) {
3605
- type_diffs = c. errors ;
3606
- }
3607
3628
} else if let Some ( where_pred) = where_pred. to_opt_poly_projection_pred ( )
3608
3629
&& let Some ( failed_pred) = failed_pred. to_opt_poly_projection_pred ( )
3609
3630
&& let Some ( found) = failed_pred. skip_binder ( ) . term . ty ( )
0 commit comments