@@ -928,32 +928,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
928
928
}
929
929
}
930
930
931
- /// Converts a region inference variable into a `ty::Region` that
932
- /// we can use for error reporting. If `r` is universally bound,
933
- /// then we use the name that we have on record for it. If `r` is
934
- /// existentially bound, then we check its inferred value and try
935
- /// to find a good name from that. Returns `None` if we can't find
936
- /// one (e.g., this is just some random part of the CFG).
937
- pub fn to_error_region ( & self , r : RegionVid ) -> Option < ty:: Region < ' tcx > > {
938
- self . to_error_region_vid ( r) . and_then ( |r| self . definitions [ r] . external_name )
939
- }
940
-
941
- /// Returns the [RegionVid] corresponding to the region returned by
942
- /// `to_error_region`.
943
- pub fn to_error_region_vid ( & self , r : RegionVid ) -> Option < RegionVid > {
944
- if self . universal_regions . is_universal_region ( r) {
945
- Some ( r)
946
- } else {
947
- let r_scc = self . constraint_sccs . scc ( r) ;
948
- let upper_bound = self . universal_upper_bound ( r) ;
949
- if self . scc_values . contains ( r_scc, upper_bound) {
950
- self . to_error_region_vid ( upper_bound)
951
- } else {
952
- None
953
- }
954
- }
955
- }
956
-
957
931
/// Invoked when we have some type-test (e.g., `T: 'X`) that we cannot
958
932
/// prove to be satisfied. If this is a closure, we will attempt to
959
933
/// "promote" this type-test into our `ClosureRegionRequirements` and
@@ -1164,7 +1138,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1164
1138
/// include the CFG anyhow.
1165
1139
/// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding
1166
1140
/// a result `'y`.
1167
- fn universal_upper_bound ( & self , r : RegionVid ) -> RegionVid {
1141
+ pub ( in crate :: borrow_check ) fn universal_upper_bound ( & self , r : RegionVid ) -> RegionVid {
1168
1142
debug ! ( "universal_upper_bound(r={:?}={})" , r, self . region_value_str( r) ) ;
1169
1143
1170
1144
// Find the smallest universal region that contains all other
@@ -1458,19 +1432,34 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1458
1432
debug ! ( "check_polonius_subset_errors: subset_error longer_fr={:?},\
1459
1433
shorter_fr={:?}", longer_fr, shorter_fr) ;
1460
1434
1461
- self . report_or_propagate_universal_region_error (
1435
+ let propagated = self . try_propagate_universal_region_error (
1462
1436
* longer_fr,
1463
1437
* shorter_fr,
1464
- infcx,
1465
1438
body,
1466
- local_names,
1467
- upvars,
1468
- mir_def_id,
1469
1439
& mut propagated_outlives_requirements,
1470
- & mut outlives_suggestion,
1471
- errors_buffer,
1472
- region_naming,
1473
1440
) ;
1441
+ if !propagated {
1442
+ // If we are not in a context where we can't propagate errors, or we
1443
+ // could not shrink `fr` to something smaller, then just report an
1444
+ // error.
1445
+ //
1446
+ // Note: in this case, we use the unapproximated regions to report the
1447
+ // error. This gives better error messages in some cases.
1448
+ let db = self . report_error (
1449
+ body,
1450
+ local_names,
1451
+ upvars,
1452
+ infcx,
1453
+ mir_def_id,
1454
+ * longer_fr,
1455
+ NLLRegionVariableOrigin :: FreeRegion ,
1456
+ * shorter_fr,
1457
+ & mut outlives_suggestion,
1458
+ region_naming,
1459
+ ) ;
1460
+
1461
+ db. buffer ( errors_buffer) ;
1462
+ }
1474
1463
}
1475
1464
1476
1465
// Handle the placeholder errors as usual, until the chalk-rustc-polonius triumvirate has
@@ -1594,48 +1583,59 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1594
1583
return None ;
1595
1584
}
1596
1585
1597
- self . report_or_propagate_universal_region_error (
1586
+ let propagated = self . try_propagate_universal_region_error (
1598
1587
longer_fr,
1599
1588
shorter_fr,
1600
- infcx,
1601
1589
body,
1602
- local_names,
1603
- upvars,
1604
- mir_def_id,
1605
1590
propagated_outlives_requirements,
1606
- outlives_suggestion,
1607
- errors_buffer,
1608
- region_naming,
1609
- )
1591
+ ) ;
1592
+
1593
+ if propagated {
1594
+ None
1595
+ } else {
1596
+ // If we are not in a context where we can't propagate errors, or we
1597
+ // could not shrink `fr` to something smaller, then just report an
1598
+ // error.
1599
+ //
1600
+ // Note: in this case, we use the unapproximated regions to report the
1601
+ // error. This gives better error messages in some cases.
1602
+ let db = self . report_error (
1603
+ body,
1604
+ local_names,
1605
+ upvars,
1606
+ infcx,
1607
+ mir_def_id,
1608
+ longer_fr,
1609
+ NLLRegionVariableOrigin :: FreeRegion ,
1610
+ shorter_fr,
1611
+ outlives_suggestion,
1612
+ region_naming,
1613
+ ) ;
1614
+
1615
+ db. buffer ( errors_buffer) ;
1616
+
1617
+ Some ( ErrorReported )
1618
+ }
1610
1619
}
1611
1620
1612
- fn report_or_propagate_universal_region_error (
1621
+ /// Attempt to propagate a region error (e.g. `'a: 'b`) that is not met to a closure's
1622
+ /// creator. If we cannot, then the caller should report an error to the user.
1623
+ ///
1624
+ /// Returns `true` if the error was propagated, and `false` otherwise.
1625
+ fn try_propagate_universal_region_error (
1613
1626
& self ,
1614
1627
longer_fr : RegionVid ,
1615
1628
shorter_fr : RegionVid ,
1616
- infcx : & InferCtxt < ' _ , ' tcx > ,
1617
1629
body : & Body < ' tcx > ,
1618
- local_names : & IndexVec < Local , Option < Symbol > > ,
1619
- upvars : & [ Upvar ] ,
1620
- mir_def_id : DefId ,
1621
1630
propagated_outlives_requirements : & mut Option < & mut Vec < ClosureOutlivesRequirement < ' tcx > > > ,
1622
- outlives_suggestion : & mut OutlivesSuggestionBuilder < ' _ > ,
1623
- errors_buffer : & mut Vec < Diagnostic > ,
1624
- region_naming : & mut RegionErrorNamingCtx ,
1625
- ) -> Option < ErrorReported > {
1626
- debug ! (
1627
- "report_or_propagate_universal_region_error: fr={:?} does not outlive shorter_fr={:?}" ,
1628
- longer_fr, shorter_fr,
1629
- ) ;
1630
-
1631
+ ) -> bool {
1631
1632
if let Some ( propagated_outlives_requirements) = propagated_outlives_requirements {
1632
1633
// Shrink `longer_fr` until we find a non-local region (if we do).
1633
1634
// We'll call it `fr-` -- it's ever so slightly smaller than
1634
1635
// `longer_fr`.
1635
-
1636
1636
if let Some ( fr_minus) =
1637
1637
self . universal_region_relations . non_local_lower_bound ( longer_fr) {
1638
- debug ! ( "report_or_propagate_universal_region_error : fr_minus={:?}" , fr_minus) ;
1638
+ debug ! ( "try_propagate_universal_region_error : fr_minus={:?}" , fr_minus) ;
1639
1639
1640
1640
let blame_span_category =
1641
1641
self . find_outlives_blame_span ( body, longer_fr,
@@ -1648,7 +1648,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1648
1648
. universal_region_relations
1649
1649
. non_local_upper_bounds ( & shorter_fr) ;
1650
1650
debug ! (
1651
- "report_or_propagate_universal_region_error : shorter_fr_plus={:?}" ,
1651
+ "try_propagate_universal_region_error : shorter_fr_plus={:?}" ,
1652
1652
shorter_fr_plus
1653
1653
) ;
1654
1654
for & & fr in & shorter_fr_plus {
@@ -1660,32 +1660,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1660
1660
category : blame_span_category. 0 ,
1661
1661
} ) ;
1662
1662
}
1663
- return None ;
1663
+ return true ;
1664
1664
}
1665
1665
}
1666
1666
1667
- // If we are not in a context where we can't propagate errors, or we
1668
- // could not shrink `fr` to something smaller, then just report an
1669
- // error.
1670
- //
1671
- // Note: in this case, we use the unapproximated regions to report the
1672
- // error. This gives better error messages in some cases.
1673
- let db = self . report_error (
1674
- body,
1675
- local_names,
1676
- upvars,
1677
- infcx,
1678
- mir_def_id,
1679
- longer_fr,
1680
- NLLRegionVariableOrigin :: FreeRegion ,
1681
- shorter_fr,
1682
- outlives_suggestion,
1683
- region_naming,
1684
- ) ;
1685
-
1686
- db. buffer ( errors_buffer) ;
1687
-
1688
- Some ( ErrorReported )
1667
+ false
1689
1668
}
1690
1669
1691
1670
fn check_bound_universal_region (
0 commit comments