Skip to content

Commit 6f7cb8c

Browse files
committed
Override LoanPath Eq impl to enforce invariant: eq lp's always have eq types.
1 parent 1217b82 commit 6f7cb8c

File tree

1 file changed

+22
-1
lines changed
  • src/librustc/middle/borrowck

1 file changed

+22
-1
lines changed

src/librustc/middle/borrowck/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,33 @@ impl<'tcx> Loan<'tcx> {
282282
}
283283
}
284284

285-
#[deriving(PartialEq, Eq, Hash, Show)]
285+
#[deriving(Eq, Hash, Show)]
286286
pub struct LoanPath<'tcx> {
287287
kind: LoanPathKind<'tcx>,
288288
ty: ty::Ty<'tcx>,
289289
}
290290

291+
impl<'tcx> LoanPath<'tcx> {
292+
pub fn eq_debug(&self, that: &LoanPath<'tcx>, tcx: &ty::ctxt<'tcx>) -> bool {
293+
let r = self.kind == that.kind;
294+
if r && self.ty != that.ty {
295+
panic!("eq variants ineq types: {} == {}, {} != {}",
296+
self.repr(tcx), that.repr(tcx),
297+
self.ty.repr(tcx), that.ty.repr(tcx));
298+
}
299+
r
300+
}
301+
}
302+
303+
impl<'tcx> PartialEq for LoanPath<'tcx> {
304+
fn eq(&self, that: &LoanPath<'tcx>) -> bool {
305+
let r = self.kind == that.kind;
306+
debug_assert!(self.ty == that.ty || !r,
307+
"Somehow loan paths are equal though their tys are not.");
308+
r
309+
}
310+
}
311+
291312
#[deriving(PartialEq, Eq, Hash, Show)]
292313
pub enum LoanPathKind<'tcx> {
293314
LpVar(ast::NodeId), // `x` in doc.rs

0 commit comments

Comments
 (0)