syntax: Remove a bunch of implicit copies

This commit is contained in:
Patrick Walton 2012-06-07 20:12:05 -07:00
parent 7ef825bb60
commit 847c5e4e98
5 changed files with 80 additions and 60 deletions

View file

@ -12,8 +12,8 @@ type path = [path_elt];
fn path_to_str_with_sep(p: path, sep: str) -> str {
let strs = vec::map(p) {|e|
alt e {
path_mod(s) { s }
path_name(s) { s }
path_mod(s) { /* FIXME: bad */ copy s }
path_name(s) { /* FIXME: bad */ copy s }
}
};
str::connect(strs, sep)
@ -21,7 +21,7 @@ fn path_to_str_with_sep(p: path, sep: str) -> str {
fn path_ident_to_str(p: path, i: ident) -> str {
if vec::is_empty(p) {
i
/* FIXME: bad */ copy i
} else {
#fmt["%s::%s", path_to_str(p), i]
}
@ -59,7 +59,7 @@ type ctx = {map: map, mut path: path,
mut local_id: uint, diag: span_handler};
type vt = visit::vt<ctx>;
fn extend(cx: ctx, elt: str) -> @path {
fn extend(cx: ctx, +elt: str) -> @path {
@(cx.path + [path_name(elt)])
}
@ -89,7 +89,7 @@ fn map_crate(diag: span_handler, c: crate) -> map {
// crate. The `path` should be the path to the item but should not include
// the item itself.
fn map_decoded_item(diag: span_handler,
map: map, path: path, ii: inlined_item) {
map: map, +path: path, ii: inlined_item) {
// I believe it is ok for the local IDs of inlined items from other crates
// to overlap with the local ids from this crate, so just generate the ids
// starting from 0. (In particular, I think these ids are only used in
@ -97,7 +97,7 @@ fn map_decoded_item(diag: span_handler,
// even if we did I think it only needs an ordering between local
// variables that are simultaneously in scope).
let cx = {map: map,
mut path: path,
mut path: /* FIXME: bad */ copy path,
mut local_id: 0u,
diag: diag};
let v = mk_ast_map_visitor();
@ -128,11 +128,13 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
}
alt fk {
visit::fk_ctor(nm, tps, self_id, parent_id) {
let ct = @{node: {id: id, self_id: self_id,
dec: decl, body: body},
let ct = @{node: {id: id,
self_id: self_id,
dec: /* FIXME: bad */ copy decl,
body: /* FIXME: bad */ copy body},
span: sp};
cx.map.insert(id, node_ctor(nm, tps, class_ctor(ct, parent_id),
@cx.path));
cx.map.insert(id, node_ctor(/* FIXME: bad */ copy nm, tps,
class_ctor(ct, parent_id), @cx.path));
}
visit::fk_dtor(tps, self_id, parent_id) {
let dt = @{node: {id: id, self_id: self_id, body: body},

View file

@ -156,7 +156,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
for variants.each {|v|
if v.node.name == i {
local = true;
parent_enum = some(it.ident);
parent_enum = some(/* FIXME: bad */ copy it.ident);
}
}
}
@ -247,12 +247,12 @@ fn block_from_expr(e: @expr) -> blk {
ret {node: blk_, span: e.span};
}
fn default_block(stmts1: [@stmt], expr1: option<@expr>, id1: node_id) ->
fn default_block(+stmts1: [@stmt], expr1: option<@expr>, id1: node_id) ->
blk_ {
{view_items: [], stmts: stmts1, expr: expr1, id: id1, rules: default_blk}
}
fn ident_to_path(s: span, i: ident) -> @path {
fn ident_to_path(s: span, +i: ident) -> @path {
@{span: s, global: false, idents: [i],
rp: none, types: []}
}
@ -265,7 +265,7 @@ pure fn is_unguarded(&&a: arm) -> bool {
}
pure fn unguarded_pat(a: arm) -> option<[@pat]> {
if is_unguarded(a) { some(a.pats) } else { none }
if is_unguarded(a) { some(/* FIXME: bad */ copy a.pats) } else { none }
}
// 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 }
pure fn class_item_ident(ci: @class_member) -> ident {
alt ci.node {
instance_var(i,_,_,_,_) { i }
class_method(it) { it.ident }
instance_var(i,_,_,_,_) { /* FIXME: bad */ copy i }
class_method(it) { /* FIXME: bad */ copy it.ident }
}
}
@ -294,7 +294,11 @@ fn split_class_items(cs: [@class_member]) -> ([ivar], [@method]) {
for cs.each {|c|
alt c.node {
instance_var(i, t, cm, id, vis) {
vs += [{ident: i, ty: t, cm: cm, id: id, vis: vis}];
vs += [{ident: /* FIXME: bad */ copy i,
ty: t,
cm: cm,
id: id,
vis: vis}];
}
class_method(m) { ms += [m]; }
}
@ -312,10 +316,10 @@ pure fn class_member_visibility(ci: @class_member) -> visibility {
impl inlined_item_methods for inlined_item {
fn ident() -> ident {
alt self {
ii_item(i) { i.ident }
ii_native(i) { i.ident }
ii_method(_, m) { m.ident }
ii_ctor(_, nm, _, _) { nm }
ii_item(i) { /* FIXME: bad */ copy i.ident }
ii_native(i) { /* FIXME: bad */ copy i.ident }
ii_method(_, m) { /* FIXME: bad */ copy m.ident }
ii_ctor(_, nm, _, _) { /* FIXME: bad */ copy nm }
}
}

View file

@ -46,21 +46,21 @@ export require_unique_names;
/* Constructors */
fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item {
fn mk_name_value_item_str(+name: ast::ident, +value: str) -> @ast::meta_item {
let value_lit = dummy_spanned(ast::lit_str(value));
ret mk_name_value_item(name, value_lit);
}
fn mk_name_value_item(name: ast::ident, value: ast::lit) -> @ast::meta_item {
fn mk_name_value_item(+name: ast::ident, +value: ast::lit) -> @ast::meta_item {
ret @dummy_spanned(ast::meta_name_value(name, value));
}
fn mk_list_item(name: ast::ident, items: [@ast::meta_item]) ->
fn mk_list_item(+name: ast::ident, +items: [@ast::meta_item]) ->
@ast::meta_item {
ret @dummy_spanned(ast::meta_list(name, items));
}
fn mk_word_item(name: ast::ident) -> @ast::meta_item {
fn mk_word_item(+name: ast::ident) -> @ast::meta_item {
ret @dummy_spanned(ast::meta_word(name));
}
@ -89,9 +89,9 @@ fn get_attr_name(attr: ast::attribute) -> ast::ident {
fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
alt meta.node {
ast::meta_word(n) { n }
ast::meta_name_value(n, _) { n }
ast::meta_list(n, _) { n }
ast::meta_word(n) { /* FIXME bad */ copy n }
ast::meta_name_value(n, _) { /* FIXME bad */ copy n }
ast::meta_list(n, _) { /* FIXME bad */ copy n }
}
}
@ -102,7 +102,14 @@ containing a string, otherwise none
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<str> {
alt meta.node {
ast::meta_name_value(_, v) {
alt v.node { ast::lit_str(s) { option::some(s) } _ { option::none } }
alt v.node {
ast::lit_str(s) {
option::some(/* FIXME bad */ copy s)
}
_ {
option::none
}
}
}
_ { option::none }
}
@ -111,7 +118,7 @@ fn get_meta_item_value_str(meta: @ast::meta_item) -> option<str> {
#[doc = "Gets a list of inner meta items from a list meta_item type"]
fn get_meta_item_list(meta: @ast::meta_item) -> option<[@ast::meta_item]> {
alt meta.node {
ast::meta_list(_, l) { option::some(l) }
ast::meta_list(_, l) { option::some(/* FIXME bad */ copy l) }
_ { option::none }
}
}
@ -126,7 +133,7 @@ fn get_name_value_str_pair(
alt attr::get_meta_item_value_str(item) {
some(value) {
let name = attr::get_meta_item_name(item);
some((name, value))
some((name, /* FIXME bad */ copy value))
}
none { none }
}
@ -138,7 +145,7 @@ fn get_name_value_str_pair(
#[doc = "
Search a list of attributes and return only those with a specific name
"]
fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
fn find_attrs_by_name(attrs: [ast::attribute], +name: ast::ident) ->
[ast::attribute] {
let filter = (
fn@(a: ast::attribute) -> option<ast::attribute> {
@ -153,7 +160,7 @@ fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
#[doc = "
Searcha list of meta items and return only those with a specific name
"]
fn find_meta_items_by_name(metas: [@ast::meta_item], name: ast::ident) ->
fn find_meta_items_by_name(metas: [@ast::meta_item], +name: ast::ident) ->
[@ast::meta_item] {
let filter = fn@(&&m: @ast::meta_item) -> option<@ast::meta_item> {
if get_meta_item_name(m) == name {
@ -201,16 +208,16 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
}
}
fn contains_name(metas: [@ast::meta_item], name: ast::ident) -> bool {
fn contains_name(metas: [@ast::meta_item], +name: ast::ident) -> bool {
let matches = find_meta_items_by_name(metas, name);
ret vec::len(matches) > 0u;
}
fn attrs_contains_name(attrs: [ast::attribute], name: ast::ident) -> bool {
fn attrs_contains_name(attrs: [ast::attribute], +name: ast::ident) -> bool {
vec::is_not_empty(find_attrs_by_name(attrs, name))
}
fn first_attr_value_str_by_name(attrs: [ast::attribute], name: ast::ident)
fn first_attr_value_str_by_name(attrs: [ast::attribute], +name: ast::ident)
-> option<str> {
let mattrs = find_attrs_by_name(attrs, name);
if vec::len(mattrs) > 0u {
@ -221,7 +228,7 @@ fn first_attr_value_str_by_name(attrs: [ast::attribute], name: ast::ident)
fn last_meta_item_by_name(
items: [@ast::meta_item],
name: str
+name: str
) -> option<@ast::meta_item> {
let items = attr::find_meta_items_by_name(items, name);
vec::last_opt(items)
@ -229,12 +236,12 @@ fn last_meta_item_by_name(
fn last_meta_item_value_str_by_name(
items: [@ast::meta_item],
name: str
+name: str
) -> option<str> {
alt last_meta_item_by_name(items, name) {
some(item) {
alt attr::get_meta_item_value_str(item) {
some(value) { some(value) }
some(value) { some(/* FIXME bad */ copy value) }
none { none }
}
}
@ -244,7 +251,7 @@ fn last_meta_item_value_str_by_name(
fn last_meta_item_list_by_name(
items: [@ast::meta_item],
name: str
+name: str
) -> option<[@ast::meta_item]> {
alt last_meta_item_by_name(items, name) {
some(item) {
@ -259,13 +266,13 @@ fn last_meta_item_list_by_name(
// FIXME: This needs to sort by meta_item variant in addition to the item name
// (See [Fixme-sorting])
fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] {
fn sort_meta_items(+items: [@ast::meta_item]) -> [@ast::meta_item] {
fn lteq(&&ma: @ast::meta_item, &&mb: @ast::meta_item) -> bool {
fn key(m: @ast::meta_item) -> ast::ident {
alt m.node {
ast::meta_word(name) { name }
ast::meta_name_value(name, _) { name }
ast::meta_list(name, _) { name }
ast::meta_word(name) { /* FIXME bad */ copy name }
ast::meta_name_value(name, _) { /* FIXME bad */ copy name }
ast::meta_list(name, _) { /* FIXME bad */ copy name }
}
}
ret key(ma) <= key(mb);
@ -280,13 +287,14 @@ fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] {
fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) ->
[@ast::meta_item] {
let filter = fn@(&&item: @ast::meta_item) -> option<@ast::meta_item> {
ret vec::filter_map(items, {
|item|
if get_meta_item_name(item) != name {
option::some(item)
} else { option::none }
};
ret vec::filter_map(items, filter);
option::some(/* FIXME bad */ copy item)
} else {
option::none
}
});
}
fn find_linkage_attrs(attrs: [ast::attribute]) -> [ast::attribute] {
@ -307,7 +315,7 @@ linkage
fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
find_linkage_attrs(attrs).flat_map {|attr|
alt check attr.node.value.node {
ast::meta_list(_, items) { items }
ast::meta_list(_, items) { /* FIXME bad */ copy items }
}
}
}
@ -362,6 +370,8 @@ fn require_unique_names(diagnostic: span_handler,
let map = map::str_hash();
for metas.each {|meta|
let name = get_meta_item_name(meta);
// FIXME: How do I silence the warnings? --pcw
if map.contains_key(name) {
diagnostic.span_fatal(meta.span,
#fmt["duplicate meta item `%s`", name]);

View file

@ -51,7 +51,7 @@ type loc = {file: filemap, line: uint, col: uint};
fn new_codemap() -> codemap { @{files: dvec()} }
fn new_filemap_w_substr(filename: filename, substr: file_substr,
fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
src: @str,
start_pos_ch: uint, start_pos_byte: uint)
-> filemap {
@ -60,7 +60,7 @@ fn new_filemap_w_substr(filename: filename, substr: file_substr,
mut lines: [{ch: start_pos_ch, byte: start_pos_byte}]};
}
fn new_filemap(filename: filename, src: @str,
fn new_filemap(+filename: filename, src: @str,
start_pos_ch: uint, start_pos_byte: uint)
-> filemap {
ret new_filemap_w_substr(filename, fss_none, src,
@ -123,14 +123,16 @@ fn lookup_char_pos_adj(map: codemap, pos: uint)
let loc = lookup_char_pos(map, pos);
alt (loc.file.substr) {
fss_none {
{filename: loc.file.name, line: loc.line, col: loc.col,
{filename: /* FIXME bad */ copy loc.file.name,
line: loc.line,
col: loc.col,
file: some(loc.file)}
}
fss_internal(sp) {
lookup_char_pos_adj(map, sp.lo + (pos - loc.file.start_pos.ch))
}
fss_external(eloc) {
{filename: eloc.filename,
{filename: /* FIXME bad */ copy eloc.filename,
line: eloc.line + loc.line - 1u,
col: if loc.line == 1u {eloc.col + loc.col} else {loc.col},
file: none}
@ -176,7 +178,7 @@ type file_lines = {file: filemap, lines: [uint]};
fn span_to_filename(sp: span, cm: codemap::codemap) -> filename {
let lo = lookup_char_pos(cm, sp.lo);
ret lo.file.name;
ret /* FIXME bad */ copy lo.file.name;
}
fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {

View file

@ -201,7 +201,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
// arbitrarily only print up to six lines of the error
let max_lines = 6u;
let mut elided = false;
let mut display_lines = lines.lines;
let mut display_lines = /* FIXME bad */ copy lines.lines;
if vec::len(display_lines) > max_lines {
display_lines = vec::slice(display_lines, 0u, max_lines);
elided = true;
@ -250,9 +250,11 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
option::iter (sp.expn_info) {|ei|
let ss = option::map_default(ei.callie.span, "",
bind codemap::span_to_str(_, cm));
print_diagnostic(ss, note,
let ss = option::map_default(ei.callie.span, @"", {
|span|
@codemap::span_to_str(span, cm)
});
print_diagnostic(*ss, note,
#fmt("in expansion of #%s", ei.callie.name));
let ss = codemap::span_to_str(ei.call_site, cm);
print_diagnostic(ss, note, "expansion site");