Skip to content

Commit 7275cfa

Browse files
committed
Explicit PlaceAncestryRelation::SamePlace and handle like Descendant
1 parent d7f8a06 commit 7275cfa

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

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

@@ -2281,12 +2282,14 @@ fn determine_place_ancestry_relation(
22812282
iter::zip(projections_a, projections_b).all(|(proj_a, proj_b)| proj_a.kind == proj_b.kind);
22822283

22832284
if same_initial_projections {
2285+
use std::cmp::Ordering;
2286+
22842287
// First min(n, m) projections are the same
22852288
// Select Ancestor/Descendant
2286-
if projections_b.len() >= projections_a.len() {
2287-
PlaceAncestryRelation::Ancestor
2288-
} else {
2289-
PlaceAncestryRelation::Descendant
2289+
match projections_b.len().cmp(&projections_a.len()) {
2290+
Ordering::Greater => PlaceAncestryRelation::Ancestor,
2291+
Ordering::Equal => PlaceAncestryRelation::SamePlace,
2292+
Ordering::Less => PlaceAncestryRelation::Descendant,
22902293
}
22912294
} else {
22922295
PlaceAncestryRelation::Divergent

0 commit comments

Comments
 (0)