Skip to content

Commit 933d481

Browse files
authored
Rollup merge of rust-lang#36004 - petrochenkov:hashloan, r=arielb1
rustc_borrowck: Don't hash types in loan paths 1) Types for equal loan paths are not always equal, they can sometimes differ in lifetimes, making equal loan paths hash differently. Example: https://github.com/rust-lang/rust/blob/71bdeea561355ba5adbc9a1f44f4f866a75a15c4/src/libcollections/linked_list.rs#L835-L856 One of `self.list`s has type ``` &ReFree(CodeExtent(15013/CallSiteScope { fn_id: 18907, body_id: 18912 }), BrNamed(0:DefIndex(3066), 'a(397), WontChange)) mut linked_list::LinkedList<T> ``` and other has type ``` &ReScope(CodeExtent(15018/Remainder(BlockRemainder { block: 18912, first_statement_index: 0 }))) mut linked_list::LinkedList<T> ``` (... but I'm not sure it's not a bug actually.) 2) Not hashing types is faster than hashing types. r? @arielb1
2 parents 7a2a381 + 14b4d72 commit 933d481

File tree

1 file changed

+9
-5
lines changed
  • src/librustc_borrowck/borrowck

1 file changed

+9
-5
lines changed

src/librustc_borrowck/borrowck/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc::ty::{self, TyCtxt};
4141
use std::fmt;
4242
use std::mem;
4343
use std::rc::Rc;
44+
use std::hash::{Hash, Hasher};
4445
use syntax::ast;
4546
use syntax::attr::AttrMetaMethods;
4647
use syntax_pos::{MultiSpan, Span};
@@ -345,18 +346,21 @@ impl<'tcx> Loan<'tcx> {
345346
}
346347
}
347348

348-
#[derive(Eq, Hash)]
349+
#[derive(Eq)]
349350
pub struct LoanPath<'tcx> {
350351
kind: LoanPathKind<'tcx>,
351352
ty: ty::Ty<'tcx>,
352353
}
353354

354355
impl<'tcx> PartialEq for LoanPath<'tcx> {
355356
fn eq(&self, that: &LoanPath<'tcx>) -> bool {
356-
let r = self.kind == that.kind;
357-
debug_assert!(self.ty == that.ty || !r,
358-
"Somehow loan paths are equal though their tys are not.");
359-
r
357+
self.kind == that.kind
358+
}
359+
}
360+
361+
impl<'tcx> Hash for LoanPath<'tcx> {
362+
fn hash<H: Hasher>(&self, state: &mut H) {
363+
self.kind.hash(state);
360364
}
361365
}
362366

0 commit comments

Comments
 (0)