Skip to content

Commit dbe1354

Browse files
committed
Move ast_map::map to LinearMap
1 parent b53057f commit dbe1354

25 files changed

+111
-113
lines changed

src/librustc/metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: writer::Encoder,
10261026
let ebml_w = copy ebml_w;
10271027
|i, cx, v| {
10281028
visit::visit_item(i, cx, v);
1029-
match ecx.tcx.items.get(&i.id) {
1029+
match *ecx.tcx.items.get(&i.id) {
10301030
ast_map::node_item(_, pt) => {
10311031
encode_info_for_item(ecx, ebml_w, i,
10321032
index, *pt);
@@ -1039,7 +1039,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: writer::Encoder,
10391039
let ebml_w = copy ebml_w;
10401040
|ni, cx, v| {
10411041
visit::visit_foreign_item(ni, cx, v);
1042-
match ecx.tcx.items.get(&ni.id) {
1042+
match *ecx.tcx.items.get(&ni.id) {
10431043
ast_map::node_foreign_item(_, abi, _, pt) => {
10441044
encode_info_for_foreign_item(ecx, ebml_w, ni,
10451045
index, /*bad*/copy *pt,

src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub fn check_item_recursion(sess: Session,
240240
match env.def_map.find(&e.id) {
241241
Some(&def_const(def_id)) => {
242242
if ast_util::is_local(def_id) {
243-
match env.ast_map.get(&def_id.node) {
243+
match *env.ast_map.get(&def_id.node) {
244244
ast_map::node_item(it, _) => {
245245
(v.visit_item)(it, env, v);
246246
}

src/librustc/middle/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
182182
if ast_util::is_local(def_id) {
183183
match tcx.items.find(&def_id.node) {
184184
None => None,
185-
Some(ast_map::node_item(it, _)) => match it.node {
185+
Some(&ast_map::node_item(it, _)) => match it.node {
186186
item_const(_, const_expr) => Some(const_expr),
187187
_ => None
188188
},

src/librustc/middle/privacy.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ pub fn check_crate(tcx: ty::ctxt,
113113
@fn(span: span, method_id: node_id) -> def_id =
114114
|span, method_id| {
115115
match tcx.items.find(&method_id) {
116-
Some(node_method(_, impl_id, _)) => impl_id,
117-
Some(node_trait_method(_, trait_id, _)) => trait_id,
116+
Some(&node_method(_, impl_id, _)) => impl_id,
117+
Some(&node_trait_method(_, trait_id, _)) => trait_id,
118118
Some(_) => {
119119
tcx.sess.span_bug(span,
120120
fmt!("method was a %s?!",
@@ -148,7 +148,7 @@ pub fn check_crate(tcx: ty::ctxt,
148148
}
149149
150150
match tcx.items.find(&container_id.node) {
151-
Some(node_item(item, _)) => {
151+
Some(&node_item(item, _)) => {
152152
match item.node {
153153
item_impl(_, None, _, _)
154154
if item.vis != public => {
@@ -170,10 +170,10 @@ pub fn check_crate(tcx: ty::ctxt,
170170
};
171171

172172
match tcx.items.find(&method_id) {
173-
Some(node_method(method, impl_id, _)) => {
173+
Some(&node_method(method, impl_id, _)) => {
174174
check(method.vis, impl_id)
175175
}
176-
Some(node_trait_method(trait_method, trait_id, _)) => {
176+
Some(&node_trait_method(trait_method, trait_id, _)) => {
177177
match *trait_method {
178178
required(_) => check(public, trait_id),
179179
provided(method) => check(method.vis, trait_id),
@@ -200,16 +200,16 @@ pub fn check_crate(tcx: ty::ctxt,
200200
let mut f: &fn(node_id) -> bool = |_| false;
201201
f = |item_id| {
202202
match tcx.items.find(&item_id) {
203-
Some(node_item(item, _)) => item.vis != public,
204-
Some(node_foreign_item(_, _, vis, _)) => vis != public,
205-
Some(node_method(method, impl_did, _)) => {
203+
Some(&node_item(item, _)) => item.vis != public,
204+
Some(&node_foreign_item(_, _, vis, _)) => vis != public,
205+
Some(&node_method(method, impl_did, _)) => {
206206
match method.vis {
207207
private => true,
208208
public => false,
209209
inherited => f(impl_did.node)
210210
}
211211
}
212-
Some(node_trait_method(_, trait_did, _)) => f(trait_did.node),
212+
Some(&node_trait_method(_, trait_did, _)) => f(trait_did.node),
213213
Some(_) => {
214214
tcx.sess.span_bug(span,
215215
fmt!("local_item_is_private: item was \
@@ -332,7 +332,7 @@ pub fn check_crate(tcx: ty::ctxt,
332332
method_super(trait_id, method_num) => {
333333
if trait_id.crate == local_crate {
334334
match tcx.items.find(&trait_id.node) {
335-
Some(node_item(item, _)) => {
335+
Some(&node_item(item, _)) => {
336336
match item.node {
337337
item_trait(_, _, ref methods) => {
338338
if method_num >= (*methods).len() {

src/librustc/middle/trans/base.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
20652065
20662066
pub fn trans_item(ccx: @CrateContext, item: ast::item) {
20672067
let _icx = ccx.insn_ctxt("trans_item");
2068-
let path = match ccx.tcx.items.get(&item.id) {
2068+
let path = match *ccx.tcx.items.get(&item.id) {
20692069
ast_map::node_item(_, p) => p,
20702070
// tjc: ?
20712071
_ => fail!(~"trans_item"),
@@ -2336,13 +2336,12 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef,
23362336
}
23372337
23382338
pub fn item_path(ccx: @CrateContext, i: @ast::item) -> path {
2339-
vec::append(
2340-
/*bad*/copy *match ccx.tcx.items.get(&i.id) {
2341-
ast_map::node_item(_, p) => p,
2342-
// separate map for paths?
2343-
_ => fail!(~"item_path")
2344-
},
2345-
~[path_name(i.ident)])
2339+
let base = match *ccx.tcx.items.get(&i.id) {
2340+
ast_map::node_item(_, p) => p,
2341+
// separate map for paths?
2342+
_ => fail!(~"item_path")
2343+
};
2344+
vec::append(/*bad*/copy *base, ~[path_name(i.ident)])
23462345
}
23472346
23482347
/* If there's already a symbol for the dtor with <id> and substs <substs>,
@@ -2393,7 +2392,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
23932392
None => {
23942393
23952394
let mut exprt = false;
2396-
let val = match ccx.tcx.items.get(&id) {
2395+
let val = match *ccx.tcx.items.get(&id) {
23972396
ast_map::node_item(i, pth) => {
23982397
let my_path = vec::append(/*bad*/copy *pth,
23992398
~[path_name(i.ident)]);

src/librustc/middle/trans/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn trans_fn_ref_with_vtables(
268268
ccx.tcx.items.find(&def_id.node),
269269
|| fmt!("local item should be in ast map"));
270270

271-
match map_node {
271+
match *map_node {
272272
ast_map::node_foreign_item(_,
273273
ast::foreign_abi_rust_intrinsic,
274274
_,

src/librustc/middle/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
158158
if !ast_util::is_local(def_id) {
159159
def_id = inline::maybe_instantiate_inline(cx, def_id, true);
160160
}
161-
match cx.tcx.items.get(&def_id.node) {
161+
match *cx.tcx.items.get(&def_id.node) {
162162
ast_map::node_item(@ast::item {
163163
node: ast::item_const(_, subexpr), _
164164
}, _) => {

src/librustc/middle/trans/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> {
849849
let sp = fcx.span.get();
850850
debug!("%s", cx.sess.codemap.span_to_str(sp));
851851

852-
let (ident, ret_ty, id) = match cx.tcx.items.get(&fcx.id) {
852+
let (ident, ret_ty, id) = match *cx.tcx.items.get(&fcx.id) {
853853
ast_map::node_item(item, _) => {
854854
match item.node {
855855
ast::item_fn(ref decl, _, _, _) => {

src/librustc/middle/trans/foreign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
567567
let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty),
568568
out_sz = machine::llbitsize_of_real(ccx, llout_ty);
569569
if tp_sz != out_sz {
570-
let sp = match ccx.tcx.items.get(&ref_id.get()) {
570+
let sp = match *ccx.tcx.items.get(&ref_id.get()) {
571571
ast_map::node_expr(e) => e.span,
572572
_ => fail!(~"reinterpret_cast or forget has non-expr arg")
573573
};
@@ -1082,7 +1082,7 @@ pub fn register_foreign_fn(ccx: @CrateContext,
10821082
fn abi_of_foreign_fn(ccx: @CrateContext, i: @ast::foreign_item)
10831083
-> ast::foreign_abi {
10841084
match attr::first_attr_value_str_by_name(i.attrs, ~"abi") {
1085-
None => match ccx.tcx.items.get(&i.id) {
1085+
None => match *ccx.tcx.items.get(&i.id) {
10861086
ast_map::node_foreign_item(_, abi, _, _) => abi,
10871087
// ??
10881088
_ => fail!(~"abi_of_foreign_fn: not foreign")

src/librustc/middle/trans/meth.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn trans_static_method_callee(bcx: block,
306306
};
307307
308308
let mname = if method_id.crate == ast::local_crate {
309-
match bcx.tcx().items.get(&method_id.node) {
309+
match *bcx.tcx().items.get(&method_id.node) {
310310
ast_map::node_trait_method(trait_method, _, _) => {
311311
ast_util::trait_method_to_ty_method(trait_method).ident
312312
}
@@ -361,7 +361,7 @@ pub fn method_from_methods(ms: &[@ast::method], name: ast::ident)
361361
pub fn method_with_name(ccx: @CrateContext, impl_id: ast::def_id,
362362
name: ast::ident) -> ast::def_id {
363363
if impl_id.crate == ast::local_crate {
364-
match ccx.tcx.items.get(&impl_id.node) {
364+
match *ccx.tcx.items.get(&impl_id.node) {
365365
ast_map::node_item(@ast::item {
366366
node: ast::item_impl(_, _, _, ref ms),
367367
_
@@ -378,7 +378,7 @@ pub fn method_with_name(ccx: @CrateContext, impl_id: ast::def_id,
378378
pub fn method_with_name_or_default(ccx: @CrateContext, impl_id: ast::def_id,
379379
name: ast::ident) -> ast::def_id {
380380
if impl_id.crate == ast::local_crate {
381-
match ccx.tcx.items.get(&impl_id.node) {
381+
match *ccx.tcx.items.get(&impl_id.node) {
382382
ast_map::node_item(@ast::item {
383383
node: ast::item_impl(_, _, _, ref ms), _
384384
}, _) => {
@@ -414,7 +414,7 @@ pub fn method_ty_param_count(ccx: @CrateContext, m_id: ast::def_id,
414414
debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id);
415415
if m_id.crate == ast::local_crate {
416416
match ccx.tcx.items.find(&m_id.node) {
417-
Some(ast_map::node_method(m, _, _)) => m.generics.ty_params.len(),
417+
Some(&ast_map::node_method(m, _, _)) => m.generics.ty_params.len(),
418418
None => {
419419
match ccx.tcx.provided_method_sources.find(&m_id) {
420420
Some(source) => {
@@ -424,7 +424,7 @@ pub fn method_ty_param_count(ccx: @CrateContext, m_id: ast::def_id,
424424
None => fail!()
425425
}
426426
}
427-
Some(ast_map::node_trait_method(@ast::provided(@ref m),
427+
Some(&ast_map::node_trait_method(@ast::provided(@ref m),
428428
_, _)) => {
429429
m.generics.ty_params.len()
430430
}

src/librustc/middle/trans/monomorphize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
9393
(may have attempted to monomorphize an item defined in a different \
9494
crate?)", fn_id));
9595
// Get the path so that we can create a symbol
96-
let (pt, name, span) = match map_node {
96+
let (pt, name, span) = match *map_node {
9797
ast_map::node_item(i, pt) => (pt, i.ident, i.span),
9898
ast_map::node_variant(ref v, enm, pt) => (pt, (*v).node.name, enm.span),
9999
ast_map::node_method(m, _, pt) => (pt, m.ident, m.span),
@@ -172,7 +172,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
172172
self_ty: impl_ty_opt
173173
});
174174

175-
let lldecl = match map_node {
175+
let lldecl = match *map_node {
176176
ast_map::node_item(i@@ast::item {
177177
// XXX: Bad copy.
178178
node: ast::item_fn(ref decl, _, _, ref body),

src/librustc/middle/trans/reachable.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,17 @@ fn traverse_exports(cx: ctx, mod_id: node_id) -> bool {
7171

7272
fn traverse_def_id(cx: ctx, did: def_id) {
7373
if did.crate != local_crate { return; }
74-
let n = match cx.tcx.items.find(&did.node) {
75-
None => return, // This can happen for self, for example
76-
Some(ref n) => (/*bad*/copy *n)
77-
};
78-
match n {
79-
ast_map::node_item(item, _) => traverse_public_item(cx, item),
80-
ast_map::node_method(_, impl_id, _) => traverse_def_id(cx, impl_id),
81-
ast_map::node_foreign_item(item, _, _, _) => {
82-
cx.rmap.insert(item.id);
83-
}
84-
ast_map::node_variant(ref v, _, _) => {
85-
cx.rmap.insert(v.node.id);
86-
}
87-
_ => ()
74+
match cx.tcx.items.find(&did.node) {
75+
None => (), // This can happen for self, for example
76+
Some(&ast_map::node_item(item, _)) => traverse_public_item(cx, item),
77+
Some(&ast_map::node_method(_, impl_id, _)) => traverse_def_id(cx, impl_id),
78+
Some(&ast_map::node_foreign_item(item, _, _, _)) => {
79+
cx.rmap.insert(item.id);
80+
}
81+
Some(&ast_map::node_variant(ref v, _, _)) => {
82+
cx.rmap.insert(v.node.id);
83+
}
84+
_ => ()
8885
}
8986
}
9087

src/librustc/middle/trans/type_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
9898
return uses;
9999
}
100100
let map_node = match ccx.tcx.items.find(&fn_id_loc.node) {
101-
Some(ref x) => (/*bad*/copy *x),
101+
Some(x) => (/*bad*/copy *x),
102102
None => ccx.sess.bug(fmt!("type_uses_for: unbound item ID %?",
103103
fn_id_loc))
104104
};

src/librustc/middle/ty.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ pub fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) {
35383538
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] {
35393539
if is_local(id) {
35403540
match cx.items.find(&id.node) {
3541-
Some(ast_map::node_item(@ast::item {
3541+
Some(&ast_map::node_item(@ast::item {
35423542
node: item_trait(_, _, ref ms),
35433543
_
35443544
}, _)) =>
@@ -3627,7 +3627,7 @@ pub fn impl_traits(cx: ctxt, id: ast::def_id, store: TraitStore) -> ~[t] {
36273627
if id.crate == ast::local_crate {
36283628
debug!("(impl_traits) searching for trait impl %?", id);
36293629
match cx.items.find(&id.node) {
3630-
Some(ast_map::node_item(@ast::item {
3630+
Some(&ast_map::node_item(@ast::item {
36313631
node: ast::item_impl(_, opt_trait, _, _),
36323632
_},
36333633
_)) => {
@@ -3663,7 +3663,7 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option<ast::def_id> {
36633663
}
36643664

36653665
match cx.items.find(&struct_did.node) {
3666-
Some(ast_map::node_item(item, _)) => {
3666+
Some(&ast_map::node_item(item, _)) => {
36673667
match item.node {
36683668
ast::item_struct(struct_def, _) => {
36693669
struct_def.ctor_id.map(|ctor_id|
@@ -3735,7 +3735,7 @@ pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind {
37353735

37363736
if is_local(struct_id) {
37373737
match cx.items.find(&struct_id.node) {
3738-
Some(ast_map::node_item(@ast::item {
3738+
Some(&ast_map::node_item(@ast::item {
37393739
node: ast::item_struct(@ast::struct_def { dtor: Some(ref dtor),
37403740
_ },
37413741
_),
@@ -3762,8 +3762,12 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
37623762
if id.crate != ast::local_crate {
37633763
csearch::get_item_path(cx, id)
37643764
} else {
3765-
let node = cx.items.get(&id.node);
3766-
match node {
3765+
// FIXME (#5521): uncomment this code and don't have a catch-all at the
3766+
// end of the match statement. Favor explicitly listing
3767+
// each variant.
3768+
// let node = cx.items.get(&id.node);
3769+
// match *node {
3770+
match *cx.items.get(&id.node) {
37673771
ast_map::node_item(item, path) => {
37683772
let item_elt = match item.node {
37693773
item_mod(_) | item_foreign_mod(_) => {
@@ -3805,9 +3809,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
38053809
vec::append_one(/*bad*/copy *path, ast_map::path_name(item.ident))
38063810
}
38073811

3808-
ast_map::node_stmt(*) | ast_map::node_expr(*) |
3809-
ast_map::node_arg(*) | ast_map::node_local(*) |
3810-
ast_map::node_block(*) => {
3812+
ref node => {
38113813
cx.sess.bug(fmt!("cannot find item_path for node %?", node));
38123814
}
38133815
}
@@ -3839,7 +3841,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
38393841
call eval_const_expr, it should never get called twice for the same
38403842
expr, since check_enum_variants also updates the enum_var_cache
38413843
*/
3842-
match cx.items.get(&id.node) {
3844+
match *cx.items.get(&id.node) {
38433845
ast_map::node_item(@ast::item {
38443846
node: ast::item_enum(ref enum_definition, _),
38453847
_
@@ -3955,15 +3957,15 @@ pub fn lookup_field_type(tcx: ctxt,
39553957
pub fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
39563958
if did.crate == ast::local_crate {
39573959
match cx.items.find(&did.node) {
3958-
Some(ast_map::node_item(i,_)) => {
3960+
Some(&ast_map::node_item(i,_)) => {
39593961
match i.node {
39603962
ast::item_struct(struct_def, _) => {
39613963
struct_field_tys(struct_def.fields)
39623964
}
39633965
_ => cx.sess.bug(~"struct ID bound to non-struct")
39643966
}
39653967
}
3966-
Some(ast_map::node_variant(ref variant, _, _)) => {
3968+
Some(&ast_map::node_variant(ref variant, _, _)) => {
39673969
match (*variant).node.kind {
39683970
ast::struct_variant_kind(struct_def) => {
39693971
struct_field_tys(struct_def.fields)

src/librustc/middle/typeck/check/method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ pub impl<'self> LookupContext<'self> {
12571257
fn report_static_candidate(&self, idx: uint, did: def_id) {
12581258
let span = if did.crate == ast::local_crate {
12591259
match self.tcx().items.find(&did.node) {
1260-
Some(ast_map::node_method(m, _, _)) => m.span,
1260+
Some(&ast_map::node_method(m, _, _)) => m.span,
12611261
_ => fail!(fmt!("report_static_candidate: bad item %?", did))
12621262
}
12631263
} else {

0 commit comments

Comments
 (0)