Remove a vestige of return-by-reference
This commit is contained in:
parent
107f827b53
commit
fe8a31e569
@ -141,18 +141,14 @@ fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) {
|
||||
}
|
||||
|
||||
fn visit_block(cx: @ctx, b: ast::blk, sc: scope, v: vt<scope>) {
|
||||
let bs = sc.bs, sc = sc;
|
||||
let sc = sc;
|
||||
for stmt in b.node.stmts {
|
||||
alt stmt.node {
|
||||
ast::stmt_decl(@{node: ast::decl_item(it), _}, _) {
|
||||
v.visit_item(it, sc, v);
|
||||
}
|
||||
ast::stmt_decl(@{node: ast::decl_local(locs), _}, _) {
|
||||
for (st, loc) in locs {
|
||||
if st == ast::let_ref {
|
||||
add_bindings_for_let(*cx, bs, loc);
|
||||
sc = {bs: bs with sc};
|
||||
}
|
||||
for loc in locs {
|
||||
alt loc.node.init {
|
||||
some(init) {
|
||||
if init.op == ast::init_move {
|
||||
@ -547,7 +543,7 @@ fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t,
|
||||
|
||||
fn def_is_local(d: ast::def) -> bool {
|
||||
alt d {
|
||||
ast::def_local(_, _) | ast::def_arg(_, _) | ast::def_binding(_) |
|
||||
ast::def_local(_) | ast::def_arg(_, _) | ast::def_binding(_) |
|
||||
ast::def_upvar(_, _, _) | ast::def_self(_) { true }
|
||||
_ { false }
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
|
||||
alt stmt.node {
|
||||
stmt_decl(@{node: decl_local(locals), _}, _) {
|
||||
for (_, local) in locals {
|
||||
for local in locals {
|
||||
alt local.node.init {
|
||||
some({op: init_assign, expr}) { maybe_copy(cx, expr); }
|
||||
_ {}
|
||||
|
@ -285,7 +285,7 @@ fn clear_in_current(cx: ctx, my_def: node_id, to: bool) {
|
||||
fn clear_def_if_path(cx: ctx, d: def, to: bool)
|
||||
-> option<node_id> {
|
||||
alt d {
|
||||
def_local(def_id, let_copy) {
|
||||
def_local(def_id) {
|
||||
clear_in_current(cx, def_id.node, to);
|
||||
some(def_id.node)
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ fn visit_decl(cx: @ctx, d: @decl, &&e: (), v: visit::vt<()>) {
|
||||
visit::visit_decl(d, e, v);
|
||||
alt d.node {
|
||||
decl_local(locs) {
|
||||
for (_, loc) in locs {
|
||||
for loc in locs {
|
||||
alt loc.node.init {
|
||||
some(init) {
|
||||
if init.op == init_move { check_move_rhs(cx, init.expr); }
|
||||
@ -282,7 +282,6 @@ fn is_immutable_def(cx: @ctx, def: def) -> option<str> {
|
||||
};
|
||||
}
|
||||
def_binding(_) { some("binding") }
|
||||
def_local(_, let_ref) { some("by-reference binding") }
|
||||
_ { none }
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +542,7 @@ fn visit_decl_with_scope(d: @decl, sc: scopes, v: vt<scopes>) {
|
||||
};
|
||||
alt d.node {
|
||||
decl_local(locs) {
|
||||
for (_, loc) in locs { v.visit_local(loc, sc, v);; *loc_pos += 1u; }
|
||||
for loc in locs { v.visit_local(loc, sc, v);; *loc_pos += 1u; }
|
||||
}
|
||||
decl_item(it) { v.visit_item(it, sc, v); }
|
||||
}
|
||||
@ -882,7 +882,7 @@ fn scope_closes(sc: scope) -> option<node_id> {
|
||||
|
||||
fn def_is_local(d: def) -> bool {
|
||||
alt d {
|
||||
ast::def_arg(_, _) | ast::def_local(_, _) | ast::def_binding(_) |
|
||||
ast::def_arg(_, _) | ast::def_local(_) | ast::def_binding(_) |
|
||||
ast::def_upvar(_, _, _) { true }
|
||||
_ { false }
|
||||
}
|
||||
@ -1114,12 +1114,12 @@ fn lookup_in_block(e: env, name: ident, sp: span, b: ast::blk_, pos: uint,
|
||||
let j = vec::len(locs);
|
||||
while j > 0u {
|
||||
j -= 1u;
|
||||
let (style, loc) = locs[j];
|
||||
let loc = locs[j];
|
||||
if ns == ns_val(ns_any_value)
|
||||
&& (i < pos || j < loc_pos) {
|
||||
alt lookup_in_pat(e, name, loc.node.pat) {
|
||||
some(did) {
|
||||
ret some(ast::def_local(did, style));
|
||||
ret some(ast::def_local(did));
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
@ -1549,7 +1549,7 @@ fn ns_for_def(d: def) -> namespace {
|
||||
alt d {
|
||||
ast::def_variant(_, _) { ns_val(ns_a_enum) }
|
||||
ast::def_fn(_, _) | ast::def_self(_) |
|
||||
ast::def_const(_) | ast::def_arg(_, _) | ast::def_local(_, _) |
|
||||
ast::def_const(_) | ast::def_arg(_, _) | ast::def_local(_) |
|
||||
ast::def_upvar(_, _, _) | ast::def_self(_) |
|
||||
ast::def_class_field(_,_) | ast::def_class_method(_,_)
|
||||
{ ns_val(ns_any_value) }
|
||||
@ -1713,7 +1713,7 @@ fn check_block(e: @env, b: ast::blk, &&x: (), v: vt<()>) {
|
||||
alt d.node {
|
||||
ast::decl_local(locs) {
|
||||
let local_values = checker(*e, "value");
|
||||
for (_, loc) in locs {
|
||||
for loc in locs {
|
||||
pat_util::pat_bindings
|
||||
(normalize_pat_def_map(e.def_map, loc.node.pat))
|
||||
{|_i, p_sp, n|
|
||||
|
@ -2395,7 +2395,7 @@ fn trans_local_var(cx: @block_ctxt, def: ast::def) -> local_var_result {
|
||||
assert (cx.fcx.llargs.contains_key(did.node));
|
||||
ret take_local(cx.fcx.llargs, did.node);
|
||||
}
|
||||
ast::def_local(did, _) | ast::def_binding(did) {
|
||||
ast::def_local(did) | ast::def_binding(did) {
|
||||
assert (cx.fcx.lllocals.contains_key(did.node));
|
||||
ret take_local(cx.fcx.lllocals, did.node);
|
||||
}
|
||||
@ -3737,18 +3737,6 @@ fn init_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
|
||||
ret alt::bind_irrefutable_pat(bcx, local.node.pat, llptr, false);
|
||||
}
|
||||
|
||||
fn init_ref_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
|
||||
let init_expr = option::get(local.node.init).expr;
|
||||
let {bcx, val, kind} = trans_lval(bcx, init_expr);
|
||||
alt kind {
|
||||
owned_imm { val = do_spill_noroot(bcx, val); }
|
||||
owned {}
|
||||
_ { bcx_tcx(bcx).sess.span_bug(local.span,
|
||||
"Someone forgot to document an invariant in init_ref_local!"); }
|
||||
}
|
||||
ret alt::bind_irrefutable_pat(bcx, local.node.pat, val, false);
|
||||
}
|
||||
|
||||
fn zero_alloca(cx: @block_ctxt, llptr: ValueRef, t: ty::t)
|
||||
-> @block_ctxt {
|
||||
let bcx = cx;
|
||||
@ -3790,12 +3778,8 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
|
||||
ast::stmt_decl(d, _) {
|
||||
alt d.node {
|
||||
ast::decl_local(locals) {
|
||||
for (style, local) in locals {
|
||||
if style == ast::let_copy {
|
||||
bcx = init_local(bcx, local);
|
||||
} else {
|
||||
bcx = init_ref_local(bcx, local);
|
||||
}
|
||||
for local in locals {
|
||||
bcx = init_local(bcx, local);
|
||||
if bcx_ccx(cx).sess.opts.extra_debuginfo {
|
||||
debuginfo::create_local_var(bcx, local);
|
||||
}
|
||||
@ -3924,9 +3908,7 @@ fn block_locals(b: ast::blk, it: fn(@ast::local)) {
|
||||
ast::stmt_decl(d, _) {
|
||||
alt d.node {
|
||||
ast::decl_local(locals) {
|
||||
for (style, local) in locals {
|
||||
if style == ast::let_copy { it(local); }
|
||||
}
|
||||
for local in locals { it(local); }
|
||||
}
|
||||
_ {/* fall through */ }
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ fn expr_to_constr_arg(tcx: ty::ctxt, e: @expr) -> @constr_arg_use {
|
||||
alt e.node {
|
||||
expr_path(p) {
|
||||
alt tcx.def_map.find(e.id) {
|
||||
some(def_local(id, _)) | some(def_arg(id, _)) |
|
||||
some(def_local(id)) | some(def_arg(id, _)) |
|
||||
some(def_binding(id)) | some(def_upvar(id, _, _)) {
|
||||
ret @respan(p.span,
|
||||
carg_ident({ident: p.node.idents[0], node: id.node}));
|
||||
@ -786,7 +786,7 @@ enum if_ty { if_check, plain_if, }
|
||||
fn local_node_id_to_def_id_strict(fcx: fn_ctxt, sp: span, i: node_id) ->
|
||||
def_id {
|
||||
alt local_node_id_to_def(fcx, i) {
|
||||
some(def_local(id, _)) | some(def_arg(id, _)) |
|
||||
some(def_local(id)) | some(def_arg(id, _)) |
|
||||
some(def_upvar(id, _, _)) {
|
||||
ret id;
|
||||
}
|
||||
@ -810,7 +810,7 @@ fn local_node_id_to_def(fcx: fn_ctxt, i: node_id) -> option<def> {
|
||||
|
||||
fn local_node_id_to_def_id(fcx: fn_ctxt, i: node_id) -> option<def_id> {
|
||||
alt local_node_id_to_def(fcx, i) {
|
||||
some(def_local(id, _)) | some(def_arg(id, _)) | some(def_binding(id)) |
|
||||
some(def_local(id)) | some(def_arg(id, _)) | some(def_binding(id)) |
|
||||
some(def_upvar(id, _, _)) {
|
||||
some(id)
|
||||
}
|
||||
@ -1062,10 +1062,9 @@ fn local_to_bindings(tcx: ty::ctxt, loc: @local) -> binding {
|
||||
{lhs: lhs, rhs: loc.node.init}
|
||||
}
|
||||
|
||||
fn locals_to_bindings(tcx: ty::ctxt,
|
||||
locals: [(let_style, @local)]) -> [binding] {
|
||||
fn locals_to_bindings(tcx: ty::ctxt, locals: [@local]) -> [binding] {
|
||||
let rslt = [];
|
||||
for (_, loc) in locals { rslt += [local_to_bindings(tcx, loc)]; }
|
||||
for loc in locals { rslt += [local_to_bindings(tcx, loc)]; }
|
||||
ret rslt;
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ fn clear_in_poststate_expr(fcx: fn_ctxt, e: @expr, t: poststate) {
|
||||
alt vec::last(p.node.idents) {
|
||||
some(i) {
|
||||
alt local_node_id_to_def(fcx, e.id) {
|
||||
some(def_local(d_id, _)) {
|
||||
some(def_local(d_id)) {
|
||||
clear_in_poststate_(bit_num(fcx, ninit(d_id.node, i)), t);
|
||||
}
|
||||
some(_) {/* ignore args (for now...) */ }
|
||||
|
@ -176,7 +176,7 @@ fn gen_if_local(fcx: fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id,
|
||||
alt node_id_to_def(fcx.ccx, new_var) {
|
||||
some(d) {
|
||||
alt d {
|
||||
def_local(d_id, _) {
|
||||
def_local(d_id) {
|
||||
find_pre_post_expr(fcx, rhs);
|
||||
let p = expr_pp(fcx.ccx, rhs);
|
||||
set_pre_and_post(fcx.ccx, larger_id, p.precondition,
|
||||
@ -214,7 +214,7 @@ fn handle_update(fcx: fn_ctxt, parent: @expr, lhs: @expr, rhs: @expr,
|
||||
// pure and assign_op require the lhs to be init'd
|
||||
let df = node_id_to_def_strict(fcx.ccx.tcx, lhs.id);
|
||||
alt df {
|
||||
def_local(d_id, _) {
|
||||
def_local(d_id) {
|
||||
let i =
|
||||
bit_num(fcx,
|
||||
ninit(d_id.node, path_to_ident(p)));
|
||||
@ -261,7 +261,7 @@ fn handle_var(fcx: fn_ctxt, rslt: pre_and_post, id: node_id, name: ident) {
|
||||
fn handle_var_def(fcx: fn_ctxt, rslt: pre_and_post, def: def, name: ident) {
|
||||
log(debug, ("handle_var_def: ", def, name));
|
||||
alt def {
|
||||
def_local(d_id, _) | def_arg(d_id, _) {
|
||||
def_local(d_id) | def_arg(d_id, _) {
|
||||
use_var(fcx, d_id.node);
|
||||
let i = bit_num(fcx, ninit(d_id.node, name));
|
||||
require_and_preserve(i, rslt);
|
||||
@ -545,7 +545,7 @@ fn find_pre_post_stmt(fcx: fn_ctxt, s: stmt) {
|
||||
decl_local(alocals) {
|
||||
let e_pp;
|
||||
let prev_pp = empty_pre_post(num_constraints(fcx.enclosing));
|
||||
for (_, alocal) in alocals {
|
||||
for alocal in alocals {
|
||||
alt alocal.node.init {
|
||||
some(an_init) {
|
||||
/* LHS always becomes initialized,
|
||||
|
@ -247,7 +247,7 @@ fn gen_if_local(fcx: fn_ctxt, p: poststate, e: @expr) -> bool {
|
||||
alt e.node {
|
||||
expr_path(pth) {
|
||||
alt fcx.ccx.tcx.def_map.find(e.id) {
|
||||
some(def_local(loc, _)) {
|
||||
some(def_local(loc)) {
|
||||
ret set_in_poststate_ident(fcx, loc.node,
|
||||
path_to_ident(pth), p);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
|
||||
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
|
||||
ret {bounds: @[], ty: typ};
|
||||
}
|
||||
ast::def_local(id, _) {
|
||||
ast::def_local(id) {
|
||||
assert (fcx.locals.contains_key(id.node));
|
||||
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
|
||||
ret {bounds: @[], ty: typ};
|
||||
@ -2526,7 +2526,7 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
|
||||
node_id = id;
|
||||
alt decl.node {
|
||||
ast::decl_local(ls) {
|
||||
for (_, l) in ls { bot |= check_decl_local(fcx, l); }
|
||||
for l in ls { bot |= check_decl_local(fcx, l); }
|
||||
}
|
||||
ast::decl_item(_) {/* ignore for now */ }
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ enum def {
|
||||
def_native_mod(def_id),
|
||||
def_const(def_id),
|
||||
def_arg(def_id, mode),
|
||||
def_local(def_id, let_style),
|
||||
def_local(def_id),
|
||||
def_variant(def_id /* enum */, def_id /* variant */),
|
||||
def_ty(def_id),
|
||||
def_prim_ty(prim_ty),
|
||||
@ -201,9 +201,7 @@ type local = spanned<local_>;
|
||||
|
||||
type decl = spanned<decl_>;
|
||||
|
||||
enum let_style { let_copy, let_ref, }
|
||||
|
||||
enum decl_ { decl_local([(let_style, @local)]), decl_item(@item), }
|
||||
enum decl_ { decl_local([@local]), decl_item(@item), }
|
||||
|
||||
type arm = {pats: [@pat], guard: option<@expr>, body: blk};
|
||||
|
||||
|
@ -28,7 +28,7 @@ fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
|
||||
fn def_id_of_def(d: def) -> def_id {
|
||||
alt d {
|
||||
def_fn(id, _) | def_self(id) | def_mod(id) |
|
||||
def_native_mod(id) | def_const(id) | def_arg(id, _) | def_local(id, _) |
|
||||
def_native_mod(id) | def_const(id) | def_arg(id, _) | def_local(id) |
|
||||
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
|
||||
def_binding(id) | def_use(id) | def_upvar(id, _, _) |
|
||||
def_class(id) | def_class_field(_, id) | def_class_method(_, id) { id }
|
||||
|
@ -320,13 +320,10 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
||||
}
|
||||
|
||||
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
|
||||
ret alt d {
|
||||
decl_local(ls) {
|
||||
decl_local(vec::map(ls, {|l| let (st, lc) = l;
|
||||
(st, fld.fold_local(lc))}))
|
||||
}
|
||||
decl_item(it) { decl_item(fld.fold_item(it)) }
|
||||
}
|
||||
alt d {
|
||||
decl_local(ls) { decl_local(vec::map(ls, fld.fold_local)) }
|
||||
decl_item(it) { decl_item(fld.fold_item(it)) }
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap<T>(f: fn@(T, ast_fold) -> T)
|
||||
|
@ -1511,18 +1511,12 @@ fn parse_pat(p: parser) -> @ast::pat {
|
||||
}
|
||||
} else if is_plain_ident(p) &&
|
||||
alt p.look_ahead(1u) {
|
||||
token::LPAREN | token::LBRACKET |
|
||||
token::LT {
|
||||
false
|
||||
}
|
||||
token::LPAREN | token::LBRACKET | token::LT { false }
|
||||
_ { true }
|
||||
} {
|
||||
let name = parse_path(p);
|
||||
let sub = if eat(p, token::AT) {
|
||||
some(parse_pat(p))
|
||||
} else {
|
||||
none
|
||||
};
|
||||
let sub = if eat(p, token::AT) { some(parse_pat(p)) }
|
||||
else { none };
|
||||
pat = ast::pat_ident(name, sub);
|
||||
} else {
|
||||
let enum_path = parse_path_and_ty_param_substs(p, true);
|
||||
@ -1563,17 +1557,10 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local {
|
||||
}
|
||||
|
||||
fn parse_let(p: parser) -> @ast::decl {
|
||||
fn parse_let_style(p: parser) -> ast::let_style {
|
||||
if eat(p, token::BINOP(token::AND)) {
|
||||
ast::let_ref
|
||||
} else {
|
||||
ast::let_copy
|
||||
}
|
||||
}
|
||||
let lo = p.span.lo;
|
||||
let locals = [(parse_let_style(p), parse_local(p, true))];
|
||||
let locals = [parse_local(p, true)];
|
||||
while eat(p, token::COMMA) {
|
||||
locals += [(parse_let_style(p), parse_local(p, true))];
|
||||
locals += [parse_local(p, true)];
|
||||
}
|
||||
ret @spanned(lo, p.last_span.hi, ast::decl_local(locals));
|
||||
}
|
||||
|
@ -1082,10 +1082,8 @@ fn print_decl(s: ps, decl: @ast::decl) {
|
||||
space_if_not_bol(s);
|
||||
ibox(s, indent_unit);
|
||||
word_nbsp(s, "let");
|
||||
fn print_local(s: ps, loc_st: (ast::let_style, @ast::local)) {
|
||||
let (st, loc) = loc_st;
|
||||
fn print_local(s: ps, &&loc: @ast::local) {
|
||||
ibox(s, indent_unit);
|
||||
if st == ast::let_ref { word(s.s, "&"); }
|
||||
print_local_decl(s, loc);
|
||||
end(s);
|
||||
alt loc.node.init {
|
||||
|
@ -276,7 +276,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
|
||||
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
|
||||
alt d.node {
|
||||
decl_local(locs) {
|
||||
for (_, loc) in locs { v.visit_local(loc, e, v); }
|
||||
for loc in locs { v.visit_local(loc, e, v); }
|
||||
}
|
||||
decl_item(it) { v.visit_item(it, e, v); }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user