Skip to content

Commit 936b6bf

Browse files
committed
Move trait_map into hir::Crate
1 parent 033013c commit 936b6bf

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

src/librustc_ast_lowering/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ pub trait Resolver {
205205
fn lint_buffer(&mut self) -> &mut LintBuffer;
206206

207207
fn next_node_id(&mut self) -> NodeId;
208+
209+
fn trait_map(&self) -> &NodeMap<Vec<hir::TraitCandidate>>;
208210
}
209211

210212
type NtToTokenstream = fn(&Nonterminal, &ParseSess, Span) -> TokenStream;
@@ -557,6 +559,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
557559
let proc_macros =
558560
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
559561

562+
let trait_map = self
563+
.resolver
564+
.trait_map()
565+
.iter()
566+
.map(|(&k, v)| (self.node_id_to_hir_id[k].unwrap(), v.clone()))
567+
.collect();
568+
560569
self.resolver.definitions().init_node_id_to_hir_id_mapping(self.node_id_to_hir_id);
561570

562571
hir::Crate {
@@ -571,6 +580,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
571580
trait_impls: self.trait_impls,
572581
modules: self.modules,
573582
proc_macros,
583+
trait_map,
574584
}
575585
}
576586

src/librustc_hir/hir.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ pub struct Crate<'hir> {
639639
/// A list of proc macro HirIds, written out in the order in which
640640
/// they are declared in the static array generated by proc_macro_harness.
641641
pub proc_macros: Vec<HirId>,
642+
643+
pub trait_map: BTreeMap<HirId, Vec<TraitCandidate>>,
642644
}
643645

644646
impl Crate<'hir> {
@@ -2651,7 +2653,7 @@ pub type CaptureModeMap = NodeMap<CaptureBy>;
26512653
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
26522654
// has length > 0 if the trait is found through an chain of imports, starting with the
26532655
// import/use statement in the scope where the trait is used.
2654-
#[derive(Clone, Debug)]
2656+
#[derive(RustcEncodable, RustcDecodable, Clone, Debug)]
26552657
pub struct TraitCandidate {
26562658
pub def_id: DefId,
26572659
pub import_ids: SmallVec<[LocalDefId; 1]>,

src/librustc_middle/hir/map/collector.rs

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
117117
body_ids: _,
118118
modules: _,
119119
proc_macros: _,
120+
trait_map: _,
120121
} = *krate;
121122

122123
hash_body(&mut hcx, root_mod_def_path_hash, item, &mut hir_body_nodes)

src/librustc_middle/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,9 @@ impl<'tcx> TyCtxt<'tcx> {
11011101
};
11021102

11031103
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
1104-
for (hir_id, v) in resolutions.trait_map.into_iter() {
1104+
for (hir_id, v) in krate.trait_map.iter() {
11051105
let map = trait_map.entry(hir_id.owner).or_default();
1106-
map.insert(hir_id.local_id, StableVec::new(v));
1106+
map.insert(hir_id.local_id, StableVec::new(v.to_vec()));
11071107
}
11081108

11091109
GlobalCtxt {

src/librustc_middle/ty/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ pub struct ResolverOutputs {
121121
pub definitions: rustc_hir::definitions::Definitions,
122122
pub cstore: Box<CrateStoreDyn>,
123123
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
124-
pub trait_map: FxHashMap<hir::HirId, Vec<hir::TraitCandidate>>,
125124
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
126125
pub maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
127126
pub export_map: ExportMap<LocalDefId>,

src/librustc_resolve/lib.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,10 @@ impl rustc_ast_lowering::Resolver for Resolver<'_> {
11091109
fn next_node_id(&mut self) -> NodeId {
11101110
self.next_node_id()
11111111
}
1112+
1113+
fn trait_map(&self) -> &NodeMap<Vec<TraitCandidate>> {
1114+
&self.trait_map
1115+
}
11121116
}
11131117

11141118
impl<'a> Resolver<'a> {
@@ -1284,11 +1288,6 @@ impl<'a> Resolver<'a> {
12841288
let definitions = self.definitions;
12851289
let extern_crate_map = self.extern_crate_map;
12861290
let export_map = self.export_map;
1287-
let trait_map = self
1288-
.trait_map
1289-
.into_iter()
1290-
.map(|(k, v)| (definitions.node_id_to_hir_id(k), v))
1291-
.collect();
12921291
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
12931292
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
12941293
let glob_map = self.glob_map;
@@ -1297,7 +1296,6 @@ impl<'a> Resolver<'a> {
12971296
cstore: Box::new(self.crate_loader.into_cstore()),
12981297
extern_crate_map,
12991298
export_map,
1300-
trait_map,
13011299
glob_map,
13021300
maybe_unused_trait_imports,
13031301
maybe_unused_extern_crates,
@@ -1315,11 +1313,6 @@ impl<'a> Resolver<'a> {
13151313
cstore: Box::new(self.cstore().clone()),
13161314
extern_crate_map: self.extern_crate_map.clone(),
13171315
export_map: self.export_map.clone(),
1318-
trait_map: self
1319-
.trait_map
1320-
.iter()
1321-
.map(|(&k, v)| (self.definitions.node_id_to_hir_id(k), v.clone()))
1322-
.collect(),
13231316
glob_map: self.glob_map.clone(),
13241317
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
13251318
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),

0 commit comments

Comments
 (0)