@@ -58,10 +58,10 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
5858 // Only check against typeck if we didn't already error
5959 if !hidden. ty . references_error ( ) {
6060 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+ }
6565 }
6666 }
6767 }
@@ -134,10 +134,10 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
134134 // Only check against typeck if we didn't already error
135135 if !hidden. ty . references_error ( ) {
136136 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+ }
141141 }
142142 }
143143 }
@@ -287,8 +287,10 @@ impl TaitConstraintLocator<'_> {
287287 if let Some ( & concrete_type) = borrowck_results. concrete_opaque_types . get ( & self . def_id ) {
288288 debug ! ( ?concrete_type, "found constraint" ) ;
289289 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 ( ) ) ;
292294 prev. ty = Ty :: new_error ( self . tcx , guar) ;
293295 }
294296 } else {
@@ -361,11 +363,13 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
361363 hidden_type. remap_generic_params_to_declaration_params ( opaque_type_key, tcx, true ) ,
362364 ) ;
363365 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+ }
369373 }
370374 } else {
371375 hir_opaque_ty = Some ( concrete_type) ;
@@ -436,9 +440,12 @@ impl RpitConstraintChecker<'_> {
436440
437441 debug ! ( ?concrete_type, "found constraint" ) ;
438442
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+ }
442449 }
443450 }
444451 }
0 commit comments