Skip to content

Commit ed1411c

Browse files
committed
Implement IsPrefixOf trait for NeoPlace
1 parent 7d10e8e commit ed1411c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/librustc_mir/borrow_check/prefixes.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use super::MirBorrowckCtxt;
1111

1212
use rustc::hir;
1313
use rustc::ty::{self, TyCtxt};
14-
use rustc::mir::{Mir, Place, ProjectionElem};
14+
use rustc::mir::{Mir, Place, NeoPlace, ProjectionElem};
1515

1616
pub trait IsPrefixOf<'tcx> {
17-
fn is_prefix_of(&self, other: &Place<'tcx>) -> bool;
17+
fn is_prefix_of(&self, other: &Self) -> bool;
1818
}
1919

2020
impl<'tcx> IsPrefixOf<'tcx> for Place<'tcx> {
@@ -36,6 +36,17 @@ impl<'tcx> IsPrefixOf<'tcx> for Place<'tcx> {
3636
}
3737
}
3838

39+
impl<'tcx> IsPrefixOf<'tcx> for NeoPlace<'tcx> {
40+
fn is_prefix_of(&self, other: &NeoPlace<'tcx>) -> bool {
41+
self.base == other.base
42+
&& self.elems.len() <= other.elems.len()
43+
&& self
44+
.elems
45+
.iter()
46+
.zip(other.elems)
47+
.all(|(elem, other_elem)| elem == other_elem)
48+
}
49+
}
3950

4051
pub(super) struct Prefixes<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
4152
mir: &'cx Mir<'tcx>,

0 commit comments

Comments
 (0)