Skip to content

Commit 847c5e4

Browse files
committed
syntax: Remove a bunch of implicit copies
1 parent 7ef825b commit 847c5e4

File tree

5 files changed

+80
-60
lines changed

5 files changed

+80
-60
lines changed

src/libsyntax/ast_map.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ type path = [path_elt];
1212
fn path_to_str_with_sep(p: path, sep: str) -> str {
1313
let strs = vec::map(p) {|e|
1414
alt e {
15-
path_mod(s) { s }
16-
path_name(s) { s }
15+
path_mod(s) { /* FIXME: bad */ copy s }
16+
path_name(s) { /* FIXME: bad */ copy s }
1717
}
1818
};
1919
str::connect(strs, sep)
2020
}
2121

2222
fn path_ident_to_str(p: path, i: ident) -> str {
2323
if vec::is_empty(p) {
24-
i
24+
/* FIXME: bad */ copy i
2525
} else {
2626
#fmt["%s::%s", path_to_str(p), i]
2727
}
@@ -59,7 +59,7 @@ type ctx = {map: map, mut path: path,
5959
mut local_id: uint, diag: span_handler};
6060
type vt = visit::vt<ctx>;
6161

62-
fn extend(cx: ctx, elt: str) -> @path {
62+
fn extend(cx: ctx, +elt: str) -> @path {
6363
@(cx.path + [path_name(elt)])
6464
}
6565

@@ -89,15 +89,15 @@ fn map_crate(diag: span_handler, c: crate) -> map {
8989
// crate. The `path` should be the path to the item but should not include
9090
// the item itself.
9191
fn map_decoded_item(diag: span_handler,
92-
map: map, path: path, ii: inlined_item) {
92+
map: map, +path: path, ii: inlined_item) {
9393
// I believe it is ok for the local IDs of inlined items from other crates
9494
// to overlap with the local ids from this crate, so just generate the ids
9595
// starting from 0. (In particular, I think these ids are only used in
9696
// alias analysis, which we will not be running on the inlined items, and
9797
// even if we did I think it only needs an ordering between local
9898
// variables that are simultaneously in scope).
9999
let cx = {map: map,
100-
mut path: path,
100+
mut path: /* FIXME: bad */ copy path,
101101
mut local_id: 0u,
102102
diag: diag};
103103
let v = mk_ast_map_visitor();
@@ -128,11 +128,13 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
128128
}
129129
alt fk {
130130
visit::fk_ctor(nm, tps, self_id, parent_id) {
131-
let ct = @{node: {id: id, self_id: self_id,
132-
dec: decl, body: body},
131+
let ct = @{node: {id: id,
132+
self_id: self_id,
133+
dec: /* FIXME: bad */ copy decl,
134+
body: /* FIXME: bad */ copy body},
133135
span: sp};
134-
cx.map.insert(id, node_ctor(nm, tps, class_ctor(ct, parent_id),
135-
@cx.path));
136+
cx.map.insert(id, node_ctor(/* FIXME: bad */ copy nm, tps,
137+
class_ctor(ct, parent_id), @cx.path));
136138
}
137139
visit::fk_dtor(tps, self_id, parent_id) {
138140
let dt = @{node: {id: id, self_id: self_id, body: body},

src/libsyntax/ast_util.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
156156
for variants.each {|v|
157157
if v.node.name == i {
158158
local = true;
159-
parent_enum = some(it.ident);
159+
parent_enum = some(/* FIXME: bad */ copy it.ident);
160160
}
161161
}
162162
}
@@ -247,12 +247,12 @@ fn block_from_expr(e: @expr) -> blk {
247247
ret {node: blk_, span: e.span};
248248
}
249249

250-
fn default_block(stmts1: [@stmt], expr1: option<@expr>, id1: node_id) ->
250+
fn default_block(+stmts1: [@stmt], expr1: option<@expr>, id1: node_id) ->
251251
blk_ {
252252
{view_items: [], stmts: stmts1, expr: expr1, id: id1, rules: default_blk}
253253
}
254254

255-
fn ident_to_path(s: span, i: ident) -> @path {
255+
fn ident_to_path(s: span, +i: ident) -> @path {
256256
@{span: s, global: false, idents: [i],
257257
rp: none, types: []}
258258
}
@@ -265,7 +265,7 @@ pure fn is_unguarded(&&a: arm) -> bool {
265265
}
266266

267267
pure fn unguarded_pat(a: arm) -> option<[@pat]> {
268-
if is_unguarded(a) { some(a.pats) } else { none }
268+
if is_unguarded(a) { some(/* FIXME: bad */ copy a.pats) } else { none }
269269
}
270270

271271
// Provides an extra node_id to hang callee information on, in case the
@@ -275,8 +275,8 @@ fn op_expr_callee_id(e: @expr) -> node_id { e.id - 1 }
275275

276276
pure fn class_item_ident(ci: @class_member) -> ident {
277277
alt ci.node {
278-
instance_var(i,_,_,_,_) { i }
279-
class_method(it) { it.ident }
278+
instance_var(i,_,_,_,_) { /* FIXME: bad */ copy i }
279+
class_method(it) { /* FIXME: bad */ copy it.ident }
280280
}
281281
}
282282

@@ -294,7 +294,11 @@ fn split_class_items(cs: [@class_member]) -> ([ivar], [@method]) {
294294
for cs.each {|c|
295295
alt c.node {
296296
instance_var(i, t, cm, id, vis) {
297-
vs += [{ident: i, ty: t, cm: cm, id: id, vis: vis}];
297+
vs += [{ident: /* FIXME: bad */ copy i,
298+
ty: t,
299+
cm: cm,
300+
id: id,
301+
vis: vis}];
298302
}
299303
class_method(m) { ms += [m]; }
300304
}
@@ -312,10 +316,10 @@ pure fn class_member_visibility(ci: @class_member) -> visibility {
312316
impl inlined_item_methods for inlined_item {
313317
fn ident() -> ident {
314318
alt self {
315-
ii_item(i) { i.ident }
316-
ii_native(i) { i.ident }
317-
ii_method(_, m) { m.ident }
318-
ii_ctor(_, nm, _, _) { nm }
319+
ii_item(i) { /* FIXME: bad */ copy i.ident }
320+
ii_native(i) { /* FIXME: bad */ copy i.ident }
321+
ii_method(_, m) { /* FIXME: bad */ copy m.ident }
322+
ii_ctor(_, nm, _, _) { /* FIXME: bad */ copy nm }
319323
}
320324
}
321325

src/libsyntax/attr.rs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ export require_unique_names;
4646

4747
/* Constructors */
4848

49-
fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item {
49+
fn mk_name_value_item_str(+name: ast::ident, +value: str) -> @ast::meta_item {
5050
let value_lit = dummy_spanned(ast::lit_str(value));
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) -> @ast::meta_item {
5555
ret @dummy_spanned(ast::meta_name_value(name, value));
5656
}
5757

58-
fn mk_list_item(name: ast::ident, items: [@ast::meta_item]) ->
58+
fn mk_list_item(+name: ast::ident, +items: [@ast::meta_item]) ->
5959
@ast::meta_item {
6060
ret @dummy_spanned(ast::meta_list(name, items));
6161
}
6262

63-
fn mk_word_item(name: ast::ident) -> @ast::meta_item {
63+
fn mk_word_item(+name: ast::ident) -> @ast::meta_item {
6464
ret @dummy_spanned(ast::meta_word(name));
6565
}
6666

@@ -89,9 +89,9 @@ fn get_attr_name(attr: ast::attribute) -> ast::ident {
8989

9090
fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
9191
alt meta.node {
92-
ast::meta_word(n) { n }
93-
ast::meta_name_value(n, _) { n }
94-
ast::meta_list(n, _) { n }
92+
ast::meta_word(n) { /* FIXME bad */ copy n }
93+
ast::meta_name_value(n, _) { /* FIXME bad */ copy n }
94+
ast::meta_list(n, _) { /* FIXME bad */ copy n }
9595
}
9696
}
9797

@@ -102,7 +102,14 @@ containing a string, otherwise none
102102
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<str> {
103103
alt meta.node {
104104
ast::meta_name_value(_, v) {
105-
alt v.node { ast::lit_str(s) { option::some(s) } _ { option::none } }
105+
alt v.node {
106+
ast::lit_str(s) {
107+
option::some(/* FIXME bad */ copy s)
108+
}
109+
_ {
110+
option::none
111+
}
112+
}
106113
}
107114
_ { option::none }
108115
}
@@ -111,7 +118,7 @@ fn get_meta_item_value_str(meta: @ast::meta_item) -> option<str> {
111118
#[doc = "Gets a list of inner meta items from a list meta_item type"]
112119
fn get_meta_item_list(meta: @ast::meta_item) -> option<[@ast::meta_item]> {
113120
alt meta.node {
114-
ast::meta_list(_, l) { option::some(l) }
121+
ast::meta_list(_, l) { option::some(/* FIXME bad */ copy l) }
115122
_ { option::none }
116123
}
117124
}
@@ -126,7 +133,7 @@ fn get_name_value_str_pair(
126133
alt attr::get_meta_item_value_str(item) {
127134
some(value) {
128135
let name = attr::get_meta_item_name(item);
129-
some((name, value))
136+
some((name, /* FIXME bad */ copy value))
130137
}
131138
none { none }
132139
}
@@ -138,7 +145,7 @@ fn get_name_value_str_pair(
138145
#[doc = "
139146
Search a list of attributes and return only those with a specific name
140147
"]
141-
fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
148+
fn find_attrs_by_name(attrs: [ast::attribute], +name: ast::ident) ->
142149
[ast::attribute] {
143150
let filter = (
144151
fn@(a: ast::attribute) -> option<ast::attribute> {
@@ -153,7 +160,7 @@ fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
153160
#[doc = "
154161
Searcha list of meta items and return only those with a specific name
155162
"]
156-
fn find_meta_items_by_name(metas: [@ast::meta_item], name: ast::ident) ->
163+
fn find_meta_items_by_name(metas: [@ast::meta_item], +name: ast::ident) ->
157164
[@ast::meta_item] {
158165
let filter = fn@(&&m: @ast::meta_item) -> option<@ast::meta_item> {
159166
if get_meta_item_name(m) == name {
@@ -201,16 +208,16 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
201208
}
202209
}
203210

204-
fn contains_name(metas: [@ast::meta_item], name: ast::ident) -> bool {
211+
fn contains_name(metas: [@ast::meta_item], +name: ast::ident) -> bool {
205212
let matches = find_meta_items_by_name(metas, name);
206213
ret vec::len(matches) > 0u;
207214
}
208215

209-
fn attrs_contains_name(attrs: [ast::attribute], name: ast::ident) -> bool {
216+
fn attrs_contains_name(attrs: [ast::attribute], +name: ast::ident) -> bool {
210217
vec::is_not_empty(find_attrs_by_name(attrs, name))
211218
}
212219

213-
fn first_attr_value_str_by_name(attrs: [ast::attribute], name: ast::ident)
220+
fn first_attr_value_str_by_name(attrs: [ast::attribute], +name: ast::ident)
214221
-> option<str> {
215222
let mattrs = find_attrs_by_name(attrs, name);
216223
if vec::len(mattrs) > 0u {
@@ -221,20 +228,20 @@ fn first_attr_value_str_by_name(attrs: [ast::attribute], name: ast::ident)
221228

222229
fn last_meta_item_by_name(
223230
items: [@ast::meta_item],
224-
name: str
231+
+name: str
225232
) -> option<@ast::meta_item> {
226233
let items = attr::find_meta_items_by_name(items, name);
227234
vec::last_opt(items)
228235
}
229236

230237
fn last_meta_item_value_str_by_name(
231238
items: [@ast::meta_item],
232-
name: str
239+
+name: str
233240
) -> option<str> {
234241
alt last_meta_item_by_name(items, name) {
235242
some(item) {
236243
alt attr::get_meta_item_value_str(item) {
237-
some(value) { some(value) }
244+
some(value) { some(/* FIXME bad */ copy value) }
238245
none { none }
239246
}
240247
}
@@ -244,7 +251,7 @@ fn last_meta_item_value_str_by_name(
244251

245252
fn last_meta_item_list_by_name(
246253
items: [@ast::meta_item],
247-
name: str
254+
+name: str
248255
) -> option<[@ast::meta_item]> {
249256
alt last_meta_item_by_name(items, name) {
250257
some(item) {
@@ -259,13 +266,13 @@ fn last_meta_item_list_by_name(
259266

260267
// FIXME: This needs to sort by meta_item variant in addition to the item name
261268
// (See [Fixme-sorting])
262-
fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] {
269+
fn sort_meta_items(+items: [@ast::meta_item]) -> [@ast::meta_item] {
263270
fn lteq(&&ma: @ast::meta_item, &&mb: @ast::meta_item) -> bool {
264271
fn key(m: @ast::meta_item) -> ast::ident {
265272
alt m.node {
266-
ast::meta_word(name) { name }
267-
ast::meta_name_value(name, _) { name }
268-
ast::meta_list(name, _) { name }
273+
ast::meta_word(name) { /* FIXME bad */ copy name }
274+
ast::meta_name_value(name, _) { /* FIXME bad */ copy name }
275+
ast::meta_list(name, _) { /* FIXME bad */ copy name }
269276
}
270277
}
271278
ret key(ma) <= key(mb);
@@ -280,13 +287,14 @@ fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] {
280287
fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) ->
281288
[@ast::meta_item] {
282289

283-
let filter = fn@(&&item: @ast::meta_item) -> option<@ast::meta_item> {
290+
ret vec::filter_map(items, {
291+
|item|
284292
if get_meta_item_name(item) != name {
285-
option::some(item)
286-
} else { option::none }
287-
};
288-
289-
ret vec::filter_map(items, filter);
293+
option::some(/* FIXME bad */ copy item)
294+
} else {
295+
option::none
296+
}
297+
});
290298
}
291299

292300
fn find_linkage_attrs(attrs: [ast::attribute]) -> [ast::attribute] {
@@ -307,7 +315,7 @@ linkage
307315
fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
308316
find_linkage_attrs(attrs).flat_map {|attr|
309317
alt check attr.node.value.node {
310-
ast::meta_list(_, items) { items }
318+
ast::meta_list(_, items) { /* FIXME bad */ copy items }
311319
}
312320
}
313321
}
@@ -362,6 +370,8 @@ fn require_unique_names(diagnostic: span_handler,
362370
let map = map::str_hash();
363371
for metas.each {|meta|
364372
let name = get_meta_item_name(meta);
373+
374+
// FIXME: How do I silence the warnings? --pcw
365375
if map.contains_key(name) {
366376
diagnostic.span_fatal(meta.span,
367377
#fmt["duplicate meta item `%s`", name]);

src/libsyntax/codemap.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type loc = {file: filemap, line: uint, col: uint};
5151

5252
fn new_codemap() -> codemap { @{files: dvec()} }
5353

54-
fn new_filemap_w_substr(filename: filename, substr: file_substr,
54+
fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
5555
src: @str,
5656
start_pos_ch: uint, start_pos_byte: uint)
5757
-> filemap {
@@ -60,7 +60,7 @@ fn new_filemap_w_substr(filename: filename, substr: file_substr,
6060
mut lines: [{ch: start_pos_ch, byte: start_pos_byte}]};
6161
}
6262

63-
fn new_filemap(filename: filename, src: @str,
63+
fn new_filemap(+filename: filename, src: @str,
6464
start_pos_ch: uint, start_pos_byte: uint)
6565
-> filemap {
6666
ret new_filemap_w_substr(filename, fss_none, src,
@@ -123,14 +123,16 @@ fn lookup_char_pos_adj(map: codemap, pos: uint)
123123
let loc = lookup_char_pos(map, pos);
124124
alt (loc.file.substr) {
125125
fss_none {
126-
{filename: loc.file.name, line: loc.line, col: loc.col,
126+
{filename: /* FIXME bad */ copy loc.file.name,
127+
line: loc.line,
128+
col: loc.col,
127129
file: some(loc.file)}
128130
}
129131
fss_internal(sp) {
130132
lookup_char_pos_adj(map, sp.lo + (pos - loc.file.start_pos.ch))
131133
}
132134
fss_external(eloc) {
133-
{filename: eloc.filename,
135+
{filename: /* FIXME bad */ copy eloc.filename,
134136
line: eloc.line + loc.line - 1u,
135137
col: if loc.line == 1u {eloc.col + loc.col} else {loc.col},
136138
file: none}
@@ -176,7 +178,7 @@ type file_lines = {file: filemap, lines: [uint]};
176178

177179
fn span_to_filename(sp: span, cm: codemap::codemap) -> filename {
178180
let lo = lookup_char_pos(cm, sp.lo);
179-
ret lo.file.name;
181+
ret /* FIXME bad */ copy lo.file.name;
180182
}
181183

182184
fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {

0 commit comments

Comments
 (0)