@@ -58,10 +58,10 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
58
58
// Only check against typeck if we didn't already error
59
59
if !hidden. ty . references_error ( ) {
60
60
for concrete_type in locator. typeck_types {
61
- if concrete_type. ty != tcx. erase_regions ( hidden. ty )
62
- && ! ( concrete_type , hidden) . references_error ( )
63
- {
64
- hidden . report_mismatch ( & concrete_type , def_id , tcx ) . emit ( ) ;
61
+ if concrete_type. ty != tcx. erase_regions ( hidden. ty ) {
62
+ if let Ok ( d ) = hidden. build_mismatch_error ( & concrete_type , def_id , tcx ) {
63
+ d . emit ( ) ;
64
+ }
65
65
}
66
66
}
67
67
}
@@ -134,10 +134,10 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
134
134
// Only check against typeck if we didn't already error
135
135
if !hidden. ty . references_error ( ) {
136
136
for concrete_type in locator. typeck_types {
137
- if concrete_type. ty != tcx. erase_regions ( hidden. ty )
138
- && ! ( concrete_type , hidden) . references_error ( )
139
- {
140
- hidden . report_mismatch ( & concrete_type , def_id , tcx ) . emit ( ) ;
137
+ if concrete_type. ty != tcx. erase_regions ( hidden. ty ) {
138
+ if let Ok ( d ) = hidden. build_mismatch_error ( & concrete_type , def_id , tcx ) {
139
+ d . emit ( ) ;
140
+ }
141
141
}
142
142
}
143
143
}
@@ -287,8 +287,10 @@ impl TaitConstraintLocator<'_> {
287
287
if let Some ( & concrete_type) = borrowck_results. concrete_opaque_types . get ( & self . def_id ) {
288
288
debug ! ( ?concrete_type, "found constraint" ) ;
289
289
if let Some ( prev) = & mut self . found {
290
- if concrete_type. ty != prev. ty && !( concrete_type, prev. ty ) . references_error ( ) {
291
- let guar = prev. report_mismatch ( & concrete_type, self . def_id , self . tcx ) . emit ( ) ;
290
+ if concrete_type. ty != prev. ty {
291
+ let ( Ok ( guar) | Err ( guar) ) = prev
292
+ . build_mismatch_error ( & concrete_type, self . def_id , self . tcx )
293
+ . map ( |d| d. emit ( ) ) ;
292
294
prev. ty = Ty :: new_error ( self . tcx , guar) ;
293
295
}
294
296
} else {
@@ -361,11 +363,13 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
361
363
hidden_type. remap_generic_params_to_declaration_params ( opaque_type_key, tcx, true ) ,
362
364
) ;
363
365
if let Some ( prev) = & mut hir_opaque_ty {
364
- if concrete_type. ty != prev. ty && !( concrete_type, prev. ty ) . references_error ( ) {
365
- prev. report_mismatch ( & concrete_type, def_id, tcx) . stash (
366
- tcx. def_span ( opaque_type_key. def_id ) ,
367
- StashKey :: OpaqueHiddenTypeMismatch ,
368
- ) ;
366
+ if concrete_type. ty != prev. ty {
367
+ if let Ok ( d) = prev. build_mismatch_error ( & concrete_type, def_id, tcx) {
368
+ d. stash (
369
+ tcx. def_span ( opaque_type_key. def_id ) ,
370
+ StashKey :: OpaqueHiddenTypeMismatch ,
371
+ ) ;
372
+ }
369
373
}
370
374
} else {
371
375
hir_opaque_ty = Some ( concrete_type) ;
@@ -436,9 +440,12 @@ impl RpitConstraintChecker<'_> {
436
440
437
441
debug ! ( ?concrete_type, "found constraint" ) ;
438
442
439
- if concrete_type. ty != self . found . ty && !( concrete_type, self . found ) . references_error ( )
440
- {
441
- self . found . report_mismatch ( & concrete_type, self . def_id , self . tcx ) . emit ( ) ;
443
+ if concrete_type. ty != self . found . ty {
444
+ if let Ok ( d) =
445
+ self . found . build_mismatch_error ( & concrete_type, self . def_id , self . tcx )
446
+ {
447
+ d. emit ( ) ;
448
+ }
442
449
}
443
450
}
444
451
}
0 commit comments