Skip to content

Commit 26faa37

Browse files
committed
syntax: Add a lot of copy keywords
1 parent 847c5e4 commit 26faa37

File tree

6 files changed

+87
-59
lines changed

6 files changed

+87
-59
lines changed

src/libsyntax/ast_map.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn map_decoded_item(diag: span_handler,
123123
fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
124124
sp: codemap::span, id: node_id, cx: ctx, v: vt) {
125125
for decl.inputs.each {|a|
126-
cx.map.insert(a.id, node_arg(a, cx.local_id));
126+
cx.map.insert(a.id, node_arg(/* FIXME: bad */ copy a, cx.local_id));
127127
cx.local_id += 1u;
128128
}
129129
alt fk {
@@ -133,13 +133,17 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
133133
dec: /* FIXME: bad */ copy decl,
134134
body: /* FIXME: bad */ copy body},
135135
span: sp};
136-
cx.map.insert(id, node_ctor(/* FIXME: bad */ copy nm, tps,
137-
class_ctor(ct, parent_id), @cx.path));
136+
cx.map.insert(id, node_ctor(/* FIXME: bad */ copy nm,
137+
/* FIXME: bad */ copy tps,
138+
class_ctor(ct, parent_id),
139+
@/* FIXME: bad */ copy cx.path));
138140
}
139141
visit::fk_dtor(tps, self_id, parent_id) {
140-
let dt = @{node: {id: id, self_id: self_id, body: body},
141-
span: sp};
142-
cx.map.insert(id, node_dtor(tps, dt, parent_id, @cx.path));
142+
let dt = @{node: {id: id, self_id: self_id,
143+
body: /* FIXME: bad */ copy body}, span: sp};
144+
cx.map.insert(id, node_dtor(/* FIXME: bad */ copy tps, dt,
145+
parent_id,
146+
@/* FIXME: bad */ copy cx.path));
143147
}
144148

145149
_ {}
@@ -148,7 +152,7 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
148152
}
149153

150154
fn map_block(b: blk, cx: ctx, v: vt) {
151-
cx.map.insert(b.node.id, node_block(b));
155+
cx.map.insert(b.node.id, node_block(/* FIXME: bad */ copy b));
152156
visit::visit_block(b, cx, v);
153157
}
154158

@@ -182,25 +186,29 @@ fn map_method(impl_did: def_id, impl_path: @path,
182186
}
183187

184188
fn map_item(i: @item, cx: ctx, v: vt) {
185-
let item_path = @cx.path;
189+
let item_path = @/* FIXME: bad */ copy cx.path;
186190
cx.map.insert(i.id, node_item(i, item_path));
187191
alt i.node {
188192
item_impl(_, _, _, _, ms) {
189193
let impl_did = ast_util::local_def(i.id);
190194
for ms.each {|m|
191-
map_method(impl_did, extend(cx, i.ident), m, cx);
195+
map_method(impl_did, extend(cx, /* FIXME: bad */ copy i.ident), m,
196+
cx);
192197
}
193198
}
194199
item_res(decl, tps, _, dtor_id, ctor_id, _) {
195-
cx.map.insert(ctor_id, node_ctor(i.ident, tps,
196-
res_ctor(decl, ctor_id, i.span),
200+
cx.map.insert(ctor_id, node_ctor(/* FIXME: bad */ copy i.ident,
201+
/* FIXME: bad */ copy tps,
202+
res_ctor(/* FIXME: bad */ copy decl,
203+
ctor_id, i.span),
197204
item_path));
198205
cx.map.insert(dtor_id, node_item(i, item_path));
199206
}
200207
item_enum(vs, _, _) {
201208
for vs.each {|v|
202209
cx.map.insert(v.node.id, node_variant(
203-
v, i, extend(cx, i.ident)));
210+
/* FIXME: bad */ copy v, i,
211+
extend(cx, /* FIXME: bad */ copy i.ident)));
204212
}
205213
}
206214
item_native_mod(nm) {
@@ -209,7 +217,9 @@ fn map_item(i: @item, cx: ctx, v: vt) {
209217
either::right(abi) { abi }
210218
};
211219
for nm.items.each {|nitem|
212-
cx.map.insert(nitem.id, node_native_item(nitem, abi, @cx.path));
220+
cx.map.insert(nitem.id,
221+
node_native_item(nitem, abi,
222+
@/* FIXME: bad */ copy cx.path));
213223
}
214224
}
215225
item_class(tps, ifces, items, ctor, dtor, _) {
@@ -219,17 +229,17 @@ fn map_item(i: @item, cx: ctx, v: vt) {
219229
vec::iter(ifces) {|p| cx.map.insert(p.id,
220230
node_item(i, item_path)); };
221231
let d_id = ast_util::local_def(i.id);
222-
let p = extend(cx, i.ident);
232+
let p = extend(cx, /* FIXME: bad */ copy i.ident);
223233
// only need to handle methods
224234
vec::iter(ms) {|m| map_method(d_id, p, m, cx); }
225235
}
226236
_ { }
227237
}
228238
alt i.node {
229239
item_mod(_) | item_native_mod(_) {
230-
cx.path += [path_mod(i.ident)];
240+
cx.path += [path_mod(/* FIXME: bad */ copy i.ident)];
231241
}
232-
_ { cx.path += [path_name(i.ident)]; }
242+
_ { cx.path += [path_name(/* FIXME: bad */ copy i.ident)]; }
233243
}
234244
visit::visit_item(i, cx, v);
235245
vec::pop(cx.path);
@@ -240,7 +250,7 @@ fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
240250
view_item_export(vps) {
241251
for vps.each {|vp|
242252
let (id, name) = alt vp.node {
243-
view_path_simple(nm, _, id) { (id, nm) }
253+
view_path_simple(nm, _, id) { (id, /* FIXME: bad */ copy nm) }
244254
view_path_glob(pth, id) | view_path_list(pth, _, id) {
245255
(id, path_to_ident(pth))
246256
}

src/libsyntax/attr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ fn mk_name_value_item_str(+name: ast::ident, +value: str) -> @ast::meta_item {
5151
ret mk_name_value_item(name, value_lit);
5252
}
5353

54-
fn mk_name_value_item(+name: ast::ident, +value: ast::lit) -> @ast::meta_item {
54+
fn mk_name_value_item(+name: ast::ident, +value: ast::lit)
55+
-> @ast::meta_item {
5556
ret @dummy_spanned(ast::meta_name_value(name, value));
5657
}
5758

src/libsyntax/fold.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
8888
meta_word(id) { meta_word(fld.fold_ident(id)) }
8989
meta_list(id, mis) {
9090
let fold_meta_item = bind fold_meta_item_(_, fld);
91-
meta_list(id, vec::map(mis, fold_meta_item))
91+
meta_list(/* FIXME: bad */ copy id,
92+
vec::map(mis, fold_meta_item))
9293
}
9394
meta_name_value(id, s) {
94-
meta_name_value(fld.fold_ident(id), s)
95+
meta_name_value(fld.fold_ident(id), /* FIXME: bad */ copy s)
9596
}
9697
},
9798
span: fld.new_span(mi.span)};
@@ -121,8 +122,8 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
121122
mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) }
122123
mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) }
123124
mac_ellipsis { mac_ellipsis }
124-
mac_aq(_,_) { /* fixme */ m.node }
125-
mac_var(_) { /* fixme */ m.node }
125+
mac_aq(_,_) { /* FIXME: bad */ copy m.node }
126+
mac_var(_) { /* FIXME: bad */ copy m.node }
126127
},
127128
span: fld.new_span(m.span)};
128129
}
@@ -143,7 +144,7 @@ fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
143144
}
144145

145146
fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param {
146-
{ident: tp.ident,
147+
{ident: /* FIXME: bad */ copy tp.ident,
147148
id: fld.new_id(tp.id),
148149
bounds: @vec::map(*tp.bounds, fold_ty_param_bound(_, fld))}
149150
}
@@ -166,19 +167,20 @@ fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
166167
crate_directive_ {
167168
ret alt cd {
168169
cdir_src_mod(id, attrs) {
169-
cdir_src_mod(fld.fold_ident(id), attrs)
170+
cdir_src_mod(fld.fold_ident(id), /* FIXME: bad */ copy attrs)
170171
}
171172
cdir_dir_mod(id, cds, attrs) {
172173
cdir_dir_mod(fld.fold_ident(id),
173-
vec::map(cds, fld.fold_crate_directive), attrs)
174+
vec::map(cds, fld.fold_crate_directive),
175+
/* FIXME: bad */ copy attrs)
174176
}
175177
cdir_view_item(vi) { cdir_view_item(fld.fold_view_item(vi)) }
176-
cdir_syntax(_) { cd }
178+
cdir_syntax(_) { copy cd }
177179
}
178180
}
179181

180182
fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ {
181-
ret vi;
183+
ret /* FIXME: bad */ copy vi;
182184
}
183185

184186

@@ -220,7 +222,8 @@ fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
220222
-> @class_member {
221223
@{node: alt ci.node {
222224
instance_var(ident, t, cm, id, p) {
223-
instance_var(ident, fld.fold_ty(t), cm, id, p)
225+
instance_var(/* FIXME: bad */ copy ident, fld.fold_ty(t), cm, id,
226+
p)
224227
}
225228
class_method(m) { class_method(fld.fold_method(m)) }
226229
},
@@ -256,7 +259,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
256259
id: dtor_id with dtor.node}
257260
with dtor}};
258261
item_class(
259-
typms,
262+
/* FIXME: bad */ copy typms,
260263
vec::map(ifaces, {|p| fold_iface_ref(p, fld) }),
261264
vec::map(items, fld.fold_class_item),
262265
{node: {body: ctor_body,
@@ -274,7 +277,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
274277
item_iface(tps, rp, methods) {
275278
item_iface(fold_ty_params(tps, fld),
276279
rp,
277-
methods)
280+
/* FIXME: bad */ copy methods)
278281
}
279282
item_res(decl, typms, body, did, cid, rp) {
280283
item_res(fold_fn_decl(decl, fld),
@@ -293,7 +296,7 @@ fn fold_iface_ref(&&p: @iface_ref, fld: ast_fold) -> @iface_ref {
293296

294297
fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
295298
ret @{ident: fld.fold_ident(m.ident),
296-
attrs: m.attrs,
299+
attrs: /* FIXME: bad */ copy m.attrs,
297300
tps: fold_ty_params(m.tps, fld),
298301
decl: fold_fn_decl(m.decl, fld),
299302
body: fld.fold_block(m.body),
@@ -328,7 +331,7 @@ fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
328331

329332
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
330333
ret alt p {
331-
pat_wild { p }
334+
pat_wild { pat_wild }
332335
pat_ident(pth, sub) {
333336
pat_ident(fld.fold_path(pth), option::map(sub, fld.fold_pat))
334337
}
@@ -340,7 +343,8 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
340343
pat_rec(fields, etc) {
341344
let mut fs = [];
342345
for fields.each {|f|
343-
fs += [{ident: f.ident, pat: fld.fold_pat(f.pat)}];
346+
fs += [{ident: /* FIXME: bad */ copy f.ident,
347+
pat: fld.fold_pat(f.pat)}];
344348
}
345349
pat_rec(fs, etc)
346350
}
@@ -410,7 +414,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
410414
}
411415
expr_unary(binop, ohs) { expr_unary(binop, fld.fold_expr(ohs)) }
412416
expr_loop_body(f) { expr_loop_body(fld.fold_expr(f)) }
413-
expr_lit(_) { e }
417+
expr_lit(_) { copy e }
414418
expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
415419
expr_addr_of(m, ohs) { expr_addr_of(m, fld.fold_expr(ohs)) }
416420
expr_if(cond, tr, fl) {
@@ -462,7 +466,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
462466
}
463467
expr_path(pth) { expr_path(fld.fold_path(pth)) }
464468
expr_fail(e) { expr_fail(option::map(e, fld.fold_expr)) }
465-
expr_break | expr_cont { e }
469+
expr_break | expr_cont { copy e }
466470
expr_ret(e) { expr_ret(option::map(e, fld.fold_expr)) }
467471
expr_log(i, lv, e) { expr_log(i, fld.fold_expr(lv),
468472
fld.fold_expr(e)) }
@@ -487,7 +491,7 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
487491
span: fld.new_span(f.span)}
488492
}
489493
alt t {
490-
ty_nil | ty_bot {t}
494+
ty_nil | ty_bot | ty_infer {copy t}
491495
ty_box(mt) {ty_box(fold_mt(mt, fld))}
492496
ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))}
493497
ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
@@ -501,17 +505,18 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
501505
vec::map(constrs, fld.fold_ty_constr))}
502506
ty_vstore(t, vs) {ty_vstore(fld.fold_ty(t), vs)}
503507
ty_mac(mac) {ty_mac(fold_mac(mac))}
504-
ty_infer {t}
505508
}
506509
}
507510

508511
fn noop_fold_constr(c: constr_, fld: ast_fold) -> constr_ {
509-
{path: fld.fold_path(c.path), args: c.args, id: fld.new_id(c.id)}
512+
{path: fld.fold_path(c.path), args: /* FIXME: bad */ copy c.args,
513+
id: fld.new_id(c.id)}
510514
}
511515

512516
fn noop_fold_ty_constr(c: ty_constr_, fld: ast_fold) -> ty_constr_ {
513517
let rslt: ty_constr_ =
514-
{path: fld.fold_path(c.path), args: c.args, id: fld.new_id(c.id)};
518+
{path: fld.fold_path(c.path), args: /* FIXME: bad */ copy c.args,
519+
id: fld.new_id(c.id)};
515520
rslt
516521
}
517522
// ...nor do modules
@@ -539,14 +544,16 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
539544
some(e) {some(fld.fold_expr(e))}
540545
none {none}
541546
};
542-
ret {name: v.name,
547+
ret {name: /* FIXME: bad */ copy v.name,
543548
attrs: attrs,
544549
args: args, id: fld.new_id(v.id),
545550
disr_expr: de,
546551
vis: v.vis};
547552
}
548553

549-
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }
554+
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident {
555+
ret /* FIXME: bad */ copy i;
556+
}
550557

551558
fn noop_fold_path(&&p: path, fld: ast_fold) -> path {
552559
ret {span: fld.new_span(p.span), global: p.global,
@@ -639,8 +646,8 @@ impl of ast_fold for ast_fold_precursor {
639646
fn fold_class_item(&&ci: @class_member) -> @class_member {
640647
@{node: alt ci.node {
641648
instance_var(nm, t, mt, id, p) {
642-
instance_var(nm, (self as ast_fold).fold_ty(t),
643-
mt, id, p)
649+
instance_var(/* FIXME: bad */ copy nm,
650+
(self as ast_fold).fold_ty(t), mt, id, p)
644651
}
645652
class_method(m) {
646653
class_method(self.fold_method(m, self as ast_fold))

src/libsyntax/parse/common.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ impl parser_common for parser {
209209
ret v;
210210
}
211211

212+
// FIXME: A lot of callers go through here, only to copy out the T and
213+
// discard the spanned<> wrapper. I feel as though there should be a
214+
// version of this that does not return a spanned result.
212215
fn parse_seq<T: copy>(bra: token::token, ket: token::token, sep: seq_sep,
213216
f: fn(parser) -> T) -> spanned<[T]> {
214217
let lo = self.span.lo;
@@ -218,4 +221,4 @@ impl parser_common for parser {
218221
self.bump();
219222
ret spanned(lo, hi, result);
220223
}
221-
}
224+
}

src/libsyntax/parse/eval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ optional suffix then adding the .rs extension.
4444
fn parse_companion_mod(cx: ctx, prefix: str, suffix: option<str>)
4545
-> ([@ast::view_item], [@ast::item], [ast::attribute]) {
4646

47-
fn companion_file(prefix: str, suffix: option<str>) -> str {
47+
fn companion_file(+prefix: str, suffix: option<str>) -> str {
4848
ret alt suffix {
4949
option::some(s) { path::connect(prefix, s) }
5050
option::none { prefix }
@@ -66,8 +66,7 @@ fn parse_companion_mod(cx: ctx, prefix: str, suffix: option<str>)
6666
#debug("found companion mod");
6767
let p0 = new_parser_from_file(cx.sess, cx.cfg, modpath, SOURCE_FILE);
6868
let inner_attrs = p0.parse_inner_attrs_and_next();
69-
let first_item_outer_attrs = inner_attrs.next;
70-
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
69+
let m0 = p0.parse_mod_items(token::EOF, inner_attrs.next);
7170
cx.sess.chpos = p0.reader.chpos;
7271
cx.sess.byte_pos = cx.sess.byte_pos + p0.reader.pos;
7372
ret (m0.view_items, m0.items, inner_attrs.inner);
@@ -102,7 +101,8 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
102101
let first_item_outer_attrs = inner_attrs.next;
103102
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
104103

105-
let i = p0.mk_item(cdir.span.lo, cdir.span.hi, id,
104+
let i = p0.mk_item(cdir.span.lo, cdir.span.hi,
105+
/* FIXME: bad */ copy id,
106106
ast::item_mod(m0), ast::public, mod_attrs);
107107
// Thread defids, chpos and byte_pos through the parsers
108108
cx.sess.chpos = p0.reader.chpos;
@@ -118,7 +118,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
118118
let (m0, a0) = eval_crate_directives_to_mod(
119119
cx, cdirs, full_path, none);
120120
let i =
121-
@{ident: id,
121+
@{ident: /* FIXME: bad */ copy id,
122122
attrs: attrs + a0,
123123
id: cx.sess.next_id,
124124
node: ast::item_mod(m0),

0 commit comments

Comments
 (0)