]> git.lizzy.rs Git - rust.git/blob - src/librustc/ich/def_path_hash.rs
change the format of the linked issue number
[rust.git] / src / librustc / ich / def_path_hash.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use hir::def_id::DefId;
12 use ty::TyCtxt;
13 use util::nodemap::DefIdMap;
14
15 pub struct DefPathHashes<'a, 'tcx: 'a> {
16     tcx: TyCtxt<'a, 'tcx, 'tcx>,
17     data: DefIdMap<u64>,
18 }
19
20 impl<'a, 'tcx> DefPathHashes<'a, 'tcx> {
21     pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
22         DefPathHashes {
23             tcx: tcx,
24             data: DefIdMap()
25         }
26     }
27
28     pub fn hash(&mut self, def_id: DefId) -> u64 {
29         let tcx = self.tcx;
30         *self.data.entry(def_id)
31                   .or_insert_with(|| {
32                       let def_path = tcx.def_path(def_id);
33                       def_path.deterministic_hash(tcx)
34                   })
35     }
36 }