Skip to content

Commit e387e6c

Browse files
committed
typeck: merge CollectCtxt and collect::CollectCtxt.
1 parent 8600a67 commit e387e6c

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ use rustc::dep_graph::DepNode;
7979
use rustc::hir::map as hir_map;
8080
use util::common::{ErrorReported, MemoizationMap};
8181
use util::nodemap::FnvHashMap;
82-
use write_ty_to_tcx;
82+
use {CrateCtxt, write_ty_to_tcx};
8383

8484
use rustc_const_math::ConstInt;
8585

86-
use std::cell::RefCell;
8786
use std::collections::HashSet;
8887
use std::collections::hash_map::Entry::{Occupied, Vacant};
8988
use std::rc::Rc;
@@ -101,22 +100,13 @@ use rustc::hir::print as pprust;
101100
///////////////////////////////////////////////////////////////////////////
102101
// Main entry point
103102

104-
pub fn collect_item_types(tcx: &TyCtxt) {
105-
let ccx = &CrateCtxt { tcx: tcx, stack: RefCell::new(Vec::new()) };
106-
let mut visitor = CollectItemTypesVisitor{ ccx: ccx };
103+
pub fn collect_item_types(ccx: &CrateCtxt) {
104+
let mut visitor = CollectItemTypesVisitor { ccx: ccx };
107105
ccx.tcx.visit_all_items_in_krate(DepNode::CollectItem, &mut visitor);
108106
}
109107

110108
///////////////////////////////////////////////////////////////////////////
111109

112-
struct CrateCtxt<'a,'tcx:'a> {
113-
tcx: &'a TyCtxt<'tcx>,
114-
115-
// This stack is used to identify cycles in the user's source.
116-
// Note that these cycles can cross multiple items.
117-
stack: RefCell<Vec<AstConvRequest>>,
118-
}
119-
120110
/// Context specific to some particular item. This is what implements
121111
/// AstConv. It has information about the predicates that are defined
122112
/// on the trait. Unfortunately, this predicate information is
@@ -134,7 +124,7 @@ struct ItemCtxt<'a,'tcx:'a> {
134124
}
135125

136126
#[derive(Copy, Clone, PartialEq, Eq)]
137-
enum AstConvRequest {
127+
pub enum AstConvRequest {
138128
GetItemTypeScheme(DefId),
139129
GetTraitDef(DefId),
140130
EnsureSuperPredicates(DefId),

src/librustc_typeck/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,17 @@ pub struct TypeAndSubsts<'tcx> {
138138
pub struct CrateCtxt<'a, 'tcx: 'a> {
139139
// A mapping from method call sites to traits that have that method.
140140
pub trait_map: hir::TraitMap,
141+
141142
/// A vector of every trait accessible in the whole crate
142143
/// (i.e. including those from subcrates). This is used only for
143144
/// error reporting, and so is lazily initialised and generally
144145
/// shouldn't taint the common path (hence the RefCell).
145146
pub all_traits: RefCell<Option<check::method::AllTraitsVec>>,
147+
148+
/// This stack is used to identify cycles in the user's source.
149+
/// Note that these cycles can cross multiple items.
150+
pub stack: RefCell<Vec<collect::AstConvRequest>>,
151+
146152
pub tcx: &'a TyCtxt<'tcx>,
147153
}
148154

@@ -337,14 +343,15 @@ pub fn check_crate(tcx: &TyCtxt, trait_map: hir::TraitMap) -> CompileResult {
337343
let ccx = CrateCtxt {
338344
trait_map: trait_map,
339345
all_traits: RefCell::new(None),
346+
stack: RefCell::new(Vec::new()),
340347
tcx: tcx
341348
};
342349

343350
// this ensures that later parts of type checking can assume that items
344351
// have valid types and not error
345352
tcx.sess.track_errors(|| {
346353
time(time_passes, "type collecting", ||
347-
collect::collect_item_types(tcx));
354+
collect::collect_item_types(&ccx));
348355

349356
})?;
350357

0 commit comments

Comments
 (0)