@@ -1875,6 +1875,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1875
1875
/// `results`. The paths are stored as a series of
1876
1876
/// `ConstraintIndex` values -- in other words, a list of *edges*.
1877
1877
///
1878
+ /// We have a special handling for `TypeAnnotation` constraints in that we don't report a path
1879
+ /// with such constraint unless we're sure that no other path exists.
1880
+ /// This enables us to say that a lifetime annotation is unnecessarily restrictive if it
1881
+ /// appears in the constraint path, and thus we can safely suggest removing it.
1882
+ ///
1878
1883
/// Returns: a series of constraints as well as the region `R`
1879
1884
/// that passed the target test.
1880
1885
pub ( crate ) fn find_constraint_paths_between_regions (
@@ -1888,10 +1893,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1888
1893
// Use a deque so that we do a breadth-first search. We will
1889
1894
// stop at the first match, which ought to be the shortest
1890
1895
// path (fewest constraints).
1891
- let mut deque = VecDeque :: new ( ) ;
1892
- deque. push_back ( from_region) ;
1896
+ let mut deque_p0 = VecDeque :: new ( ) ; // Higher priority queue.
1897
+ let mut deque_p1 = VecDeque :: new ( ) ; // Lower priority queue. See method docs.
1898
+ deque_p0. push_back ( from_region) ;
1893
1899
1894
- while let Some ( r) = deque . pop_front ( ) {
1900
+ while let Some ( r) = deque_p0 . pop_front ( ) . or_else ( || deque_p1 . pop_front ( ) ) {
1895
1901
debug ! (
1896
1902
"find_constraint_paths_between_regions: from_region={:?} r={:?} value={}" ,
1897
1903
from_region,
@@ -1939,8 +1945,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1939
1945
debug_assert_eq ! ( constraint. sup, r) ;
1940
1946
let sub_region = constraint. sub ;
1941
1947
if let Trace :: NotVisited = context[ sub_region] {
1948
+ let constraint_category = constraint. category ;
1942
1949
context[ sub_region] = Trace :: FromOutlivesConstraint ( constraint) ;
1943
- deque. push_back ( sub_region) ;
1950
+ match constraint_category {
1951
+ ConstraintCategory :: TypeAnnotation => deque_p1. push_back ( sub_region) ,
1952
+ // FIXME A `ClosureBounds` constraint can be mapped to `TypeAnnotation`
1953
+ // later. It should be treated as such here but we're ingoring that.
1954
+ _ => deque_p0. push_back ( sub_region) ,
1955
+ }
1944
1956
}
1945
1957
} ;
1946
1958
0 commit comments