diff options
| author | Gary Guo <gary@garyguo.net> | 2021-10-09 06:41:05 +0100 |
|---|---|---|
| committer | Gary Guo <gary@garyguo.net> | 2021-10-09 06:49:47 +0100 |
| commit | 7275cfa47cf3fdbf41c2ad859ac937bffe5923a4 (patch) | |
| tree | 8244d8789a6228e7d7d5055bcad1da4b8db46161 /compiler | |
| parent | d7f8a0678012f8a0fa24609345b777af4a6a4c04 (diff) | |
| download | rust-7275cfa47cf3fdbf41c2ad859ac937bffe5923a4.tar.gz rust-7275cfa47cf3fdbf41c2ad859ac937bffe5923a4.zip | |
Explicit `PlaceAncestryRelation::SamePlace` and handle like `Descendant`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_typeck/src/check/upvar.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 9b94fda5153..3a10988bba0 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -65,6 +65,7 @@ use std::iter; enum PlaceAncestryRelation { Ancestor, Descendant, + SamePlace, Divergent, } @@ -564,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for possible_ancestor in min_cap_list.iter_mut() { match determine_place_ancestry_relation(&place, &possible_ancestor.place) { // current place is descendant of possible_ancestor - PlaceAncestryRelation::Descendant => { + PlaceAncestryRelation::Descendant | PlaceAncestryRelation::SamePlace => { ancestor_found = true; let backup_path_expr_id = possible_ancestor.info.path_expr_id; @@ -2281,12 +2282,14 @@ fn determine_place_ancestry_relation( iter::zip(projections_a, projections_b).all(|(proj_a, proj_b)| proj_a.kind == proj_b.kind); if same_initial_projections { + use std::cmp::Ordering; + // First min(n, m) projections are the same // Select Ancestor/Descendant - if projections_b.len() >= projections_a.len() { - PlaceAncestryRelation::Ancestor - } else { - PlaceAncestryRelation::Descendant + match projections_b.len().cmp(&projections_a.len()) { + Ordering::Greater => PlaceAncestryRelation::Ancestor, + Ordering::Equal => PlaceAncestryRelation::SamePlace, + Ordering::Less => PlaceAncestryRelation::Descendant, } } else { PlaceAncestryRelation::Divergent |
