Skip to content

Commit e2f363c

Browse files
nbdd0121cuviper
authored andcommitted
Explicit PlaceAncestryRelation::SamePlace and handle like Descendant
(cherry picked from commit 7275cfa)
1 parent 0ee5315 commit e2f363c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

compiler/rustc_typeck/src/check/upvar.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use std::iter;
6565
enum PlaceAncestryRelation {
6666
Ancestor,
6767
Descendant,
68+
SamePlace,
6869
Divergent,
6970
}
7071

@@ -565,7 +566,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
565566
for possible_ancestor in min_cap_list.iter_mut() {
566567
match determine_place_ancestry_relation(&place, &possible_ancestor.place) {
567568
// current place is descendant of possible_ancestor
568-
PlaceAncestryRelation::Descendant => {
569+
PlaceAncestryRelation::Descendant | PlaceAncestryRelation::SamePlace => {
569570
ancestor_found = true;
570571
let backup_path_expr_id = possible_ancestor.info.path_expr_id;
571572

@@ -2306,12 +2307,14 @@ fn determine_place_ancestry_relation(
23062307
iter::zip(projections_a, projections_b).all(|(proj_a, proj_b)| proj_a.kind == proj_b.kind);
23072308

23082309
if same_initial_projections {
2310+
use std::cmp::Ordering;
2311+
23092312
// First min(n, m) projections are the same
23102313
// Select Ancestor/Descendant
2311-
if projections_b.len() >= projections_a.len() {
2312-
PlaceAncestryRelation::Ancestor
2313-
} else {
2314-
PlaceAncestryRelation::Descendant
2314+
match projections_b.len().cmp(&projections_a.len()) {
2315+
Ordering::Greater => PlaceAncestryRelation::Ancestor,
2316+
Ordering::Equal => PlaceAncestryRelation::SamePlace,
2317+
Ordering::Less => PlaceAncestryRelation::Descendant,
23152318
}
23162319
} else {
23172320
PlaceAncestryRelation::Divergent

0 commit comments

Comments
 (0)