@@ -49,7 +49,7 @@ impl<'tcx> UniverseInfo<'tcx> {
4949 UniverseInfo :: RelateTys { expected, found }
5050 }
5151
52- pub ( crate ) fn report_error (
52+ pub ( crate ) fn report_erroneous_element (
5353 & self ,
5454 mbcx : & mut MirBorrowckCtxt < ' _ , ' _ , ' tcx > ,
5555 placeholder : ty:: PlaceholderRegion ,
@@ -68,7 +68,7 @@ impl<'tcx> UniverseInfo<'tcx> {
6868 mbcx. buffer_error ( err) ;
6969 }
7070 UniverseInfo :: TypeOp ( ref type_op_info) => {
71- type_op_info. report_error ( mbcx, placeholder, error_element, cause) ;
71+ type_op_info. report_erroneous_element ( mbcx, placeholder, error_element, cause) ;
7272 }
7373 UniverseInfo :: Other => {
7474 // FIXME: This error message isn't great, but it doesn't show
@@ -145,8 +145,11 @@ pub(crate) trait TypeOpInfo<'tcx> {
145145 error_region : Option < ty:: Region < ' tcx > > ,
146146 ) -> Option < Diag < ' infcx > > ;
147147
148+ /// Constraints require that `error_element` appear in the
149+ /// values of `placeholder`, but this cannot be proven to
150+ /// hold. Report an error.
148151 #[ instrument( level = "debug" , skip( self , mbcx) ) ]
149- fn report_error (
152+ fn report_erroneous_element (
150153 & self ,
151154 mbcx : & mut MirBorrowckCtxt < ' _ , ' _ , ' tcx > ,
152155 placeholder : ty:: PlaceholderRegion ,
@@ -190,12 +193,7 @@ pub(crate) trait TypeOpInfo<'tcx> {
190193 let nice_error = self . nice_error ( mbcx, cause, placeholder_region, error_region) ;
191194
192195 debug ! ( ?nice_error) ;
193-
194- if let Some ( nice_error) = nice_error {
195- mbcx. buffer_error ( nice_error) ;
196- } else {
197- mbcx. buffer_error ( self . fallback_error ( tcx, span) ) ;
198- }
196+ mbcx. buffer_error ( nice_error. unwrap_or_else ( || self . fallback_error ( tcx, span) ) ) ;
199197 }
200198}
201199
@@ -450,7 +448,8 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
450448 ty:: ReVar ( vid) => universe_of_region ( vid) ,
451449 _ => ty:: UniverseIndex :: ROOT ,
452450 } ;
453- let matches =
451+ // Are the two regions the same?
452+ let regions_the_same =
454453 |a_region : Region < ' tcx > , b_region : Region < ' tcx > | match ( a_region. kind ( ) , b_region. kind ( ) ) {
455454 ( RePlaceholder ( a_p) , RePlaceholder ( b_p) ) => a_p. bound == b_p. bound ,
456455 _ => a_region == b_region,
@@ -459,7 +458,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
459458 |constraint : & Constraint < ' tcx > , cause : & SubregionOrigin < ' tcx > , exact| match * constraint {
460459 Constraint :: RegSubReg ( sub, sup)
461460 if ( ( exact && sup == placeholder_region)
462- || ( !exact && matches ( sup, placeholder_region) ) )
461+ || ( !exact && regions_the_same ( sup, placeholder_region) ) )
463462 && sup != sub =>
464463 {
465464 Some ( ( sub, cause. clone ( ) ) )
@@ -468,23 +467,21 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
468467 if ( exact
469468 && sup == placeholder_region
470469 && !universe_of_region ( vid) . can_name ( placeholder_universe) )
471- || ( !exact && matches ( sup, placeholder_region) ) =>
470+ || ( !exact && regions_the_same ( sup, placeholder_region) ) =>
472471 {
473472 Some ( ( ty:: Region :: new_var ( infcx. tcx , vid) , cause. clone ( ) ) )
474473 }
475474 _ => None ,
476475 } ;
477- let mut info = region_constraints
478- . constraints
479- . iter ( )
480- . find_map ( |( constraint, cause) | check ( constraint, cause, true ) ) ;
481- if info. is_none ( ) {
482- info = region_constraints
476+
477+ let mut find_culprit = |exact_match : bool | {
478+ region_constraints
483479 . constraints
484480 . iter ( )
485- . find_map ( |( constraint, cause) | check ( constraint, cause, false ) ) ;
486- }
487- let ( sub_region, cause) = info?;
481+ . find_map ( |( constraint, cause) | check ( constraint, cause, exact_match) )
482+ } ;
483+
484+ let ( sub_region, cause) = find_culprit ( true ) . or_else ( || find_culprit ( false ) ) ?;
488485
489486 debug ! ( ?sub_region, "cause = {:#?}" , cause) ;
490487 let error = match ( error_region, * sub_region) {
0 commit comments