diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-02-17 22:20:36 -0800 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-02-25 07:49:34 -0800 |
| commit | f14409c528125836a5cbe9d4d7a39b8d6695f7b1 (patch) | |
| tree | 7953b69703588cb654de1445d9f2cfad377dc23c | |
| parent | 9ac5262bdf27c964d1e9496479994aff2ae80acc (diff) | |
libsyntax: progress on making syntax::visit vecs_implicitly_copyable-free
41 files changed, 1061 insertions, 922 deletions
diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index a9ddfe81404..1887b83ebeb 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -134,7 +134,7 @@ pub pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool { pub fn safe_to_steal_ty(t: @ast::Ty, tm: test_mode) -> bool { // Restrictions happen to be the same. - safe_to_replace_ty(t.node, tm) + safe_to_replace_ty(&t.node, tm) } // Not type-parameterized: https://github.com/mozilla/rust/issues/898 (FIXED) @@ -175,8 +175,8 @@ pub fn steal(crate: ast::crate, tm: test_mode) -> StolenStuff { } -pub fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool { - match e { +pub fn safe_to_replace_expr(e: &ast::expr_, _tm: test_mode) -> bool { + match *e { // https://github.com/mozilla/rust/issues/652 ast::expr_if(*) => { false } ast::expr_block(_) => { false } @@ -188,8 +188,8 @@ pub fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool { } } -pub fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool { - match t { +pub fn safe_to_replace_ty(t: &ast::ty_, _tm: test_mode) -> bool { + match *t { ast::ty_infer => { false } // always implicit, always top level ast::ty_bot => { false } // in source, can only appear // as the out type of a function @@ -204,7 +204,7 @@ pub fn replace_expr_in_crate(crate: ast::crate, i: uint, ast::crate { let j: @mut uint = @mut 0u; fn fold_expr_rep(j_: @mut uint, i_: uint, newexpr_: ast::expr_, - original: ast::expr_, fld: fold::ast_fold, + original: &ast::expr_, fld: fold::ast_fold, tm_: test_mode) -> ast::expr_ { *j_ += 1u; @@ -221,7 +221,7 @@ pub fn replace_expr_in_crate(crate: ast::crate, i: uint, .. *fold::default_ast_fold() }; let af = fold::make_fold(afp); - let crate2: @ast::crate = @af.fold_crate(crate); + let crate2: @ast::crate = @af.fold_crate(&crate); *crate2 } @@ -231,7 +231,7 @@ pub fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::Ty, tm: test_mode) -> ast::crate { let j: @mut uint = @mut 0u; fn fold_ty_rep(j_: @mut uint, i_: uint, newty_: ast::ty_, - original: ast::ty_, fld: fold::ast_fold, + original: &ast::ty_, fld: fold::ast_fold, tm_: test_mode) -> ast::ty_ { *j_ += 1u; @@ -244,7 +244,7 @@ pub fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::Ty, .. *fold::default_ast_fold() }; let af = fold::make_fold(afp); - let crate2: @ast::crate = @af.fold_crate(crate); + let crate2: @ast::crate = @af.fold_crate(&crate); *crate2 } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 45bbe5d091e..61bb03dd7f9 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -396,7 +396,7 @@ pub fn pretty_print_input(sess: Session, +cfg: ast::crate_cfg, input: input, pprust::node_block(s, ref blk) => { pp::space(s.s); pprust::synth_comment( - s, ~"block " + int::to_str((*blk).node.id)); + s, ~"block " + int::to_str(blk.node.id)); } pprust::node_expr(s, expr) => { pp::space(s.s); diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index afb73a6e7c3..faa1ad9854a 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -45,7 +45,7 @@ pub fn strip_items(crate: @ast::crate, in_cfg: in_cfg_pred) .. *fold::default_ast_fold()}; let fold = fold::make_fold(precursor); - let res = @fold.fold_crate(*crate); + let res = @fold.fold_crate(&*crate); return res; } @@ -63,7 +63,7 @@ fn filter_view_item(cx: @Context, &&view_item: @ast::view_item } } -fn fold_mod(cx: @Context, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { +fn fold_mod(cx: @Context, m: &ast::_mod, fld: fold::ast_fold) -> ast::_mod { let filtered_items = m.items.filter_mapped(|a| filter_item(cx, *a)); let filtered_view_items = @@ -83,7 +83,7 @@ fn filter_foreign_item(cx: @Context, &&item: @ast::foreign_item) -> fn fold_foreign_mod( cx: @Context, - nm: ast::foreign_mod, + nm: &ast::foreign_mod, fld: fold::ast_fold ) -> ast::foreign_mod { let filtered_items = @@ -98,21 +98,21 @@ fn fold_foreign_mod( } } -fn fold_item_underscore(cx: @Context, +item: ast::item_, +fn fold_item_underscore(cx: @Context, item: &ast::item_, fld: fold::ast_fold) -> ast::item_ { - let item = match item { - ast::item_impl(a, b, c, methods) => { + let item = match *item { + ast::item_impl(ref a, b, c, ref methods) => { let methods = methods.filtered(|m| method_in_cfg(cx, *m) ); - ast::item_impl(a, b, c, methods) + ast::item_impl(/*bad*/ copy *a, b, c, methods) } ast::item_trait(ref a, ref b, ref methods) => { let methods = methods.filtered(|m| trait_method_in_cfg(cx, m) ); ast::item_trait(/*bad*/copy *a, /*bad*/copy *b, methods) } - item => item + ref item => /*bad*/ copy *item }; - fold::noop_fold_item_underscore(item, fld) + fold::noop_fold_item_underscore(&item, fld) } fn filter_stmt(cx: @Context, &&stmt: @ast::stmt) -> @@ -134,7 +134,7 @@ fn filter_stmt(cx: @Context, &&stmt: @ast::stmt) -> fn fold_block( cx: @Context, - b: ast::blk_, + b: &ast::blk_, fld: fold::ast_fold ) -> ast::blk_ { let filtered_stmts = diff --git a/src/librustc/front/core_inject.rs b/src/librustc/front/core_inject.rs index 62a2dfd880b..b7df9979592 100644 --- a/src/librustc/front/core_inject.rs +++ b/src/librustc/front/core_inject.rs @@ -66,10 +66,13 @@ fn inject_libcore_ref(sess: Session, view_items: vis, ../*bad*/copy crate.module }; - new_module = fld.fold_mod(new_module); + new_module = fld.fold_mod(&new_module); // FIXME #2543: Bad copy. - let new_crate = ast::crate_ { module: new_module, ..copy crate }; + let new_crate = ast::crate_ { + module: new_module, + ..copy *crate + }; (new_crate, span) }, fold_mod: |module, fld| { @@ -95,12 +98,15 @@ fn inject_libcore_ref(sess: Session, let vis = vec::append(~[vi2], module.view_items); // FIXME #2543: Bad copy. - let new_module = ast::_mod { view_items: vis, ..copy module }; - fold::noop_fold_mod(new_module, fld) + let new_module = ast::_mod { + view_items: vis, + ..copy *module + }; + fold::noop_fold_mod(&new_module, fld) }, ..*fold::default_ast_fold() }; let fold = fold::make_fold(precursor); - @fold.fold_crate(*crate) + @fold.fold_crate(crate) } diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index f19b52661f2..4e845d156f4 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -91,7 +91,7 @@ fn generate_test_harness(sess: session::Session, fold_mod: |a,b| fold_mod(cx, a, b),.. *fold::default_ast_fold()}; let fold = fold::make_fold(precursor); - let res = @fold.fold_crate(*crate); + let res = @fold.fold_crate(&*crate); cx.ext_cx.bt_pop(); return res; } @@ -106,7 +106,7 @@ fn strip_test_functions(crate: @ast::crate) -> @ast::crate { } fn fold_mod(cx: @mut TestCtxt, - m: ast::_mod, + m: &ast::_mod, fld: fold::ast_fold) -> ast::_mod { // Remove any #[main] from the AST so it doesn't clash with @@ -125,19 +125,21 @@ fn fold_mod(cx: @mut TestCtxt, items: vec::map(m.items, |i| nomain(cx, *i)), }; - fold::noop_fold_mod(mod_nomain, fld) + fold::noop_fold_mod(&mod_nomain, fld) } fn fold_crate(cx: @mut TestCtxt, - c: ast::crate_, + c: &ast::crate_, fld: fold::ast_fold) -> ast::crate_ { let folded = fold::noop_fold_crate(c, fld); // Add a special __test module to the crate that will contain code // generated for the test harness - ast::crate_ { module: add_test_module(cx, /*bad*/copy folded.module), - .. folded } + ast::crate_ { + module: add_test_module(cx, &folded.module), + .. folded + } } @@ -238,11 +240,11 @@ fn should_fail(i: @ast::item) -> bool { vec::len(attr::find_attrs_by_name(i.attrs, ~"should_fail")) > 0u } -fn add_test_module(cx: &TestCtxt, +m: ast::_mod) -> ast::_mod { +fn add_test_module(cx: &TestCtxt, m: &ast::_mod) -> ast::_mod { let testmod = mk_test_module(cx); ast::_mod { items: vec::append_one(/*bad*/copy m.items, testmod), - .. m + .. /*bad*/ copy *m } } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index c862a15dbc7..8324721c33a 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -323,7 +323,7 @@ fn encode_path(ecx: @EncodeContext, ebml_w: writer::Encoder, } fn encode_info_for_mod(ecx: @EncodeContext, ebml_w: writer::Encoder, - md: _mod, id: node_id, path: &[ast_map::path_elt], + md: &_mod, id: node_id, path: &[ast_map::path_elt], name: ident) { ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(id)); @@ -621,7 +621,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, } ebml_w.end_tag(); } - item_mod(m) => { + item_mod(ref m) => { add_to_index(); encode_info_for_mod(ecx, ebml_w, m, item.id, path, item.ident); } @@ -856,8 +856,8 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, // method info, we output static methods with type signatures as // written. Here, we output the *real* type signatures. I feel like // maybe we should only ever handle the real type signatures. - for vec::each((*ms)) |m| { - let ty_m = ast_util::trait_method_to_ty_method(*m); + for ms.each |m| { + let ty_m = ast_util::trait_method_to_ty_method(m); if ty_m.self_ty.node != ast::sty_static { loop; } index.push(entry { val: ty_m.id, pos: ebml_w.writer.tell() }); @@ -927,7 +927,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: writer::Encoder, let index = @mut ~[]; ebml_w.start_tag(tag_items_data); index.push(entry { val: crate_node_id, pos: ebml_w.writer.tell() }); - encode_info_for_mod(ecx, ebml_w, crate.node.module, + encode_info_for_mod(ecx, ebml_w, &crate.node.module, crate_node_id, ~[], syntax::parse::token::special_idents::invalid); visit::visit_crate(*crate, (), visit::mk_vt(@visit::Visitor { diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 0b1abd683b1..2658e5c4674 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -298,7 +298,7 @@ fn encode_ast(ebml_w: writer::Encoder, item: ast::inlined_item) { // nested items, as otherwise it would get confused when translating // inlined items. fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { - fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ { + fn drop_nested_items(blk: &ast::blk_, fld: fold::ast_fold) -> ast::blk_ { let stmts_sans_items = do blk.stmts.filtered |stmt| { match stmt.node { ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | @@ -317,7 +317,7 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { id: blk.id, rules: blk.rules }; - fold::noop_fold_block(blk_sans_items, fld) + fold::noop_fold_block(&blk_sans_items, fld) } let fld = fold::make_fold(@fold::AstFoldFns { @@ -336,7 +336,7 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { ast::ii_foreign(fld.fold_foreign_item(i)) } ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => { - let dtor_body = fld.fold_block((*dtor).node.body); + let dtor_body = fld.fold_block(&dtor.node.body); ast::ii_dtor( codemap::spanned { node: ast::struct_dtor_ { body: dtor_body, @@ -372,7 +372,7 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item) ast::ii_foreign(fld.fold_foreign_item(i)) } ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => { - let dtor_body = fld.fold_block((*dtor).node.body); + let dtor_body = fld.fold_block(&dtor.node.body); let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs); let new_params = fold::fold_ty_params(/*bad*/copy *tps, fld); let dtor_id = fld.new_id((*dtor).node.id); diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 0c043dac216..6efcc0b97c0 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -580,8 +580,8 @@ impl CheckLoanCtxt { } fn check_loans_in_fn(fk: &visit::fn_kind, - decl: ast::fn_decl, - body: ast::blk, + decl: &ast::fn_decl, + body: &ast::blk, sp: span, id: ast::node_id, &&self: @mut CheckLoanCtxt, @@ -753,7 +753,7 @@ fn check_loans_in_expr(expr: @ast::expr, visit::visit_expr(expr, self, vt); } -fn check_loans_in_block(blk: ast::blk, +fn check_loans_in_block(blk: &ast::blk, &&self: @mut CheckLoanCtxt, vt: visit::vt<@mut CheckLoanCtxt>) { do save_and_restore_managed(self.declared_purity) { diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 1b9c935cf75..eea11fa0675 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -96,8 +96,8 @@ pub fn gather_loans(bccx: @BorrowckCtxt, crate: @ast::crate) -> ReqMaps { } fn req_loans_in_fn(fk: &visit::fn_kind, - decl: ast::fn_decl, - body: ast::blk, + decl: &ast::fn_decl, + body: &ast::blk, sp: span, id: ast::node_id, &&self: @mut GatherLoanCtxt, @@ -269,13 +269,13 @@ fn req_loans_in_expr(ex: @ast::expr, (vt.visit_expr)(cond, self, vt); // during body, can only root for the body - self.root_ub = (*body).node.id; - (vt.visit_block)((*body), self, vt); + self.root_ub = body.node.id; + (vt.visit_block)(body, self, vt); } // see explanation attached to the `root_ub` field: ast::expr_loop(ref body, _) => { - self.root_ub = (*body).node.id; + self.root_ub = body.node.id; visit::visit_expr(ex, self, vt); } diff --git a/src/librustc/middle/check_loop.rs b/src/librustc/middle/check_loop.rs index 34665fe7b7d..15f64b0fa2f 100644 --- a/src/librustc/middle/check_loop.rs +++ b/src/librustc/middle/check_loop.rs @@ -33,10 +33,10 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) { match e.node { expr_while(e, ref b) => { (v.visit_expr)(e, cx, v); - (v.visit_block)((*b), Context { in_loop: true,.. cx }, v); + (v.visit_block)(b, Context { in_loop: true,.. cx }, v); } expr_loop(ref b, _) => { - (v.visit_block)((*b), Context { in_loop: true,.. cx }, v); + (v.visit_block)(b, Context { in_loop: true,.. cx }, v); } expr_fn(*) => { visit::visit_expr(e, Context { @@ -45,7 +45,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) { }, v); } expr_fn_block(_, ref b) => { - (v.visit_block)((*b), Context { + (v.visit_block)(b, Context { in_loop: false, can_ret: false }, v); @@ -53,10 +53,10 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) { expr_loop_body(@expr {node: expr_fn_block(_, ref b), _}) => { let sigil = ty::ty_closure_sigil(ty::expr_ty(tcx, e)); let blk = (sigil == BorrowedSigil); - (v.visit_block)((*b), Context { + (v.visit_block)(b, Context { in_loop: true, can_ret: blk - }, v); + }, v); } expr_break(_) => { if !cx.in_loop { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index ce44ef9c071..8666ae0fa44 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -670,8 +670,8 @@ pub fn check_local(cx: @MatchCheckCtxt, pub fn check_fn(cx: @MatchCheckCtxt, kind: &visit::fn_kind, - decl: fn_decl, - body: blk, + decl: &fn_decl, + body: &blk, sp: span, id: node_id, &&s: (), diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 81c4b1ae70c..f69e0e2d454 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -39,7 +39,7 @@ pub type freevar_map = HashMap<ast::node_id, freevar_info>; // Since we want to be able to collect upvars in some arbitrary piece // of the AST, we take a walker function that we invoke with a visitor // in order to start the search. -fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk) +fn collect_freevars(def_map: resolve::DefMap, blk: &ast::blk) -> freevar_info { let seen = HashMap(); let refs = @mut ~[]; @@ -100,8 +100,8 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) -> freevar_map { let freevars = HashMap(); - let walk_fn = fn@(_fk: &visit::fn_kind, _decl: ast::fn_decl, - blk: ast::blk, _sp: span, nid: ast::node_id) { + let walk_fn = fn@(_fk: &visit::fn_kind, _decl: &ast::fn_decl, + blk: &ast::blk, _sp: span, nid: ast::node_id) { let vars = collect_freevars(def_map, blk); freevars.insert(nid, vars); }; diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 2d87f041979..1b1e9afa924 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -153,8 +153,14 @@ fn with_appropriate_checker(cx: Context, id: node_id, b: fn(check_fn)) { // Check that the free variables used in a shared/sendable closure conform // to the copy/move kind bounds. Then recursively check the function body. -fn check_fn(fk: &visit::fn_kind, decl: fn_decl, body: blk, sp: span, - fn_id: node_id, cx: Context, v: visit::vt<Context>) { +fn check_fn( + fk: &visit::fn_kind, + decl: &fn_decl, + body: &blk, + sp: span, + fn_id: node_id, + cx: Context, + v: visit::vt<Context>) { // Check kinds on free variables: do with_appropriate_checker(cx, fn_id) |chk| { @@ -166,7 +172,7 @@ fn check_fn(fk: &visit::fn_kind, decl: fn_decl, body: blk, sp: span, visit::visit_fn(fk, decl, body, sp, fn_id, cx, v); } -fn check_arm(a: arm, cx: Context, v: visit::vt<Context>) { +fn check_arm(a: &arm, cx: Context, v: visit::vt<Context>) { for vec::each(a.pats) |p| { do pat_util::pat_bindings(cx.tcx.def_map, *p) |mode, id, span, _pth| { if mode == bind_by_copy { diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 95be98be776..c69bba8c25d 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -726,7 +726,7 @@ fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) { fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, - decl: ast::fn_decl) { + decl: &ast::fn_decl) { let tys = vec::map(decl.inputs, |a| a.ty ); for vec::each(vec::append_one(tys, decl.output)) |ty| { match ty.node { @@ -760,7 +760,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { either::Right(ast::foreign_abi_rust_intrinsic) => { for nmod.items.each |ni| { match /*bad*/copy ni.node { - ast::foreign_item_fn(decl, _, _) => { + ast::foreign_item_fn(ref decl, _, _) => { check_foreign_fn(cx, it.id, decl); } // FIXME #4622: Not implemented. @@ -923,8 +923,8 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) { } } -fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: ast::fn_decl, - _body: ast::blk, span: span, id: ast::node_id) { +fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: &ast::fn_decl, + _body: &ast::blk, span: span, id: ast::node_id) { debug!("lint check_fn fk=%? id=%?", fk, id); // don't complain about blocks, since they tend to get their modes @@ -938,7 +938,7 @@ fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: ast::fn_decl, check_fn_deprecated_modes(tcx, fn_ty, decl, span, id); } -fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl, +fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: &ast::fn_decl, span: span, id: ast::node_id) { match ty::get(fn_ty).sty { ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) | @@ -990,7 +990,7 @@ fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl, ast::ty_closure(@ast::TyClosure{decl: ref d, _}) | ast::ty_bare_fn(@ast::TyBareFn{decl: ref d, _})=>{ check_fn_deprecated_modes(tcx, arg_ty.ty, - *d, span, id); + d, span, id); } ast::ty_path(*) => { // This is probably a typedef, so we can't @@ -1026,7 +1026,7 @@ fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) { ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => { let fn_ty = ty::node_id_to_type(tcx, it.id); check_fn_deprecated_modes( - tcx, fn_ty, *decl, ty.span, it.id) + tcx, fn_ty, decl, ty.span, it.id) } _ => () } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 739882258b2..e6c8a3f1aa5 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -436,8 +436,8 @@ impl IrMaps { } fn visit_fn(fk: &visit::fn_kind, - decl: fn_decl, - body: blk, + decl: &fn_decl, + body: &blk, sp: span, id: node_id, &&self: @mut IrMaps, @@ -540,7 +540,7 @@ fn visit_local(local: @local, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) { visit::visit_local(local, self, vt); } -fn visit_arm(arm: arm, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) { +fn visit_arm(arm: &arm, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) { let def_map = self.tcx.def_map; for arm.pats.each |pat| { do pat_util::pat_bindings(def_map, *pat) |bm, p_id, sp, path| { @@ -979,7 +979,7 @@ impl Liveness { // _______________________________________________________________________ - fn compute(&self, decl: fn_decl, body: blk) -> LiveNode { + fn compute(&self, decl: &fn_decl, body: &blk) -> LiveNode { // if there is a `break` or `again` at the top level, then it's // effectively a return---this only occurs in `for` loops, // where the body is really a closure. @@ -1004,7 +1004,7 @@ impl Liveness { entry_ln } - fn propagate_through_fn_block(&self, decl: fn_decl, blk: blk) + fn propagate_through_fn_block(&self, decl: &fn_decl, blk: &blk) -> LiveNode { // inputs passed by & mode should be considered live on exit: for decl.inputs.each |arg| { @@ -1038,7 +1038,7 @@ impl Liveness { self.propagate_through_block(blk, self.s.fallthrough_ln) } - fn propagate_through_block(&self, blk: blk, succ: LiveNode) -> LiveNode { + fn propagate_through_block(&self, blk: &blk, succ: LiveNode) -> LiveNode { let succ = self.propagate_through_opt_expr(blk.node.expr, succ); do blk.node.stmts.foldr(succ) |stmt, succ| { self.propagate_through_stmt(*stmt, succ) @@ -1134,7 +1134,7 @@ impl Liveness { The next-node for a break is the successor of the entire loop. The next-node for a continue is the top of this loop. */ - self.with_loop_nodes((*blk).node.id, succ, + self.with_loop_nodes(blk.node.id, succ, self.live_node(expr.id, expr.span), || { // the construction of a closure itself is not important, @@ -1164,7 +1164,7 @@ impl Liveness { // ( succ ) // let else_ln = self.propagate_through_opt_expr(els, succ); - let then_ln = self.propagate_through_block((*then), succ); + let then_ln = self.propagate_through_block(then, succ); let ln = self.live_node(expr.id, expr.span); self.init_from_succ(ln, else_ln); self.merge_from_succ(ln, then_ln, false); @@ -1172,13 +1172,13 @@ impl Liveness { } expr_while(cond, ref blk) => { - self.propagate_through_loop(expr, Some(cond), (*blk), succ) + self.propagate_through_loop(expr, Some(cond), blk, succ) } // Note that labels have been resolved, so we don't need to look // at the label ident expr_loop(ref blk, _) => { - self.propagate_through_loop(expr, None, (*blk), succ) + self.propagate_through_loop(expr, None, blk, succ) } expr_match(e, ref arms) => { @@ -1199,9 +1199,9 @@ impl Liveness { let ln = self.live_node(expr.id, expr.span); self.init_empty(ln, succ); let mut first_merge = true; - for (*arms).each |arm| { + for arms.each |arm| { let body_succ = - self.propagate_through_block(arm.body, succ); + self.propagate_through_block(&arm.body, succ); let guard_succ = self.propagate_through_opt_expr(arm.guard, body_succ); let arm_succ = @@ -1362,7 +1362,7 @@ impl Liveness { } expr_block(ref blk) => { - self.propagate_through_block((*blk), succ) + self.propagate_through_block(blk, succ) } expr_mac(*) => { @@ -1463,7 +1463,7 @@ impl Liveness { fn propagate_through_loop(&self, expr: @expr, cond: Option<@expr>, - body: blk, + body: &blk, succ: LiveNode) -> LiveNode { /* @@ -1568,7 +1568,7 @@ fn check_local(local: @local, &&self: @Liveness, vt: vt<@Liveness>) { visit::visit_local(local, self, vt); } -fn check_arm(arm: arm, &&self: @Liveness, vt: vt<@Liveness>) { +fn check_arm(arm: &arm, &&self: @Liveness, vt: vt<@Liveness>) { do self.arm_pats_bindings(arm.pats) |ln, var, sp| { self.warn_about_unused(sp, ln, var); } @@ -1639,8 +1639,8 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { } } -fn check_fn(_fk: &visit::fn_kind, _decl: fn_decl, - _body: blk, _sp: span, _id: node_id, +fn check_fn(_fk: &visit::fn_kind, _decl: &fn_decl, + _body: &blk, _sp: span, _id: node_id, &&_self: @Liveness, _v: vt<@Liveness>) { // do not check contents of nested fns } @@ -1885,7 +1885,7 @@ impl @Liveness { if name[0] == ('_' as u8) { None } else { Some(name) } } - fn warn_about_unused_args(&self, decl: fn_decl, entry_ln: LiveNode) { + fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) { for decl.inputs.each |arg| { do pat_util::pat_bindings(self.tcx.def_map, arg.pat) |_bm, p_id, sp, _n| { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 7782a58356b..74f485d08af 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -221,7 +221,7 @@ pub fn record_parent(cx: ctxt, child_id: ast::node_id) { } } -pub fn resolve_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) { +pub fn resolve_block(blk: &ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) { // Record the parent of this block. record_parent(cx, blk.node.id); @@ -230,7 +230,7 @@ pub fn resolve_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) { visit::visit_block(blk, new_cx, visitor); } -pub fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) { +pub fn resolve_arm(arm: &ast::arm, cx: ctxt, visitor: visit::vt<ctxt>) { visit::visit_arm(arm, cx, visitor); } @@ -317,8 +317,8 @@ pub fn resolve_item(item: @ast::item, cx: ctxt, visitor: visit::vt<ctxt>) { } pub fn resolve_fn(fk: &visit::fn_kind, - decl: ast::fn_decl, - body: ast::blk, + decl: &ast::fn_decl, + body: &ast::blk, sp: span, id: ast::node_id, cx: ctxt, @@ -608,8 +608,8 @@ pub fn determine_rp_in_item(item: @ast::item, } pub fn determine_rp_in_fn(fk: &visit::fn_kind, - decl: ast::fn_decl, - body: ast::blk, + decl: &ast::fn_decl, + body: &ast::blk, _: span, _: ast::node_id, &&cx: @mut DetermineRpCtxt, @@ -626,7 +626,7 @@ pub fn determine_rp_in_fn(fk: &visit::fn_kind, } } -pub fn determine_rp_in_ty_method(ty_m: ast::ty_method, +pub fn determine_rp_in_ty_method(ty_m: &ast::ty_method, &&cx: @mut DetermineRpCtxt, visitor: visit::vt<@mut DetermineRpCtxt>) { do cx.with(cx.item_id, false) { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index afcc0298a95..cff6603cf05 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1027,7 +1027,7 @@ pub impl Resolver { } } - fn block_needs_anonymous_module(@mut self, block: blk) -> bool { + fn block_needs_anonymous_module(@mut self, block: &blk) -> bool { // If the block has view items, we need an anonymous module. if block.node.view_items.len() > 0 { return true; @@ -1276,7 +1276,7 @@ pub impl Resolver { // methods, so check that first. let mut has_static_methods = false; for (*methods).each |method| { - let ty_m = trait_method_to_ty_method(*method); + let ty_m = trait_method_to_ty_method(method); match ty_m.self_ty.node { sty_static => { has_static_methods = true; @@ -1304,7 +1304,7 @@ pub impl Resolver { // Add the names of all the methods to the trait info. let method_names = @HashMap(); for (*methods).each |method| { - let ty_m = trait_method_to_ty_method(*method); + let ty_m = trait_method_to_ty_method(method); let ident = ty_m.ident; // Add it to the trait info if not static, @@ -1534,7 +1534,7 @@ pub impl Resolver { } fn build_reduced_graph_for_block(@mut self, - block: blk, + block: &blk, parent: ReducedGraphParent, &&visitor: vt<ReducedGraphParent>) { let mut new_parent; @@ -3788,7 +3788,7 @@ pub impl Resolver { item.id, 0, OpaqueFunctionRibKind), - (*block), + block, NoSelfBinding, visitor); } @@ -3866,7 +3866,7 @@ pub impl Resolver { rib_kind: RibKind, optional_declaration: Option<@fn_decl>, type_parameters: TypeParameters, - block: blk, + block: &blk, self_binding: SelfBinding, visitor: ResolveVisitor) { // Create a value rib for the function. @@ -3982,7 +3982,7 @@ pub impl Resolver { self.resolve_function(NormalRibKind, None, NoTypeParameters, - (*destructor).node.body, + &destructor.node.body, HasSelfBinding ((*destructor).node.self_id, true), @@ -4015,7 +4015,7 @@ pub impl Resolver { self.resolve_function(rib_kind, Some(@/*bad*/copy method.decl), type_parameters, - method.body, + &method.body, self_binding, visitor); } @@ -4140,7 +4140,7 @@ pub impl Resolver { return result; } - fn check_consistent_bindings(@mut self, arm: arm) { + fn check_consistent_bindings(@mut self, arm: &arm) { if arm.pats.len() == 0 { return; } let map_0 = self.binding_mode_map(arm.pats[0]); for arm.pats.eachi() |i, p| { @@ -4179,7 +4179,7 @@ pub impl Resolver { } } - fn resolve_arm(@mut self, arm: arm, visitor: ResolveVisitor) { + fn resolve_arm(@mut self, arm: &arm, visitor: ResolveVisitor) { (*self.value_ribs).push(@Rib(NormalRibKind)); let bindings_list = HashMap(); @@ -4193,12 +4193,12 @@ pub impl Resolver { self.check_consistent_bindings(arm); visit_expr_opt(arm.guard, (), visitor); - self.resolve_block(arm.body, visitor); + self.resolve_block(&arm.body, visitor); (*self.value_ribs).pop(); } - fn resolve_block(@mut self, block: blk, visitor: ResolveVisitor) { + fn resolve_block(@mut self, block: &blk, visitor: ResolveVisitor) { debug!("(resolving block) entering block"); (*self.value_ribs).push(@Rib(NormalRibKind)); @@ -4910,7 +4910,7 @@ pub impl Resolver { self.resolve_function(FunctionRibKind(expr.id, block.node.id), Some(@/*bad*/copy *fn_decl), NoTypeParameters, - (*block), + block, NoSelfBinding, visitor); } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 9723e2cda26..d2896216459 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2093,7 +2093,7 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) { vec::append(/*bad*/copy *path, ~[path_name(item.ident)]), decl, body, llfndecl, no_self, None, item.id, None); } else { - for vec::each((*body).node.stmts) |stmt| { + for body.node.stmts.each |stmt| { match stmt.node { ast::stmt_decl(@codemap::spanned { node: ast::decl_item(i), _ }, _) => { @@ -2108,7 +2108,7 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) { meth::trans_impl(ccx, /*bad*/copy *path, item.ident, ms, tps, None, item.id); } - ast::item_mod(m) => { + ast::item_mod(ref m) => { trans_mod(ccx, m); } ast::item_enum(ref enum_definition, ref tps) => { @@ -2121,11 +2121,10 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) { } } ast::item_const(_, expr) => consts::trans_const(ccx, expr, item.id), - ast::item_foreign_mod(foreign_mod) => { + ast::item_foreign_mod(ref foreign_mod) => { let abi = match attr::foreign_abi(item.attrs) { - either::Right(abi_) => abi_, - either::Left(ref msg) => ccx.sess.span_fatal(item.span, - /*bad*/copy *msg) + Right(abi_) => abi_, + Left(ref msg) => ccx.sess.span_fatal(item.span, /*bad*/copy *msg) }; foreign::trans_foreign_mod(ccx, foreign_mod, abi); } @@ -2165,9 +2164,9 @@ pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def, // separate modules in the compiled program. That's because modules exist // only as a convenience for humans working with the code, to organize names // and control visibility. -pub fn trans_mod(ccx: @CrateContext, m: ast::_mod) { +pub fn trans_mod(ccx: @CrateContext, m: &ast::_mod) { let _icx = ccx.insn_ctxt("trans_mod"); - for vec::each(m.items) |item| { + for m.items.each |item| { trans_item(ccx, **item); } } @@ -3130,7 +3129,7 @@ pub fn trans_crate(sess: session::Session, { let _icx = ccx.insn_ctxt("text"); - trans_mod(ccx, crate.node.module); + trans_mod(ccx, &crate.node.module); } decl_gc_metadata(ccx, llmod_id); diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index c1dac70ae97..3782bb9c3fd 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -390,7 +390,7 @@ pub fn trans_rtcall_or_lang_call_with_type_params(bcx: block, ArgVals(args), dest, DontAutorefArg); } -pub fn body_contains_ret(body: ast::blk) -> bool { +pub fn body_contains_ret(body: &ast::blk) -> bool { let cx = @mut false; visit::visit_block(body, cx, visit::mk_vt(@visit::Visitor { visit_item: |_i, _cx, _v| { }, @@ -424,7 +424,7 @@ pub fn trans_call_inner( ast::expr_loop_body(@ast::expr { node: ast::expr_fn_block(_, ref body), _ - }) => body_contains_ret((*body)), + }) => body_contains_ret(body), _ => false } } diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 3d1d70abefd..b0a2539b81e 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -202,7 +202,7 @@ fn build_wrap_fn_(ccx: @CrateContext, // function itself is unnecessary). We used to do this, in fact, and will // perhaps do so in the future. pub fn trans_foreign_mod(ccx: @CrateContext, - foreign_mod: ast::foreign_mod, + foreign_mod: &ast::foreign_mod, abi: ast::foreign_abi) { let _icx = ccx.insn_ctxt("foreign::trans_foreign_mod"); diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 02ea29f915d..825dcbb44d2 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -310,7 +310,7 @@ pub fn trans_static_method_callee(bcx: block, let mname = if method_id.crate == ast::local_crate { match bcx.tcx().items.get(&method_id.node) { ast_map::node_trait_method(trait_method, _, _) => { - ast_util::trait_method_to_ty_method(*trait_method).ident + ast_util::trait_method_to_ty_method(trait_method).ident } _ => fail!(~"callee is not a trait method") } diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index b917021add2..ac2abcac1e2 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -109,7 +109,7 @@ fn traverse_public_item(cx: ctx, item: @item) { item_fn(_, _, ref tps, ref blk) => { if tps.len() > 0u || attr::find_inline_attr(item.attrs) != attr::ia_none { - traverse_inline_body(cx, (*blk)); + traverse_inline_body(cx, blk); } } item_impl(tps, _, _, ms) => { @@ -117,7 +117,7 @@ fn traverse_public_item(cx: ctx, item: @item) { if tps.len() > 0u || m.tps.len() > 0u || attr::find_inline_attr(m.attrs) != attr::ia_none { cx.rmap.insert(m.id, ()); - traverse_inline_body(cx, m.body); + traverse_inline_body(cx, &m.body); } } } @@ -129,7 +129,7 @@ fn traverse_public_item(cx: ctx, item: @item) { cx.rmap.insert(dtor.node.id, ()); if tps.len() > 0u || attr::find_inline_attr(dtor.node.attrs) != attr::ia_none { - traverse_inline_body(cx, dtor.node.body); + traverse_inline_body(cx, &dtor.node.body); } } } @@ -168,7 +168,7 @@ fn traverse_ty(ty: @Ty, cx: ctx, v: visit::vt<ctx>) { } } -fn traverse_inline_body(cx: ctx, body: blk) { +fn traverse_inline_body(cx: ctx, body: &blk) { fn traverse_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) { match e.node { expr_path(_) => { @@ -217,7 +217,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { fn traverse_item(i: @item, cx: ctx, _v: visit::vt<ctx>) { traverse_public_item(cx, i); } - visit::visit_block(body, cx, visit::mk_vt(@visit::Visitor { + visit::visit_block(body, cx, visit::mk_vt(@visit::Visitor { visit_expr: traverse_expr, visit_item: traverse_item, ..*visit::default_visitor() diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 3013f928b75..47762ce4574 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -103,7 +103,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) ast_map::node_item(@ast::item { node: item_fn(_, _, _, ref body), _ }, _) | ast_map::node_method(@ast::method {body: ref body, _}, _, _) => { - handle_body(cx, (*body)); + handle_body(cx, body); } ast_map::node_trait_method(*) => { // This will be a static trait method. For now, we just assume @@ -159,8 +159,8 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;} } } - ast_map::node_dtor(_, dtor, _, _) => { - handle_body(cx, dtor.node.body); + ast_map::node_dtor(_, ref dtor, _, _) => { + handle_body(cx, &dtor.node.body); } ast_map::node_struct_ctor(*) => { // Similarly to node_variant, this monomorphized function just uses @@ -359,7 +359,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) { } } -pub fn handle_body(cx: Context, body: blk) { +pub fn handle_body(cx: Context, body: &blk) { let v = visit::mk_vt(@visit::Visitor { visit_expr: |e, cx, v| { visit::visit_expr(e, cx, v); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 239e86623ca..3dedd169c85 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3850,7 +3850,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { ast_map::path_name(method.ident)) } ast_map::node_trait_method(trait_method, _, path) => { - let method = ast_util::trait_method_to_ty_method(*trait_method); + let method = ast_util::trait_method_to_ty_method(&*trait_method); vec::append_one(/*bad*/copy *path, ast_map::path_name(method.ident)) } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 9269752b8ec..c026cc4845c 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -332,14 +332,14 @@ pub fn ast_ty_to_ty<AC:AstConv,RS:region_scope + Copy + Durable>( }; ty::mk_rec(tcx, flds) } - ast::ty_bare_fn(bf) => { + ast::ty_bare_fn(ref bf) => { ty::mk_bare_fn(tcx, ty_of_bare_fn(self, rscope, bf.purity, - bf.abi, bf.decl)) + bf.abi, &bf.decl)) } - ast::ty_closure(f) => { + ast::ty_closure(ref f) => { let fn_decl = ty_of_closure(self, rscope, f.sigil, f.purity, f.onceness, - f.region, f.decl, None, + f.region, &f.decl, None, ast_ty.span); ty::mk_closure(tcx, fn_decl) } @@ -473,7 +473,7 @@ pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>( rscope: RS, purity: ast::purity, abi: ast::Abi, - decl: ast::fn_decl) + decl: &ast::fn_decl) -> ty::BareFnTy { debug!("ty_of_fn_decl"); @@ -501,7 +501,7 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>( purity: ast::purity, onceness: ast::Onceness, opt_region: Option<@ast::region>, - decl: ast::fn_decl, + decl: &ast::fn_decl, expected_tys: Option<ty::FnSig>, span: span) -> ty::ClosureTy { diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 82f9828db3f..8c39beac6bb 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -58,7 +58,7 @@ pub fn check_match(fcx: @mut FnCtxt, Some(e) => { check_expr_has_type(fcx, e, ty::mk_bool(tcx)); }, None => () } - if !check_block(fcx, arm.body) { arm_non_bot = true; } + if !check_block(fcx, &arm.body) { arm_non_bot = true; } let bty = fcx.node_ty(arm.body.node.id); demand::suptype(fcx, arm.body.span, result_ty, bty); } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 9d14030d261..309a4a9b0fa 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -244,7 +244,7 @@ pub fn check_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) { pub fn check_bare_fn(ccx: @mut CrateCtxt, decl: &ast::fn_decl, - body: ast::blk, + body: &ast::blk, id: ast::node_id, self_info: Option<SelfInfo>) { let fty = ty::node_id_to_type(ccx.tcx, id); @@ -264,7 +264,7 @@ pub fn check_fn(ccx: @mut CrateCtxt, sigil: Option<ast::Sigil>, fn_sig: &ty::FnSig, decl: &ast::fn_decl, - body: ast::blk, + body: &ast::blk, fn_kind: FnKind, old_fcx: Option<@mut FnCtxt>) { let tcx = ccx.tcx; @@ -381,7 +381,7 @@ pub fn check_fn(ccx: @mut CrateCtxt, fn gather_locals(fcx: @mut FnCtxt, decl: &ast::fn_decl, - body: ast::blk, + body: &ast::blk, arg_tys: &[ty::t], self_info: Option<SelfInfo>) { let tcx = fcx.ccx.tcx; @@ -459,7 +459,7 @@ pub fn check_fn(ccx: @mut CrateCtxt, visit::visit_pat(p, e, v); }; - let visit_block = fn@(b: ast::blk, &&e: (), v: visit::vt<()>) { + let visit_block = fn@(b: &ast::blk, &&e: (), v: visit::vt<()>) { // non-obvious: the `blk` variable maps to region lb, so // we have to keep this up-to-date. This // is... unfortunate. It'd be nice to not need this. @@ -469,8 +469,8 @@ pub fn check_fn(ccx: @mut CrateCtxt, }; // Don't descend into fns and items - fn visit_fn(_fk: &visit::fn_kind, _decl: ast::fn_decl, - _body: ast::blk, _sp: span, + fn visit_fn(_fk: &visit::fn_kind, _decl: &ast::fn_decl, + _body: &ast::blk, _sp: span, _id: ast::node_id, &&_t: (), _v: visit::vt<()>) { } fn visit_item(_i: @ast::item, &&_e: (), _v: visit::vt<()>) { } @@ -497,7 +497,13 @@ pub fn check_method(ccx: @mut CrateCtxt, def_id: self_impl_def_id, explicit_self: method.self_ty }; - check_bare_fn(ccx, &method.decl, method.body, method.id, Some(self_info)); + check_bare_fn( + ccx, + &method.decl, + &method.body, + method.id, + Some(self_info) + ); } pub fn check_no_duplicate_fields(tcx: ty::ctxt, @@ -541,9 +547,13 @@ pub fn check_struct(ccx: @mut CrateCtxt, }; // typecheck the dtor let dtor_dec = ast_util::dtor_dec(); - check_bare_fn(ccx, &dtor_dec, - dtor.node.body, dtor.node.id, - Some(class_t)); + check_bare_fn( + ccx, + &dtor_dec, + &dtor.node.body, + dtor.node.id, + Some(class_t) + ); }; // Check that the class is instantiable @@ -565,7 +575,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) { it.id); } ast::item_fn(ref decl, _, _, ref body) => { - check_bare_fn(ccx, decl, (*body), it.id, None); + check_bare_fn(ccx, decl, body, it.id, None); } ast::item_impl(_, _, ty, ms) => { let rp = ccx.tcx.region_paramd_items.find(&it.id); @@ -1397,7 +1407,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, fn check_for(fcx: @mut FnCtxt, local: @ast::local, element_ty: ty::t, - body: ast::blk, + body: &ast::blk, node_id: ast::node_id) -> bool { let local_ty = fcx.local_ty(local.span, local.node.id); @@ -1411,7 +1421,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, // A generic function for checking the then and else in an if // or if-check fn check_then_else(fcx: @mut FnCtxt, - thn: ast::blk, + thn: &ast::blk, elsopt: Option<@ast::expr>, id: ast::node_id, _sp: span) @@ -1609,7 +1619,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expr: @ast::expr, ast_sigil_opt: Option<ast::Sigil>, decl: &ast::fn_decl, - body: ast::blk, + body: &ast::blk, fn_kind: FnKind, expected: Option<ty::t>) { let tcx = fcx.ccx.tcx; @@ -1653,7 +1663,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let mut fn_ty = astconv::ty_of_closure( fcx, fcx, sigil, purity, expected_onceness, - None, *decl, expected_tys, expr.span); + None, decl, expected_tys, expr.span); let fty = ty::mk_closure(tcx, copy fn_ty); @@ -2094,7 +2104,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, // message because of the indirect_ret_ty. let fn_kind = if err_happened {Vanilla} else {ForLoop}; check_expr_fn(fcx, loop_body, None, - decl, *body, fn_kind, Some(inner_ty)); + decl, body, fn_kind, Some(inner_ty)); demand::suptype(fcx, loop_body.span, inner_ty, fcx.expr_ty(loop_body)); } @@ -2341,28 +2351,28 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } ast::expr_if(cond, ref thn, elsopt) => { bot = check_expr_has_type(fcx, cond, ty::mk_bool(tcx)); - bot |= check_then_else(fcx, *thn, elsopt, id, expr.span); + bot |= check_then_else(fcx, thn, elsopt, id, expr.span); } ast::expr_while(cond, ref body) => { bot = check_expr_has_type(fcx, cond, ty::mk_bool(tcx)); - check_block_no_value(fcx, (*body)); + check_block_no_value(fcx, body); fcx.write_ty(id, ty::mk_nil(tcx)); } ast::expr_loop(ref body, _) => { - check_block_no_value(fcx, (*body)); + check_block_no_value(fcx, body); fcx.write_ty(id, ty::mk_nil(tcx)); - bot = !may_break(tcx, expr.id, (*body)); + bot = !may_break(tcx, expr.id, body); } ast::expr_match(discrim, ref arms) => { bot = _match::check_match(fcx, expr, discrim, (/*bad*/copy *arms)); } ast::expr_fn(sigil, ref decl, ref body, _) => { check_expr_fn(fcx, expr, Some(sigil), - decl, (*body), Vanilla, expected); + decl, body, Vanilla, expected); } ast::expr_fn_block(ref decl, ref body) => { check_expr_fn(fcx, expr, None, - decl, (*body), Vanilla, expected); + decl, body, Vanilla, expected); } ast::expr_loop_body(loop_body) => { check_loop_body(fcx, expr, expected, loop_body); @@ -2392,7 +2402,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, match b.node { ast::expr_fn_block(ref decl, ref body) => { check_expr_fn(fcx, b, None, - decl, *body, DoBlock, Some(inner_ty)); + decl, body, DoBlock, Some(inner_ty)); demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b)); } // argh @@ -2402,7 +2412,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } ast::expr_block(ref b) => { // If this is an unchecked block, turn off purity-checking - bot = check_block_with_expected(fcx, *b, expected); + bot = check_block_with_expected(fcx, b, expected); let typ = match b.node.expr { Some(expr) => fcx.expr_ty(expr), @@ -2692,7 +2702,7 @@ pub fn check_stmt(fcx: @mut FnCtxt, stmt: @ast::stmt) -> bool { return bot; } -pub fn check_block_no_value(fcx: @mut FnCtxt, blk: ast::blk) -> bool { +pub fn check_block_no_value(fcx: @mut FnCtxt, blk: &ast::blk) -> bool { let bot = check_block(fcx, blk); if !bot { let blkty = fcx.node_ty(blk.node.id); @@ -2702,12 +2712,12 @@ pub fn check_block_no_value(fcx: @mut FnCtxt, blk: ast::blk) -> bool { return bot; } -pub fn check_block(fcx0: @mut FnCtxt, blk: ast::blk) -> bool { +pub fn check_block(fcx0: @mut FnCtxt, blk: &ast::blk) -> bool { check_block_with_expected(fcx0, blk, None) } pub fn check_block_with_expected(fcx0: @mut FnCtxt, - blk: ast::blk, + blk: &ast::blk, expected: Option<ty::t>) -> bool { let fcx = match blk.node.rules { @@ -3102,7 +3112,7 @@ pub fn ast_expr_vstore_to_vstore(fcx: @mut FnCtxt, } // Returns true if b contains a break that can exit from b -pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool { +pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: &ast::blk) -> bool { // First: is there an unlabeled break immediately // inside the loop? (loop_query(b, |e| { diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index c91607489ec..bf6ddc4f542 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -125,7 +125,7 @@ pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) { fcx.infcx().resolve_regions(); } -pub fn regionck_fn(fcx: @mut FnCtxt, blk: ast::blk) { +pub fn regionck_fn(fcx: @mut FnCtxt, blk: &ast::blk) { let rcx = @mut Rcx { fcx: fcx, errors_reported: 0 }; let v = regionck_visitor(); (v.visit_block)(blk, rcx, v); @@ -176,7 +176,7 @@ pub fn visit_local(l: @ast::local, &&rcx: @mut Rcx, v: rvt) { } } -pub fn visit_block(b: ast::blk, &&rcx: @mut Rcx, v: rvt) { +pub fn visit_block(b: &ast::blk, &&rcx: @mut Rcx, v: rvt) { visit::visit_block(b, rcx, v); } diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index e6b837fa949..c8cd7c05fe8 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -731,7 +731,7 @@ pub fn resolve_expr(ex: @ast::expr, // Detect points where a trait-bounded type parameter is // instantiated, resolve the impls for the parameters. -pub fn resolve_in_block(fcx: @mut FnCtxt, bl: ast::blk) { +pub fn resolve_in_block(fcx: @mut FnCtxt, bl: &ast::blk) { visit::visit_block(bl, fcx, visit::mk_vt(@visit::Visitor { visit_expr: resolve_expr, visit_item: |_,_,_| {}, diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index a16dab4bdea..7fb896a902c 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -200,7 +200,7 @@ fn visit_expr(e: @ast::expr, &&wbcx: @mut WbCtxt, v: wb_vt) { } visit::visit_expr(e, wbcx, v); } -fn visit_block(b: ast::blk, &&wbcx: @mut WbCtxt, v: wb_vt) { +fn visit_block(b: &ast::blk, &&wbcx: @mut WbCtxt, v: wb_vt) { if !wbcx.success { return; } resolve_type_vars_for_node(wbcx, b.span, b.node.id); visit::visit_block(b, wbcx, v); @@ -260,7 +260,7 @@ pub fn resolve_type_vars_in_expr(fcx: @mut FnCtxt, e: @ast::expr) -> bool { pub fn resolve_type_vars_in_fn(fcx: @mut FnCtxt, decl: &ast::fn_decl, - blk: ast::blk, + blk: &ast::blk, self_info: Option<SelfInfo>) -> bool { let wbcx = @mut WbCtxt { fcx: fcx, success: true }; let visit = mk_visitor(); diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 96c76b52181..0c44c20b25e 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -228,7 +228,7 @@ pub fn ensure_trait_methods(ccx: @mut CrateCtxt, } fn make_static_method_ty(ccx: @mut CrateCtxt, - am: ast::ty_method, + am: &ast::ty_method, rp: Option<ty::region_variance>, m: ty::method, // Take this as an argument b/c we may check @@ -289,10 +289,11 @@ pub fn ensure_trait_methods(ccx: @mut CrateCtxt, } let trait_bounds = ty_param_bounds(ccx, *params); - let ty_m = trait_method_to_ty_method(*m); - let method_ty = ty_of_ty_method(ccx, ty_m, region_paramd, def_id); + let ty_m = trait_method_to_ty_method(m); + let method_ty = ty_of_ty_method(ccx, &ty_m, region_paramd, + def_id); if ty_m.self_ty.node == ast::sty_static { - make_static_method_ty(ccx, ty_m, region_paramd, + make_static_method_ty(ccx, &ty_m, region_paramd, method_ty, trait_ty, trait_bounds); } @@ -689,7 +690,7 @@ pub fn convert_struct(ccx: @mut CrateCtxt, astconv::ty_of_bare_fn( ccx, type_rscope(rp), ast::impure_fn, ast::RustAbi, - ast_util::dtor_dec())); + &ast_util::dtor_dec())); write_ty_to_tcx(tcx, dtor.node.id, t_dtor); tcx.tcache.insert(local_def(dtor.node.id), ty_param_bounds_and_ty { @@ -748,7 +749,7 @@ pub fn ty_of_method(ccx: @mut CrateCtxt, ident: m.ident, tps: ty_param_bounds(ccx, m.tps), fty: astconv::ty_of_bare_fn(ccx, type_rscope(rp), m.purity, - ast::RustAbi, m.decl), + ast::RustAbi, &m.decl), self_ty: m.self_ty.node, vis: m.vis, def_id: local_def(m.id) @@ -756,14 +757,14 @@ pub fn ty_of_method(ccx: @mut CrateCtxt, } pub fn ty_of_ty_method(self: @mut CrateCtxt, - m: ast::ty_method, + m: &ast::ty_method, rp: Option<ty::region_variance>, id: ast::def_id) -> ty::method { ty::method { ident: m.ident, tps: ty_param_bounds(self, m.tps), fty: astconv::ty_of_bare_fn(self, type_rscope(rp), m.purity, - ast::RustAbi, m.decl), + ast::RustAbi, &m.decl), // assume public, because this is only invoked on trait methods self_ty: m.self_ty.node, vis: ast::public, @@ -819,7 +820,7 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) ast::item_fn(decl, purity, tps, _) => { let bounds = ty_param_bounds(ccx, tps); let tofd = astconv::ty_of_bare_fn(ccx, empty_rscope, purity, - ast::RustAbi, decl); + ast::RustAbi, &decl); let tpt = ty_param_bounds_and_ty { bounds: bounds, region_param: None, @@ -903,17 +904,17 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) pub fn ty_of_foreign_item(ccx: @mut CrateCtxt, it: @ast::foreign_item) -> ty::ty_param_bounds_and_ty { match /*bad*/copy it.node { - ast::foreign_item_fn(fn_decl, _, params) => { - return ty_of_foreign_fn_decl(ccx, fn_decl, params, local_def(it.id)); - } - ast::foreign_item_const(t) => { - let rb = in_binding_rscope(empty_rscope); - return ty::ty_param_bounds_and_ty { - bounds: @~[], - region_param: None, - ty: ast_ty_to_ty(ccx, rb, t) - }; - } + ast::foreign_item_fn(ref fn_decl, _, ref params) => { + ty_of_foreign_fn_decl(ccx, fn_decl, *params, local_def(it.id)) + } + ast::foreign_item_const(t) => { + let rb = in_binding_rscope(empty_rscope); + ty::ty_param_bounds_and_ty { + bounds: @~[], + region_param: None, + ty: ast_ty_to_ty(ccx, rb, t) + } + } } } @@ -958,7 +959,7 @@ pub fn compute_bounds(ccx: @mut CrateCtxt, } pub fn ty_param_bounds(ccx: @mut CrateCtxt, - params: ~[ast::ty_param]) + params: &[ast::ty_param]) -> @~[ty::param_bounds] { @do params.map |param| { match ccx.tcx.ty_param_bounds.find(¶m.id) { @@ -973,8 +974,8 @@ pub fn ty_param_bounds(ccx: @mut CrateCtxt, } pub fn ty_of_foreign_fn_decl(ccx: @mut CrateCtxt, - decl: ast::fn_decl, - +ty_params: ~[ast::ty_param], + decl: &ast::fn_decl, + ty_params: &[ast::ty_param], def_id: ast::def_id) -> ty::ty_param_bounds_and_ty { let bounds = ty_param_bounds(ccx, ty_params); diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 7b980b9de0d..59fe85cf173 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -56,7 +56,7 @@ pub fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] { // Takes a predicate p, returns true iff p is true for any subexpressions // of b -- skipping any inner loops (loop, while, loop_body) -pub fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool { +pub fn loop_query(b: &ast::blk, p: fn@(ast::expr_) -> bool) -> bool { let rs = @mut false; let visit_expr: @fn(@ast::expr, &&flag: @mut bool, @@ -79,7 +79,7 @@ pub fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool { // Takes a predicate p, returns true iff p is true for any subexpressions // of b -- skipping any inner loops (loop, while, loop_body) -pub fn block_query(b: ast::blk, p: fn@(@ast::expr) -> bool) -> bool { +pub fn block_query(b: &ast::blk, p: fn@(@ast::expr) -> bool) -> bool { let rs = @mut false; let visit_expr: @fn(@ast::expr, &&flag: @mut bool, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 8b0c84cff83..f262b2219e9 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -70,7 +70,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) re_scope(node_id) => { match cx.items.find(&node_id) { Some(ast_map::node_block(ref blk)) => { - explain_span(cx, "block", (*blk).span) + explain_span(cx, "block", blk.span) } Some(ast_map::node_expr(expr)) => { match expr.node { @@ -108,7 +108,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) match cx.items.find(&id) { Some(ast_map::node_block(ref blk)) => { - let (msg, opt_span) = explain_span(cx, "block", (*blk).span); + let (msg, opt_span) = explain_span(cx, "block", blk.span); (fmt!("%s %s", prefix, msg), opt_span) } Some(_) | None => { @@ -159,7 +159,7 @@ pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { match cx.items.find(&node_id) { Some(ast_map::node_block(ref blk)) => { fmt!("<block at %s>", - cx.sess.codemap.span_to_str((*blk).span)) + cx.sess.codemap.span_to_str(blk.span)) } Some(ast_map::node_expr(expr)) => { match expr.node { diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 64a6d9c5055..fdabe86359a 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -76,7 +76,7 @@ struct ReadyCtx { fns: ~[ListenerFn] } -fn fold_mod(_ctx: @mut ReadyCtx, m: ast::_mod, +fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: fold::ast_fold) -> ast::_mod { fn strip_main(item: @ast::item) -> @ast::item { @ast::item { @@ -87,11 +87,11 @@ fn fold_mod(_ctx: @mut ReadyCtx, m: ast::_mod, } } - fold::noop_fold_mod(ast::_mod { - items: do vec::map(m.items) |item| { + fold::noop_fold_mod(&ast::_mod { + items: do m.items.map |item| { strip_main(*item) }, - .. m + .. copy *m }, fold) } @@ -199,7 +199,7 @@ pub fn ready_crate(sess: session::Session, let fold = fold::make_fold(precursor); - @fold.fold_crate(*crate) + @fold.fold_crate(crate) } pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> { diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 8386f3c0498..b56dfeffd7a 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -186,8 +186,8 @@ pub fn map_decoded_item(diag: span_handler, pub fn map_fn( fk: &visit::fn_kind, - decl: fn_decl, - body: blk, + decl: &fn_decl, + body: &blk, sp: codemap::span, id: node_id, &&cx: @mut Ctx, @@ -205,7 +205,7 @@ pub fn map_fn( id: id, attrs: /* FIXME (#2543) */ vec::from_slice(*attrs), self_id: self_id, - body: /* FIXME (#2543) */ copy body, + body: /* FIXME (#2543) */ copy *body, }, span: sp, }; @@ -222,8 +222,8 @@ pub fn map_fn( visit::visit_fn(fk, decl, body, sp, id, cx, v); } -pub fn map_block(b: blk, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { - cx.map.insert(b.node.id, node_block(/* FIXME (#2543) */ copy b)); +pub fn map_block(b: &blk, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { + cx.map.insert(b.node.id, node_block(/* FIXME (#2543) */ copy *b)); visit::visit_block(b, cx, v); } @@ -244,7 +244,7 @@ pub fn map_local(loc: @local, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { visit::visit_local(loc, cx, v); } -pub fn map_arm(arm: arm, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { +pub fn map_arm(arm: &arm, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { number_pat(cx, arm.pats[0]); visit::visit_arm(arm, cx, v); } @@ -308,7 +308,7 @@ pub fn map_item(i: @item, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { cx.map.insert(p.ref_id, node_item(i, item_path)); } for methods.each |tm| { - let id = ast_util::trait_method_to_ty_method(*tm).id; + let id = ast_util::trait_method_to_ty_method(tm).id; let d_id = ast_util::local_def(i.id); cx.map.insert(id, node_trait_method(@*tm, d_id, item_path)); } @@ -387,14 +387,14 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { fmt!("method %s in %s (id=%?)", *itr.get(m.ident), path_to_str(*path, itr), id) } - Some(node_trait_method(tm, _, path)) => { - let m = ast_util::trait_method_to_ty_method(*tm); + Some(node_trait_method(ref tm, _, path)) => { + let m = ast_util::trait_method_to_ty_method(&**tm); fmt!("method %s in %s (id=%?)", *itr.get(m.ident), path_to_str(*path, itr), id) } Some(node_variant(ref variant, _, path)) => { fmt!("variant %s in %s (id=%?)", - *itr.get((*variant).node.name), path_to_str(*path, itr), id) + *itr.get(variant.node.name), path_to_str(*path, itr), id) } Some(node_expr(expr)) => { fmt!("expr %s (id=%?)", pprust::expr_to_str(expr, itr), id) diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 3830c81f084..7bf08aaaf76 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -260,9 +260,9 @@ pub fn public_methods(ms: ~[@method]) -> ~[@method] { // extract a ty_method from a trait_method. if the trait_method is // a default, pull out the useful fields to make a ty_method -pub fn trait_method_to_ty_method(method: trait_method) -> ty_method { - match method { - required(ref m) => (*m), +pub fn trait_method_to_ty_method(method: &trait_method) -> ty_method { + match *method { + required(ref m) => copy *m, provided(ref m) => { ty_method { ident: m.ident, @@ -278,7 +278,7 @@ pub fn trait_method_to_ty_method(method: trait_method) -> ty_method { } } -pub fn split_trait_methods(trait_methods: ~[trait_method]) +pub fn split_trait_methods(trait_methods: &[trait_method]) -> (~[ty_method], ~[@method]) { let mut reqd = ~[], provd = ~[]; for trait_methods.each |trt_method| { @@ -425,7 +425,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { vfn(l.node.id); }, - visit_block: fn@(b: blk) { + visit_block: fn@(b: &blk) { vfn(b.node.id); }, @@ -433,7 +433,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { vfn(ast_util::stmt_id(*s)); }, - visit_arm: fn@(_a: arm) { }, + visit_arm: fn@(_a: &arm) { }, visit_pat: fn@(p: @pat) { vfn(p.id) @@ -463,8 +463,8 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { } }, - visit_fn: fn@(fk: &visit::fn_kind, d: ast::fn_decl, - _b: ast::blk, _sp: span, id: ast::node_id) { + visit_fn: fn@(fk: &visit::fn_kind, d: &ast::fn_decl, + _b: &ast::blk, _sp: span, id: ast::node_id) { vfn(id); match *fk { @@ -491,10 +491,10 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { } }, - visit_ty_method: fn@(_ty_m: ty_method) { + visit_ty_method: fn@(_ty_m: &ty_method) { }, - visit_trait_method: fn@(_ty_m: trait_method) { + visit_trait_method: fn@(_ty_m: &trait_method) { }, visit_struct_def: fn@(_sd: @struct_def, _id: ident, _tps: &[ty_param], diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index dad1c2a7fea..5b2d6f7600b 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -183,28 +183,28 @@ pub fn contains(haystack: &[@ast::meta_item], } fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { - return match a.node { - ast::meta_word(ref na) => match b.node { + match a.node { + ast::meta_word(ref na) => match b.node { ast::meta_word(ref nb) => (*na) == (*nb), _ => false - }, - ast::meta_name_value(ref na, va) => match b.node { + }, + ast::meta_name_value(ref na, va) => match b.node { ast::meta_name_value(ref nb, vb) => { (*na) == (*nb) && va.node == vb.node } _ => false - }, - ast::meta_list(ref na, misa) => match b.node { - ast::meta_list(ref nb, misb) => { + }, + ast::meta_list(ref na, ref misa) => match b.node { + ast::meta_list(ref nb, ref misb) => { if na != nb { return false; } - for misa.each |&mi| { - if !contains(misb, mi) { return false; } + for misa.each |mi| { + if !misb.contains(mi) { return false; } } true } _ => false - } } + } } pub fn contains_name(metas: &[@ast::meta_item], name: &str) -> bool { @@ -260,21 +260,23 @@ pub fn last_meta_item_list_by_name(items: ~[@ast::meta_item], name: &str) /* Higher-level applications */ -pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] { +pub fn sort_meta_items(items: &[@ast::meta_item]) -> ~[@ast::meta_item] { // This is sort of stupid here, converting to a vec of mutables and back - let mut v = items; + let mut v = vec::from_slice(items); do std::sort::quick_sort(v) |ma, mb| { get_meta_item_name(*ma) <= get_meta_item_name(*mb) } // There doesn't seem to be a more optimal way to do this - do v.map |&m| { + do v.map |m| { match m.node { - ast::meta_list(n, mis) => @spanned { - node: ast::meta_list(n, sort_meta_items(mis)), - .. *m - }, - _ => m + ast::meta_list(n, ref mis) => { + @spanned { + node: ast::meta_list(n, sort_meta_items(*mis)), + .. /*bad*/ copy **m + } + } + _ => /*bad*/ copy *m } } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 0b2aaa89d9b..d26b566ecf6 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -24,63 +24,71 @@ use core::vec; use std::oldmap::HashMap; pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt, - e: expr_, s: span, fld: ast_fold, - orig: fn@(expr_, span, ast_fold) -> (expr_, span)) + e: &expr_, s: span, fld: ast_fold, + orig: fn@(&expr_, span, ast_fold) -> (expr_, span)) -> (expr_, span) { - return match e { - // expr_mac should really be expr_ext or something; it's the - // entry-point for all syntax extensions. - expr_mac(ref mac) => { - + match *e { + // expr_mac should really be expr_ext or something; it's the + // entry-point for all syntax extensions. + expr_mac(ref mac) => { match (*mac).node { - - // Token-tree macros, these will be the only case when we're - // finished transitioning. - mac_invoc_tt(pth, ref tts) => { - assert (vec::len(pth.idents) == 1u); - /* using idents and token::special_idents would make the - the macro names be hygienic */ - let extname = cx.parse_sess().interner.get(pth.idents[0]); - match exts.find(&extname) { - None => { - cx.span_fatal(pth.span, - fmt!("macro undefined: '%s'", *extname)) - } - Some(NormalTT(SyntaxExpanderTT{expander: exp, - span: exp_sp})) => { - cx.bt_push(ExpandedFrom(CallInfo{ - call_site: s, - callee: NameAndSpan { - name: *extname, span: exp_sp + // Token-tree macros, these will be the only case when we're + // finished transitioning. + mac_invoc_tt(pth, ref tts) => { + assert (vec::len(pth.idents) == 1u); + /* using idents and token::special_idents would make the + the macro names be hygienic */ + let extname = cx.parse_sess().interner.get(pth.idents[0]); + match exts.find(&extname) { + None => { + cx.span_fatal( + pth.span, + fmt!("macro undefined: '%s'", *extname)) } - })); - - let expanded = match exp(cx, (*mac).span, (*tts)) { - MRExpr(e) => e, - MRAny(expr_maker,_,_) => expr_maker(), - _ => cx.span_fatal( - pth.span, fmt!("non-expr macro in expr pos: %s", - *extname)) - }; - - //keep going, outside-in - let fully_expanded = fld.fold_expr(expanded).node; - cx.bt_pop(); - - (fully_expanded, s) - } - _ => { - cx.span_fatal(pth.span, - fmt!("'%s' is not a tt-style macro", - *extname)) - } - + Some(NormalTT(SyntaxExpanderTT{ + expander: exp, + span: exp_sp + })) => { + cx.bt_push(ExpandedFrom(CallInfo { + call_site: s, + callee: NameAndSpan { + name: *extname, + span: exp_sp, + }, + })); + + let expanded = match exp(cx, mac.span, *tts) { + MRExpr(e) => e, + MRAny(expr_maker,_,_) => expr_maker(), + _ => { + cx.span_fatal( + pth.span, + fmt!( + "non-expr macro in expr pos: %s", + *extname + ) + ) + } + }; + + //keep going, outside-in + let fully_expanded = fld.fold_expr(expanded).node; + cx.bt_pop(); + + (fully_expanded, s) + } + _ => { + cx.span_fatal( + pth.span, + fmt!("'%s' is not a tt-style macro", *extname) + ) + } + } } - } } - } - _ => orig(e, s, fld) - }; + } + _ => orig(e, s, fld) + } } // This is a secondary mechanism for invoking syntax extensions on items: @@ -93,8 +101,8 @@ pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt, // NB: there is some redundancy between this and expand_item, below, and // they might benefit from some amount of semantic and language-UI merger. pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt, - module_: ast::_mod, fld: ast_fold, - orig: fn@(ast::_mod, ast_fold) -> ast::_mod) + module_: &ast::_mod, fld: ast_fold, + orig: fn@(&ast::_mod, ast_fold) -> ast::_mod) -> ast::_mod { // Fold the contents first: let module_ = orig(module_, fld); @@ -130,8 +138,8 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt, // When we enter a module, record it, for the sake of `module!` pub fn expand_item(exts: SyntaxExtensions, - cx: ext_ctxt, &&it: @ast::item, fld: ast_fold, - orig: fn@(&&v: @ast::item, ast_fold) -> Option<@ast::item>) + cx: ext_ctxt, it: @ast::item, fld: ast_fold, + orig: fn@(@ast::item, ast_fold) -> Option<@ast::item>) -> Option<@ast::item> { let is_mod = match it.node { ast::item_mod(_) | ast::item_foreign_mod(_) => true, @@ -223,13 +231,13 @@ pub fn expand_item_mac(exts: SyntaxExtensions, } pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt, - && s: stmt_, sp: span, fld: ast_fold, - orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span)) + s: &stmt_, sp: span, fld: ast_fold, + orig: fn@(s: &stmt_, span, ast_fold) -> (stmt_, span)) -> (stmt_, span) { - let (mac, pth, tts, semi) = match s { + let (mac, pth, tts, semi) = match *s { stmt_mac(ref mac, semi) => { - match (*mac).node { + match mac.node { mac_invoc_tt(pth, ref tts) => ((*mac), pth, (*tts), semi) } } @@ -361,8 +369,7 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, // as it registers all the core macros as expanders. f.fold_expr(cm); - let res = @f.fold_crate(*c); - return res; + @f.fold_crate(&*c) } // Local Variables: // mode: rust diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index eaf29d40c3b..e74376afb08 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -18,27 +18,27 @@ use core::option; use core::vec; pub trait ast_fold { - fn fold_crate(crate) -> crate; - fn fold_view_item(&&v: @view_item) -> @view_item; - fn fold_foreign_item(&&v: @foreign_item) -> @foreign_item; - fn fold_item(&&v: @item) -> Option<@item>; - fn fold_struct_field(&&v: @struct_field) -> @struct_field; - fn fold_item_underscore(item_) -> item_; - fn fold_method(&&v: @method) -> @method; - fn fold_block(blk) -> blk; - fn fold_stmt(&&v: @stmt) -> @stmt; - fn fold_arm(arm) -> arm; - fn fold_pat(&&v: @pat) -> @pat; - fn fold_decl(&&v: @decl) -> @decl; - fn fold_expr(&&v: @expr) -> @expr; - fn fold_ty(&&v: @Ty) -> @Ty; - fn fold_mod(_mod) -> _mod; - fn fold_foreign_mod(foreign_mod) -> foreign_mod; - fn fold_variant(variant) -> variant; - fn fold_ident(&&v: ident) -> ident; - fn fold_path(&&v: @path) -> @path; - fn fold_local(&&v: @local) -> @local; - fn map_exprs(fn@(&&v: @expr) -> @expr, ~[@expr]) -> ~[@expr]; + fn fold_crate(&crate) -> crate; + fn fold_view_item(@view_item) -> @view_item; + fn fold_foreign_item(@foreign_item) -> @foreign_item; + fn fold_item(@item) -> Option<@item>; + fn fold_struct_field(@struct_field) -> @struct_field; + fn fold_item_underscore(&item_) -> item_; + fn fold_method(@method) -> @method; + fn fold_block(&blk) -> blk; + fn fold_stmt(&stmt) -> @stmt; + fn fold_arm(&arm) -> arm; + fn fold_pat(@pat) -> @pat; + fn fold_decl(@decl) -> @decl; + fn fold_expr(@expr) -> @expr; + fn fold_ty(@Ty) -> @Ty; + fn fold_mod(&_mod) -> _mod; + fn fold_foreign_mod(&foreign_mod) -> foreign_mod; + fn fold_variant(&variant) -> variant; + fn fold_ident(ident) -> ident; + fn fold_path(@path) -> @path; + fn fold_local(@local) -> @local; + fn map_exprs(fn@(@expr) -> @expr, &[@expr]) -> ~[@expr]; fn new_id(node_id) -> node_id; fn new_span(span) -> span; } @@ -47,27 +47,27 @@ pub trait ast_fold { pub struct AstFoldFns { //unlike the others, item_ is non-trivial - fold_crate: fn@(crate_, span, ast_fold) -> (crate_, span), + fold_crate: fn@(&crate_, span, ast_fold) -> (crate_, span), fold_view_item: fn@(view_item_, ast_fold) -> view_item_, - fold_foreign_item: fn@(&&v: @foreign_item, ast_fold) -> @foreign_item, - fold_item: fn@(&&v: @item, ast_fold) -> Option<@item>, - fold_struct_field: fn@(&&v: @struct_field, ast_fold) -> @struct_field, - fold_item_underscore: fn@(item_, ast_fold) -> item_, - fold_method: fn@(&&v: @method, ast_fold) -> @method, - fold_block: fn@(blk_, span, ast_fold) -> (blk_, span), - fold_stmt: fn@(stmt_, span, ast_fold) -> (stmt_, span), - fold_arm: fn@(arm, ast_fold) -> arm, - fold_pat: fn@(pat_, span, ast_fold) -> (pat_, span), - fold_decl: fn@(decl_, span, ast_fold) -> (decl_, span), - fold_expr: fn@(expr_, span, ast_fold) -> (expr_, span), - fold_ty: fn@(ty_, span, ast_fold) -> (ty_, span), - fold_mod: fn@(_mod, ast_fold) -> _mod, - fold_foreign_mod: fn@(foreign_mod, ast_fold) -> foreign_mod, - fold_variant: fn@(variant_, span, ast_fold) -> (variant_, span), - fold_ident: fn@(&&v: ident, ast_fold) -> ident, - fold_path: fn@(path, ast_fold) -> path, - fold_local: fn@(local_, span, ast_fold) -> (local_, span), - map_exprs: fn@(fn@(&&v: @expr) -> @expr, ~[@expr]) -> ~[@expr], + fold_foreign_item: fn@(@foreign_item, ast_fold) -> @foreign_item, + fold_item: fn@(@item, ast_fold) -> Option<@item>, + fold_struct_field: fn@(@struct_field, ast_fold) -> @struct_field, + fold_item_underscore: fn@(&item_, ast_fold) -> item_, + fold_method: fn@(@method, ast_fold) -> @method, + fold_block: fn@(&blk_, span, ast_fold) -> (blk_, span), + fold_stmt: fn@(&stmt_, span, ast_fold) -> (stmt_, span), + fold_arm: fn@(&arm, ast_fold) -> arm, + fold_pat: fn@(&pat_, span, ast_fold) -> (pat_, span), + fold_decl: fn@(&decl_, span, ast_fold) -> (decl_, span), + fold_expr: fn@(&expr_, span, ast_fold) -> (expr_, span), + fold_ty: fn@(&ty_, span, ast_fold) -> (ty_, span), + fold_mod: fn@(&_mod, ast_fold) -> _mod, + fold_foreign_mod: fn@(&foreign_mod, ast_fold) -> foreign_mod, + fold_variant: fn@(&variant_, span, ast_fold) -> (variant_, span), + fold_ident: fn@(ident, ast_fold) -> ident, + fold_path: fn@(@path, ast_fold) -> path, + fold_local: fn@(&local_, span, ast_fold) -> (local_, span), + map_exprs: fn@(fn@(@expr) -> @expr, &[@expr]) -> ~[@expr], new_id: fn@(node_id) -> node_id, new_span: fn@(span) -> span } @@ -77,18 +77,20 @@ pub type ast_fold_fns = @AstFoldFns; /* some little folds that probably aren't useful to have in ast_fold itself*/ //used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive -fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item { +fn fold_meta_item_(mi: @meta_item, fld: ast_fold) -> @meta_item { @spanned { node: match mi.node { - meta_word(ref id) => meta_word((*id)), - meta_list(ref id, ref mis) => { + meta_word(id) => meta_word(id), + meta_list(id, ref mis) => { let fold_meta_item = |x| fold_meta_item_(x, fld); - meta_list(/* FIXME: (#2543) */ copy *id, - mis.map(|e| fold_meta_item(*e))) + meta_list( + id, + mis.map(|e| fold_meta_item(*e)) + ) } - meta_name_value(ref id, s) => { - meta_name_value((*id), /* FIXME (#2543) */ copy s) + meta_name_value(id, s) => { + meta_name_value(id, /* FIXME (#2543) */ copy s) } }, span: fld.new_span(mi.span) } @@ -116,13 +118,13 @@ fn fold_arg_(a: arg, fld: ast_fold) -> arg { } //used in noop_fold_expr, and possibly elsewhere in the future fn fold_mac_(m: mac, fld: ast_fold) -> mac { - spanned { node: match m.node { - mac_invoc_tt(*) => m.node, - }, - span: fld.new_span(m.span) } + spanned { + node: match m.node { mac_invoc_tt(*) => copy m.node }, + span: fld.new_span(m.span), + } } -pub fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl { +pub fn fold_fn_decl(decl: &ast::fn_decl, fld: ast_fold) -> ast::fn_decl { ast::fn_decl { inputs: decl.inputs.map(|x| fold_arg_(*x, fld)), output: fld.fold_ty(decl.output), @@ -130,29 +132,34 @@ pub fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl { } } -fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound { - match tpb { +fn fold_ty_param_bound( + tpb: &ty_param_bound, + fld: ast_fold +) -> ty_param_bound { + match *tpb { TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_ty(ty)), RegionTyParamBound => RegionTyParamBound } } -pub fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param { - ast::ty_param { ident: /* FIXME (#2543) */ copy tp.ident, - id: fld.new_id(tp.id), - bounds: @tp.bounds.map(|x| fold_ty_param_bound(*x, fld) )} +pub fn fold_ty_param(tp: &ty_param, fld: ast_fold) -> ty_param { + ast::ty_param { + ident: /* FIXME (#2543) */ copy tp.ident, + id: fld.new_id(tp.id), + bounds: @tp.bounds.map(|x| fold_ty_param_bound(x, fld)), + } } -pub fn fold_ty_params(tps: ~[ty_param], fld: ast_fold) -> ~[ty_param] { - tps.map(|x| fold_ty_param(*x, fld)) +pub fn fold_ty_params(tps: &[ty_param], fld: ast_fold) -> ~[ty_param] { + tps.map(|x| fold_ty_param(x, fld)) } -pub fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ { +pub fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ { let fold_meta_item = |x| fold_meta_item_(x, fld); let fold_attribute = |x| fold_attribute_(x, fld); crate_ { - module: fld.fold_mod(c.module), + module: fld.fold_mod(&c.module), attrs: c.attrs.map(|x| fold_attribute(*x)), config: c.config.map(|x| fold_meta_item(*x)), } @@ -163,17 +170,17 @@ fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ { } -fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold) +fn noop_fold_foreign_item(ni: @foreign_item, fld: ast_fold) -> @foreign_item { let fold_arg = |x| fold_arg_(x, fld); let fold_attribute = |x| fold_attribute_(x, fld); @ast::foreign_item { ident: fld.fold_ident(ni.ident), - attrs: vec::map(ni.attrs, |x| fold_attribute(*x)), + attrs: ni.attrs.map(|x| fold_attribute(*x)), node: match ni.node { - foreign_item_fn(fdec, purity, typms) => { + foreign_item_fn(ref fdec, purity, ref tps) => { foreign_item_fn( ast::fn_decl { inputs: fdec.inputs.map(|a| fold_arg(*a)), @@ -181,7 +188,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold) cf: fdec.cf, }, purity, - fold_ty_params(typms, fld)) + fold_ty_params(*tps, fld)) } foreign_item_const(t) => { foreign_item_const(fld.fold_ty(t)) @@ -193,18 +200,18 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold) } } -pub fn noop_fold_item(&&i: @item, fld: ast_fold) -> Option<@item> { +pub fn noop_fold_item(i: @item, fld: ast_fold) -> Option<@item> { let fold_attribute = |x| fold_attribute_(x, fld); Some(@ast::item { ident: fld.fold_ident(i.ident), attrs: i.attrs.map(|e| fold_attribute(*e)), id: fld.new_id(i.id), - node: fld.fold_item_underscore(i.node), + node: fld.fold_item_underscore(&i.node), vis: i.vis, span: fld.new_span(i.span) }) } -fn noop_fold_struct_field(&&sf: @struct_field, fld: ast_fold) +fn noop_fold_struct_field(sf: @struct_field, fld: ast_fold) -> @struct_field { @spanned { node: ast::struct_field_ { kind: copy sf.node.kind, id: sf.node.id, @@ -212,38 +219,51 @@ fn noop_fold_struct_field(&&sf: @struct_field, fld: ast_fold) span: sf.span } } -pub fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { - match i { - item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)), - item_fn(ref decl, purity, ref typms, ref body) => { - item_fn(fold_fn_decl(/* FIXME (#2543) */ copy *decl, fld), - purity, - fold_ty_params(/* FIXME (#2543) */ copy *typms, fld), - fld.fold_block(*body)) - } - item_mod(m) => item_mod(fld.fold_mod(m)), - item_foreign_mod(nm) => item_foreign_mod(fld.fold_foreign_mod(nm)), - item_ty(t, typms) => item_ty(fld.fold_ty(t), - fold_ty_params(typms, fld)), - item_enum(ref enum_definition, ref typms) => { - item_enum(ast::enum_def(ast::enum_def_ { - variants: enum_definition.variants.map( - |x| fld.fold_variant(*x)), - common: enum_definition.common.map( - |x| fold_struct_def(*x, fld)), - }), fold_ty_params(/* FIXME (#2543) */ copy *typms, fld)) - } - item_struct(ref struct_def, ref typms) => { - let struct_def = fold_struct_def( - /* FIXME (#2543) */ copy *struct_def, - fld); - item_struct(struct_def, /* FIXME (#2543) */ copy *typms) +pub fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ { + match *i { + item_const(t, e) => { + item_const(fld.fold_ty(t), fld.fold_expr(e)) + } + item_fn(ref decl, purity, ref tps, ref body) => { + item_fn( + fold_fn_decl(decl, fld), + purity, + fold_ty_params(*tps, fld), + fld.fold_block(body) + ) + } + item_mod(ref m) => item_mod(fld.fold_mod(m)), + item_foreign_mod(ref nm) => { + item_foreign_mod(fld.fold_foreign_mod(nm)) + } + item_ty(t, ref tps) => { + item_ty(fld.fold_ty(t), fold_ty_params(*tps, fld)) + } + item_enum(ref enum_definition, ref tps) => { + item_enum( + ast::enum_def( + ast::enum_def_ { + variants: do enum_definition.variants.map |x| { + fld.fold_variant(x) + }, + common: do enum_definition.common.map |x| { + fold_struct_def(*x, fld) + } + } + ), + fold_ty_params(*tps, fld)) + } + item_struct(ref struct_def, ref tps) => { + let struct_def = fold_struct_def(*struct_def, fld); + item_struct(struct_def, /* FIXME (#2543) */ copy *tps) } item_impl(ref tps, ifce, ty, ref methods) => { - item_impl(fold_ty_params(/* FIXME (#2543) */ copy *tps, fld), - ifce.map(|p| fold_trait_ref(*p, fld)), - fld.fold_ty(ty), - methods.map(|x| fld.fold_method(*x))) + item_impl( + fold_ty_params(*tps, fld), + ifce.map(|p| fold_trait_ref(*p, fld)), + fld.fold_ty(ty), + methods.map(|x| fld.fold_method(*x)) + ) } item_trait(ref tps, ref traits, ref methods) => { let methods = do methods.map |method| { @@ -252,9 +272,11 @@ pub fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { provided(method) => provided(fld.fold_method(method)) } }; - item_trait(fold_ty_params(/* FIXME (#2543) */ copy *tps, fld), - traits.map(|p| fold_trait_ref(*p, fld)), - methods) + item_trait( + fold_ty_params(*tps, fld), + traits.map(|p| fold_trait_ref(*p, fld)), + methods + ) } item_mac(ref m) => { // FIXME #2888: we might actually want to do something here. @@ -266,12 +288,16 @@ pub fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold) -> @ast::struct_def { let dtor = do option::map(&struct_def.dtor) |dtor| { - let dtor_body = fld.fold_block(dtor.node.body); + let dtor_body = fld.fold_block(&dtor.node.body); let dtor_id = fld.new_id(dtor.node.id); - spanned { node: ast::struct_dtor_ { body: dtor_body, - id: dtor_id, - .. dtor.node}, - span: dtor.span } + spanned { + node: ast::struct_dtor_ { + body: dtor_body, + id: dtor_id, + .. copy dtor.node + }, + span: copy dtor.span + } }; @ast::struct_def { fields: struct_def.fields.map(|f| fold_struct_field(*f, fld)), @@ -280,29 +306,33 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold) } } -fn fold_trait_ref(&&p: @trait_ref, fld: ast_fold) -> @trait_ref { +fn fold_trait_ref(p: @trait_ref, fld: ast_fold) -> @trait_ref { @ast::trait_ref { path: fld.fold_path(p.path), ref_id: fld.new_id(p.ref_id), } } -fn fold_struct_field(&&f: @struct_field, fld: ast_fold) -> @struct_field { - @spanned { node: ast::struct_field_ { kind: copy f.node.kind, - id: fld.new_id(f.node.id), - ty: fld.fold_ty(f.node.ty) }, - span: fld.new_span(f.span) } +fn fold_struct_field(f: @struct_field, fld: ast_fold) -> @struct_field { + @spanned { + node: ast::struct_field_ { + kind: copy f.node.kind, + id: fld.new_id(f.node.id), + ty: fld.fold_ty(f.node.ty), + }, + span: fld.new_span(f.span), + } } -fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method { +fn noop_fold_method(m: @method, fld: ast_fold) -> @method { @ast::method { ident: fld.fold_ident(m.ident), attrs: /* FIXME (#2543) */ copy m.attrs, tps: fold_ty_params(m.tps, fld), self_ty: m.self_ty, purity: m.purity, - decl: fold_fn_decl(m.decl, fld), - body: fld.fold_block(m.body), + decl: fold_fn_decl(&m.decl, fld), + body: fld.fold_block(&m.body), id: fld.new_id(m.id), span: fld.new_span(m.span), self_id: fld.new_id(m.self_id), @@ -311,7 +341,7 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method { } -pub fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ { +pub fn noop_fold_block(b: &blk_, fld: ast_fold) -> blk_ { ast::blk_ { view_items: b.view_items.map(|x| fld.fold_view_item(*x)), stmts: b.stmts.map(|x| fld.fold_stmt(*x)), @@ -321,38 +351,42 @@ pub fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ { } } -fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { +fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ { let fold_mac = |x| fold_mac_(x, fld); - return match s { - stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)), - stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)), - stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)), - stmt_mac(ref mac, semi) => stmt_mac(fold_mac((*mac)), semi) - }; + match *s { + stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)), + stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)), + stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)), + stmt_mac(ref mac, semi) => stmt_mac(fold_mac((*mac)), semi) + } } -fn noop_fold_arm(a: arm, fld: ast_fold) -> arm { +fn noop_fold_arm(a: &arm, fld: ast_fold) -> arm { arm { - pats: vec::map(a.pats, |x| fld.fold_pat(*x)), - guard: option::map(&a.guard, |x| fld.fold_expr(*x)), - body: fld.fold_block(a.body), - } -} - -pub fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { - return match p { - pat_wild => pat_wild, - pat_ident(binding_mode, pth, sub) => { - pat_ident(binding_mode, - fld.fold_path(pth), - option::map(&sub, |x| fld.fold_pat(*x))) - } - pat_lit(e) => pat_lit(fld.fold_expr(e)), - pat_enum(pth, pats) => { - pat_enum(fld.fold_path(pth), option::map(&pats, - |pats| vec::map(*pats, |x| fld.fold_pat(*x)))) - } - pat_rec(fields, etc) => { + pats: a.pats.map(|x| fld.fold_pat(*x)), + guard: a.guard.map(|x| fld.fold_expr(*x)), + body: fld.fold_block(&a.body), + } +} + +pub fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ { + match *p { + pat_wild => pat_wild, + pat_ident(binding_mode, pth, sub) => { + pat_ident( + binding_mode, + fld.fold_path(pth), + sub.map(|x| fld.fold_pat(*x)) + ) + } + pat_lit(e) => pat_lit(fld.fold_expr(e)), + pat_enum(pth, pats) => { + pat_enum( + fld.fold_path(pth), + pats.map(|pats| pats.map(|x| fld.fold_pat(*x))) + ) + } + pat_rec(fields, etc) => { let fs = do fields.map |f| { ast::field_pat { ident: /* FIXME (#2543) */ copy f.ident, @@ -360,8 +394,8 @@ pub fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { } }; pat_rec(fs, etc) - } - pat_struct(pth, fields, etc) => { + } + pat_struct(pth, fields, etc) => { let pth_ = fld.fold_path(pth); let fs = do fields.map |f| { ast::field_pat { @@ -370,40 +404,44 @@ pub fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { } }; pat_struct(pth_, fs, etc) - } - pat_tup(elts) => pat_tup(vec::map(elts, |x| fld.fold_pat(*x))), - pat_box(inner) => pat_box(fld.fold_pat(inner)), - pat_uniq(inner) => pat_uniq(fld.fold_pat(inner)), - pat_region(inner) => pat_region(fld.fold_pat(inner)), - pat_range(e1, e2) => { + } + pat_tup(ref elts) => pat_tup(elts.map(|x| fld.fold_pat(*x))), + pat_box(inner) => pat_box(fld.fold_pat(inner)), + pat_uniq(inner) => pat_uniq(fld.fold_pat(inner)), + pat_region(inner) => pat_region(fld.fold_pat(inner)), + pat_range(e1, e2) => { pat_range(fld.fold_expr(e1), fld.fold_expr(e2)) - }, - pat_vec(elts, tail) => pat_vec( - vec::map(elts, |x| fld.fold_pat(*x)), - option::map(&tail, |tail| fld.fold_pat(*tail)) - ) - }; + }, + pat_vec(elts, tail) => { + pat_vec( + elts.map(|x| fld.fold_pat(*x)), + tail.map(|tail| fld.fold_pat(*tail)) + ) + } + } } -fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ { - match d { - decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(*x))), - decl_item(it) => match fld.fold_item(it) { - Some(it_folded) => decl_item(it_folded), - None => decl_local(~[]) - } +fn noop_fold_decl(d: &decl_, fld: ast_fold) -> decl_ { + match *d { + decl_local(ls) => decl_local(ls.map(|x| fld.fold_local(*x))), + decl_item(it) => { + match fld.fold_item(it) { + Some(it_folded) => decl_item(it_folded), + None => decl_local(~[]), + } + } } } -pub fn wrap<T>(f: fn@(T, ast_fold) -> T) - -> fn@(T, span, ast_fold) -> (T, span) +pub fn wrap<T>(f: fn@(&T, ast_fold) -> T) + -> fn@(&T, span, ast_fold) -> (T, span) { - return fn@(x: T, s: span, fld: ast_fold) -> (T, span) { + fn@(x: &T, s: span, fld: ast_fold) -> (T, span) { (f(x, fld), s) } } -pub fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { +pub fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { fn fold_field_(field: field, fld: ast_fold) -> field { spanned { node: ast::field_ { @@ -418,157 +456,196 @@ pub fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { let fold_mac = |x| fold_mac_(x, fld); - return match e { - expr_vstore(e, v) => { + match *e { + expr_vstore(e, v) => { expr_vstore(fld.fold_expr(e), v) - } - expr_vec(exprs, mutt) => { - expr_vec(fld.map_exprs(|x| fld.fold_expr(x), exprs), mutt) - } - expr_repeat(expr, count, mutt) => - expr_repeat(fld.fold_expr(expr), fld.fold_expr(count), mutt), - expr_rec(ref fields, maybe_expr) => { - expr_rec(vec::map((*fields), |x| fold_field(*x)), - option::map(&maybe_expr, |x| fld.fold_expr(*x))) - } - expr_tup(elts) => expr_tup(vec::map(elts, |x| fld.fold_expr(*x))), - expr_call(f, args, blk) => { - expr_call(fld.fold_expr(f), - fld.map_exprs(|x| fld.fold_expr(x), args), - blk) - } - expr_method_call(f, i, tps, args, blk) => { - expr_method_call(fld.fold_expr(f), - fld.fold_ident(i), - vec::map(tps, |x| fld.fold_ty(*x)), - fld.map_exprs(|x| fld.fold_expr(x), args), - blk) - } - expr_binary(binop, lhs, rhs) => { + } + expr_vec(ref exprs, mutt) => { + expr_vec(fld.map_exprs(|x| fld.fold_expr(x), *exprs), mutt) + } + expr_repeat(expr, count, mutt) => { + expr_repeat(fld.fold_expr(expr), fld.fold_expr(count), mutt) + } + expr_rec(ref fields, maybe_expr) => { + expr_rec( + fields.map(|x| fold_field(*x)), + maybe_expr.map(|x| fld.fold_expr(*x)) + ) + } + expr_tup(ref elts) => expr_tup(elts.map(|x| fld.fold_expr(*x))), + expr_call(f, ref args, blk) => { + expr_call( + fld.fold_expr(f), + fld.map_exprs(|x| fld.fold_expr(x), *args), + blk + ) + } + expr_method_call(f, i, ref tps, ref args, blk) => { + expr_method_call( + fld.fold_expr(f), + fld.fold_ident(i), + tps.map(|x| fld.fold_ty(*x)), + fld.map_exprs(|x| fld.fold_expr(x), *args), + blk + ) + } + expr_binary(binop, lhs, rhs) => { expr_binary(binop, fld.fold_expr(lhs), fld.fold_expr(rhs)) - } - expr_unary(binop, ohs) => expr_unary(binop, fld.fold_expr(ohs)), - expr_loop_body(f) => expr_loop_body(fld.fold_expr(f)), - expr_do_body(f) => expr_do_body(fld.fold_expr(f)), - expr_lit(_) => copy e, - expr_cast(expr, ty) => expr_cast(fld.fold_expr(expr), ty), - expr_addr_of(m, ohs) => expr_addr_of(m, fld.fold_expr(ohs)), - expr_if(cond, ref tr, fl) => { - expr_if(fld.fold_expr(cond), fld.fold_block((*tr)), - option::map(&fl, |x| fld.fold_expr(*x))) - } - expr_while(cond, ref body) => { - expr_while(fld.fold_expr(cond), fld.fold_block((*body))) - } - expr_loop(ref body, opt_ident) => { - expr_loop(fld.fold_block((*body)), - option::map(&opt_ident, |x| fld.fold_ident(*x))) - } - expr_match(expr, ref arms) => { - expr_match(fld.fold_expr(expr), - vec::map((*arms), |x| fld.fold_arm(*x))) - } - expr_fn(proto, ref decl, ref body, _) => { - expr_fn(proto, - fold_fn_decl(/* FIXME (#2543) */ copy *decl, fld), - fld.fold_block(*body), - @()) - } - expr_fn_block(ref decl, ref body) => { - expr_fn_block(fold_fn_decl(/* FIXME (#2543) */ copy *decl, fld), - fld.fold_block(*body)) - } - expr_block(ref blk) => expr_block(fld.fold_block((*blk))), - expr_copy(e) => expr_copy(fld.fold_expr(e)), - expr_assign(el, er) => { + } + expr_unary(binop, ohs) => expr_unary(binop, fld.fold_expr(ohs)), + expr_loop_body(f) => expr_loop_body(fld.fold_expr(f)), + expr_do_body(f) => expr_do_body(fld.fold_expr(f)), + expr_lit(_) => copy *e, + expr_cast(expr, ty) => expr_cast(fld.fold_expr(expr), ty), + expr_addr_of(m, ohs) => expr_addr_of(m, fld.fold_expr(ohs)), + expr_if(cond, ref tr, fl) => { + expr_if( + fld.fold_expr(cond), + fld.fold_block(tr), + fl.map(|x| fld.fold_expr(*x)) + ) + } + expr_while(cond, ref body) => { + expr_while(fld.fold_expr(cond), fld.fold_block(body)) + } + expr_loop(ref body, opt_ident) => { + expr_loop( + fld.fold_block(body), + opt_ident.map(|x| fld.fold_ident(*x)) + ) + } + expr_match(expr, ref arms) => { + expr_match( + fld.fold_expr(expr), + arms.map(|x| fld.fold_arm(x)) + ) + } + expr_fn(proto, ref decl, ref body, _) => { + expr_fn( + proto, + fold_fn_decl(decl, fld), + fld.fold_block(body), + @() + ) + } + expr_fn_block(ref decl, ref body) => { + expr_fn_block( + fold_fn_decl(decl, fld), + fld.fold_block(body) + ) + } + expr_block(ref blk) => expr_block(fld.fold_block(blk)), + expr_copy(e) => expr_copy(fld.fold_expr(e)), + expr_assign(el, er) => { expr_assign(fld.fold_expr(el), fld.fold_expr(er)) - } - expr_swap(el, er) => { + } + expr_swap(el, er) => { expr_swap(fld.fold_expr(el), fld.fold_expr(er)) - } - expr_assign_op(op, el, er) => { + } + expr_assign_op(op, el, er) => { expr_assign_op(op, fld.fold_expr(el), fld.fold_expr(er)) - } - expr_field(el, id, tys) => { - expr_field(fld.fold_expr(el), fld.fold_ident(id), - vec::map(tys, |x| fld.fold_ty(*x))) - } - expr_index(el, er) => { + } + expr_field(el, id, ref tys) => { + expr_field( + fld.fold_expr(el), fld.fold_ident(id), + tys.map(|x| fld.fold_ty(*x)) + ) + } + expr_index(el, er) => { expr_index(fld.fold_expr(el), fld.fold_expr(er)) - } - expr_path(pth) => expr_path(fld.fold_path(pth)), - expr_break(opt_ident) => - expr_break(option::map(&opt_ident, |x| fld.fold_ident(*x))), - expr_again(opt_ident) => - expr_again(option::map(&opt_ident, |x| fld.fold_ident(*x))), - expr_ret(e) => expr_ret(option::map(&e, |x| fld.fold_expr(*x))), - expr_log(i, lv, e) => expr_log(i, fld.fold_expr(lv), - fld.fold_expr(e)), - expr_assert(e) => expr_assert(fld.fold_expr(e)), - expr_mac(ref mac) => expr_mac(fold_mac((*mac))), - expr_struct(path, ref fields, maybe_expr) => { - expr_struct(fld.fold_path(path), - vec::map((*fields), |x| fold_field(*x)), - option::map(&maybe_expr, |x| fld.fold_expr(*x))) - }, - expr_paren(ex) => expr_paren(fld.fold_expr(ex)) - } -} - -pub fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { + } + expr_path(pth) => expr_path(fld.fold_path(pth)), + expr_break(ref opt_ident) => { + expr_break(opt_ident.map(|x| fld.fold_ident(*x))) + } + expr_again(ref opt_ident) => { + expr_again(opt_ident.map(|x| fld.fold_ident(*x))) + } + expr_ret(ref e) => { + expr_ret(e.map(|x| fld.fold_expr(*x))) + } + expr_log(i, lv, e) => { + expr_log( + i, + fld.fold_expr(lv), + fld.fold_expr(e) + ) + } + expr_assert(e) => expr_assert(fld.fold_expr(e)), + expr_mac(ref mac) => expr_mac(fold_mac((*mac))), + expr_struct(path, ref fields, maybe_expr) => { + expr_struct( + fld.fold_path(path), + fields.map(|x| fold_field(*x)), + maybe_expr.map(|x| fld.fold_expr(*x)) + ) + }, + expr_paren(ex) => expr_paren(fld.fold_expr(ex)) + } +} + +pub fn noop_fold_ty(t: &ty_, fld: ast_fold) -> ty_ { let fold_mac = |x| fold_mac_(x, fld); - fn fold_mt(mt: mt, fld: ast_fold) -> mt { - mt { ty: fld.fold_ty(mt.ty), mutbl: mt.mutbl } + fn fold_mt(mt: &mt, fld: ast_fold) -> mt { + mt { + ty: fld.fold_ty(mt.ty), + mutbl: mt.mutbl, + } } fn fold_field(f: ty_field, fld: ast_fold) -> ty_field { spanned { node: ast::ty_field_ { ident: fld.fold_ident(f.node.ident), - mt: fold_mt(f.node.mt, fld), + mt: fold_mt(&f.node.mt, fld), }, span: fld.new_span(f.span), } } - match t { - ty_nil | ty_bot | ty_infer => copy t, - ty_box(mt) => ty_box(fold_mt(mt, fld)), - ty_uniq(mt) => ty_uniq(fold_mt(mt, fld)), - ty_vec(mt) => ty_vec(fold_mt(mt, fld)), - ty_ptr(mt) => ty_ptr(fold_mt(mt, fld)), - ty_rptr(region, mt) => ty_rptr(region, fold_mt(mt, fld)), - ty_rec(ref fields) => - ty_rec(vec::map((*fields), |f| fold_field(*f, fld))), - ty_closure(f) => - ty_closure(@TyClosure { - sigil: f.sigil, - purity: f.purity, - region: f.region, - onceness: f.onceness, - decl: fold_fn_decl(f.decl, fld) - }), - ty_bare_fn(f) => - ty_bare_fn(@TyBareFn { - purity: f.purity, - abi: f.abi, - decl: fold_fn_decl(f.decl, fld) - }), - ty_tup(tys) => ty_tup(vec::map(tys, |ty| fld.fold_ty(*ty))), - ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)), - ty_fixed_length_vec(mt, vs) => - ty_fixed_length_vec(fold_mt(mt, fld), vs), - ty_mac(ref mac) => ty_mac(fold_mac((*mac))) + match *t { + ty_nil | ty_bot | ty_infer => copy *t, + ty_box(ref mt) => ty_box(fold_mt(mt, fld)), + ty_uniq(ref mt) => ty_uniq(fold_mt(mt, fld)), + ty_vec(ref mt) => ty_vec(fold_mt(mt, fld)), + ty_ptr(ref mt) => ty_ptr(fold_mt(mt, fld)), + ty_rptr(region, ref mt) => ty_rptr(region, fold_mt(mt, fld)), + ty_rec(ref fields) => ty_rec(fields.map(|f| fold_field(*f, fld))), + ty_closure(ref f) => { + ty_closure(@TyClosure { + sigil: f.sigil, + purity: f.purity, + region: f.region, + onceness: f.onceness, + decl: fold_fn_decl(&f.decl, fld) + }) + } + ty_bare_fn(ref f) => { + ty_bare_fn(@TyBareFn { + purity: f.purity, + abi: f.abi, + decl: fold_fn_decl(&f.decl, fld) + }) + } + ty_tup(ref tys) => ty_tup(tys.map(|ty| fld.fold_ty(*ty))), + ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)), + ty_fixed_length_vec(ref mt, vs) => { + ty_fixed_length_vec( + fold_mt(mt, fld), + vs + ) + } + ty_mac(ref mac) => ty_mac(fold_mac(*mac)) } } // ...nor do modules -pub fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod { +pub fn noop_fold_mod(m: &_mod, fld: ast_fold) -> _mod { ast::_mod { view_items: vec::map(m.view_items, |x| fld.fold_view_item(*x)), items: vec::filter_mapped(m.items, |x| fld.fold_item(*x)), } } -fn noop_fold_foreign_mod(nm: foreign_mod, fld: ast_fold) -> foreign_mod { +fn noop_fold_foreign_mod(nm: &foreign_mod, fld: ast_fold) -> foreign_mod { ast::foreign_mod { sort: nm.sort, abi: nm.abi, @@ -577,7 +654,7 @@ fn noop_fold_foreign_mod(nm: foreign_mod, fld: ast_fold) -> foreign_mod { } } -fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { +fn noop_fold_variant(v: &variant_, fld: ast_fold) -> variant_ { fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg { ast::variant_arg { ty: fld.fold_ty(va.ty), id: fld.new_id(va.id) } } @@ -585,17 +662,23 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { let kind; match v.kind { - tuple_variant_kind(variant_args) => - kind = tuple_variant_kind(vec::map(variant_args, - |x| fold_variant_arg(*x))), + tuple_variant_kind(ref variant_args) => { + kind = tuple_variant_kind(do variant_args.map |x| { + fold_variant_arg(*x) + }) + } struct_variant_kind(struct_def) => { let dtor = do option::map(&struct_def.dtor) |dtor| { - let dtor_body = fld.fold_block(dtor.node.body); + let dtor_body = fld.fold_block(&dtor.node.body); let dtor_id = fld.new_id(dtor.node.id); - spanned { node: ast::struct_dtor_ { body: dtor_body, - id: dtor_id, - .. dtor.node}, - .. *dtor } + spanned { + node: ast::struct_dtor_ { + body: dtor_body, + id: dtor_id, + .. copy dtor.node + }, + .. copy *dtor + } }; kind = struct_variant_kind(@ast::struct_def { fields: vec::map(struct_def.fields, @@ -604,12 +687,13 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { ctor_id: option::map(&struct_def.ctor_id, |c| fld.new_id(*c)) }) } - enum_variant_kind(ref enum_definition) => { - let variants = vec::map((*enum_definition).variants, - |x| fld.fold_variant(*x)); - let common = option::map(&(*enum_definition).common, - |x| fold_struct_def(*x, fld)); + let variants = do (*enum_definition).variants.map |x| { + fld.fold_variant(x) + }; + let common = do (*enum_definition).common.map |x| { + fold_struct_def(*x, fld) + }; kind = enum_variant_kind( ast::enum_def(ast::enum_def_ { variants: variants, @@ -620,7 +704,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { } let fold_attribute = |x| fold_attribute_(x, fld); - let attrs = vec::map(v.attrs, |x| fold_attribute(*x)); + let attrs = v.attrs.map(|x| fold_attribute(*x)); let de = match v.disr_expr { Some(e) => Some(fld.fold_expr(e)), @@ -636,11 +720,11 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { } } -fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { - return /* FIXME (#2543) */ copy i; +fn noop_fold_ident(i: ident, _fld: ast_fold) -> ident { + /* FIXME (#2543) */ copy i } -fn noop_fold_path(&&p: path, fld: ast_fold) -> path { +fn noop_fold_path(p: @path, fld: ast_fold) -> path { ast::path { span: fld.new_span(p.span), global: p.global, idents: p.idents.map(|x| fld.fold_ident(*x)), @@ -648,7 +732,7 @@ fn noop_fold_path(&&p: path, fld: ast_fold) -> path { types: p.types.map(|x| fld.fold_ty(*x)) } } -fn noop_fold_local(l: local_, fld: ast_fold) -> local_ { +fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ { local_ { is_mutbl: l.is_mutbl, ty: fld.fold_ty(l.ty), @@ -660,8 +744,8 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ { /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a value */ -fn noop_map_exprs(f: fn@(&&v: @expr) -> @expr, es: ~[@expr]) -> ~[@expr] { - return vec::map(es, |x| f(*x)); +fn noop_map_exprs(f: fn@(@expr) -> @expr, es: &[@expr]) -> ~[@expr] { + es.map(|x| f(*x)) } fn noop_id(i: node_id) -> node_id { return i; } @@ -669,38 +753,40 @@ fn noop_id(i: node_id) -> node_id { return i; } fn noop_span(sp: span) -> span { return sp; } pub fn default_ast_fold() -> ast_fold_fns { - return @AstFoldFns {fold_crate: wrap(noop_fold_crate), - fold_view_item: noop_fold_view_item, - fold_foreign_item: noop_fold_foreign_item, - fold_item: noop_fold_item, - fold_struct_field: noop_fold_struct_field, - fold_item_underscore: noop_fold_item_underscore, - fold_method: noop_fold_method, - fold_block: wrap(noop_fold_block), - fold_stmt: wrap(noop_fold_stmt), - fold_arm: noop_fold_arm, - fold_pat: wrap(noop_fold_pat), - fold_decl: wrap(noop_fold_decl), - fold_expr: wrap(noop_fold_expr), - fold_ty: wrap(noop_fold_ty), - fold_mod: noop_fold_mod, - fold_foreign_mod: noop_fold_foreign_mod, - fold_variant: wrap(noop_fold_variant), - fold_ident: noop_fold_ident, - fold_path: noop_fold_path, - fold_local: wrap(noop_fold_local), - map_exprs: noop_map_exprs, - new_id: noop_id, - new_span: noop_span}; + @AstFoldFns { + fold_crate: wrap(noop_fold_crate), + fold_view_item: noop_fold_view_item, + fold_foreign_item: noop_fold_foreign_item, + fold_item: noop_fold_item, + fold_struct_field: noop_fold_struct_field, + fold_item_underscore: noop_fold_item_underscore, + fold_method: noop_fold_method, + fold_block: wrap(noop_fold_block), + fold_stmt: wrap(noop_fold_stmt), + fold_arm: noop_fold_arm, + fold_pat: wrap(noop_fold_pat), + fold_decl: wrap(noop_fold_decl), + fold_expr: wrap(noop_fold_expr), + fold_ty: wrap(noop_fold_ty), + fold_mod: noop_fold_mod, + fold_foreign_mod: noop_fold_foreign_mod, + fold_variant: wrap(noop_fold_variant), + fold_ident: noop_fold_ident, + fold_path: noop_fold_path, + fold_local: wrap(noop_fold_local), + map_exprs: noop_map_exprs, + new_id: noop_id, + new_span: noop_span + } } pub impl ast_fold for ast_fold_fns { /* naturally, a macro to write these would be nice */ - fn fold_crate(c: crate) -> crate { - let (n, s) = (self.fold_crate)(c.node, c.span, self as ast_fold); + fn fold_crate(c: &crate) -> crate { + let (n, s) = (self.fold_crate)(&c.node, c.span, self as ast_fold); spanned { node: n, span: (self.new_span)(s) } } - fn fold_view_item(&&x: @view_item) -> + fn fold_view_item(x: @view_item) -> @view_item { @ast::view_item { node: (self.fold_view_item)(x.node, self as ast_fold), @@ -710,14 +796,13 @@ pub impl ast_fold for ast_fold_fns { span: (self.new_span)(x.span), } } - fn fold_foreign_item(&&x: @foreign_item) - -> @foreign_item { - return (self.fold_foreign_item)(x, self as ast_fold); + fn fold_foreign_item(x: @foreign_item) -> @foreign_item { + (self.fold_foreign_item)(x, self as ast_fold) } - fn fold_item(&&i: @item) -> Option<@item> { - return (self.fold_item)(i, self as ast_fold); + fn fold_item(i: @item) -> Option<@item> { + (self.fold_item)(i, self as ast_fold) } - fn fold_struct_field(&&sf: @struct_field) -> @struct_field { + fn fold_struct_field(sf: @struct_field) -> @struct_field { @spanned { node: ast::struct_field_ { kind: copy sf.node.kind, @@ -727,39 +812,37 @@ pub impl ast_fold for ast_fold_fns { span: (self.new_span)(sf.span), } } - fn fold_item_underscore(i: item_) -> - item_ { - return (self.fold_item_underscore)(i, self as ast_fold); + fn fold_item_underscore(i: &item_) -> item_ { + (self.fold_item_underscore)(i, self as ast_fold) } - fn fold_method(&&x: @method) - -> @method { - return (self.fold_method)(x, self as ast_fold); + fn fold_method(x: @method) -> @method { + (self.fold_method)(x, self as ast_fold) } - fn fold_block(x: blk) -> blk { - let (n, s) = (self.fold_block)(x.node, x.span, self as ast_fold); + fn fold_block(x: &blk) -> blk { + let (n, s) = (self.fold_block)(&x.node, x.span, self as ast_fold); spanned { node: n, span: (self.new_span)(s) } } - fn fold_stmt(&&x: @stmt) -> @stmt { - let (n, s) = (self.fold_stmt)(x.node, x.span, self as ast_fold); + fn fold_stmt(x: &stmt) -> @stmt { + let (n, s) = (self.fold_stmt)(&x.node, x.span, self as ast_fold); @spanned { node: n, span: (self.new_span)(s) } } - fn fold_arm(x: arm) -> arm { - return (self.fold_arm)(x, self as ast_fold); + fn fold_arm(x: &arm) -> arm { + (self.fold_arm)(x, self as ast_fold) } - fn fold_pat(&&x: @pat) -> @pat { - let (n, s) = (self.fold_pat)(x.node, x.span, self as ast_fold); + fn fold_pat(x: @pat) -> @pat { + let (n, s) = (self.fold_pat)(&x.node, x.span, self as ast_fold); @pat { id: (self.new_id)(x.id), node: n, span: (self.new_span)(s), } } - fn fold_decl(&&x: @decl) -> @decl { - let (n, s) = (self.fold_decl)(x.node, x.span, self as ast_fold); + fn fold_decl(x: @decl) -> @decl { + let (n, s) = (self.fold_decl)(&x.node, x.span, self as ast_fold); @spanned { node: n, span: (self.new_span)(s) } } - fn fold_expr(&&x: @expr) -> @expr { - let (n, s) = (self.fold_expr)(x.node, x.span, self as ast_fold); + fn fold_expr(x: @expr) -> @expr { + let (n, s) = (self.fold_expr)(&x.node, x.span, self as ast_fold); @expr { id: (self.new_id)(x.id), callee_id: (self.new_id)(x.callee_id), @@ -767,37 +850,35 @@ pub impl ast_fold for ast_fold_fns { span: (self.new_span)(s), } } - fn fold_ty(&&x: @Ty) -> @Ty { - let (n, s) = (self.fold_ty)(x.node, x.span, self as ast_fold); + fn fold_ty(x: @Ty) -> @Ty { + let (n, s) = (self.fold_ty)(&x.node, x.span, self as ast_fold); @Ty { id: (self.new_id)(x.id), node: n, span: (self.new_span)(s), } } - fn fold_mod(x: _mod) -> _mod { - return (self.fold_mod)(x, self as ast_fold); + fn fold_mod(x: &_mod) -> _mod { + (self.fold_mod)(x, self as ast_fold) } - fn fold_foreign_mod(x: foreign_mod) -> - foreign_mod { - return (self.fold_foreign_mod)(x, self as ast_fold); + fn fold_foreign_mod(x: &foreign_mod) -> foreign_mod { + (self.fold_foreign_mod)(x, self as ast_fold) } - fn fold_variant(x: variant) -> - variant { - let (n, s) = (self.fold_variant)(x.node, x.span, self as ast_fold); + fn fold_variant(x: &variant) -> variant { + let (n, s) = (self.fold_variant)(&x.node, x.span, self as ast_fold); spanned { node: n, span: (self.new_span)(s) } } - fn fold_ident(&&x: ident) -> ident { - return (self.fold_ident)(x, self as ast_fold); + fn fold_ident(x: ident) -> ident { + (self.fold_ident)(x, self as ast_fold) } - fn fold_path(&&x: @path) -> @path { - @(self.fold_path)(*x, self as ast_fold) + fn fold_path(x: @path) -> @path { + @(self.fold_path)(x, self as ast_fold) } - fn fold_local(&&x: @local) -> @local { - let (n, s) = (self.fold_local)(x.node, x.span, self as ast_fold); + fn fold_local(x: @local) -> @local { + let (n, s) = (self.fold_local)(&x.node, x.span, self as ast_fold); @spanned { node: n, span: (self.new_span)(s) } } - fn map_exprs(f: fn@(&&v: @expr) -> @expr, e: ~[@expr]) -> ~[@expr] { + fn map_exprs(f: fn@(@expr) -> @expr, e: &[@expr]) -> ~[@expr] { (self.map_exprs)(f, e) } fn new_id(node_id: ast::node_id) -> node_id { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6230b0465dc..b4773fe2f97 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -38,8 +38,8 @@ use core::u64; use core::vec; // The @ps is stored here to prevent recursive type. -pub enum ann_node { - node_block(@ps, ast::blk), +pub enum ann_node/& { + node_block(@ps, &ast::blk), node_item(@ps, @ast::item), node_expr(@ps, @ast::expr), node_pat(@ps, @ast::pat), @@ -183,7 +183,7 @@ pub fn fun_to_str(decl: ast::fn_decl, name: ast::ident, } } -pub fn block_to_str(blk: ast::blk, intr: @ident_interner) -> ~str { +pub fn block_to_str(blk: &ast::blk, intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); // containing cbox, will be closed by print-block at } @@ -510,7 +510,7 @@ pub fn print_item(s: @ps, &&item: @ast::item) { item.vis ); word(s.s, ~" "); - print_block_with_attrs(s, (*body), item.attrs); + print_block_with_attrs(s, body, item.attrs); } ast::item_mod(_mod) => { head(s, visibility_qualified(item.vis, ~"mod")); @@ -607,8 +607,8 @@ pub fn print_item(s: @ps, &&item: @ast::item) { } word(s.s, ~" "); bopen(s); - for (*methods).each |meth| { - print_trait_method(s, *meth); + for methods.each |meth| { + print_trait_method(s, meth); } bclose(s, item.span); } @@ -741,7 +741,7 @@ pub fn print_struct(s: @ps, maybe_print_comment(s, dtor.span.lo); print_outer_attributes(s, dtor.node.attrs); head(s, ~"drop"); - print_block(s, dtor.node.body); + print_block(s, &dtor.node.body); } for struct_def.fields.each |field| { @@ -839,7 +839,7 @@ pub fn print_variant(s: @ps, v: ast::variant) { } } -pub fn print_ty_method(s: @ps, m: ast::ty_method) { +pub fn print_ty_method(s: @ps, m: &ast::ty_method) { hardbreak_if_not_bol(s); maybe_print_comment(s, m.span.lo); print_outer_attributes(s, m.attrs); @@ -849,10 +849,10 @@ pub fn print_ty_method(s: @ps, m: ast::ty_method) { word(s.s, ~";"); } -pub fn print_trait_method(s: @ps, m: ast::trait_method) { - match m { - required(ref ty_m) => print_ty_method(s, (*ty_m)), - provided(m) => print_method(s, m) +pub fn print_trait_method(s: @ps, m: &ast::trait_method) { + match *m { + required(ref ty_m) => print_ty_method(s, ty_m), + provided(m) => print_method(s, m) } } @@ -864,7 +864,7 @@ pub fn print_method(s: @ps, meth: @ast::method) { meth.ident, meth.tps, Some(meth.self_ty.node), meth.vis); word(s.s, ~" "); - print_block_with_attrs(s, meth.body, meth.attrs); + print_block_with_attrs(s, &meth.body, meth.attrs); } pub fn print_outer_attributes(s: @ps, attrs: ~[ast::attribute]) { @@ -935,22 +935,22 @@ pub fn print_stmt(s: @ps, st: ast::stmt) { maybe_print_trailing_comment(s, st.span, None); } -pub fn print_block(s: @ps, blk: ast::blk) { +pub fn print_block(s: @ps, blk: &ast::blk) { print_possibly_embedded_block(s, blk, block_normal, indent_unit); } -pub fn print_block_unclosed(s: @ps, blk: ast::blk) { +pub fn print_block_unclosed(s: @ps, blk: &ast::blk) { print_possibly_embedded_block_(s, blk, block_normal, indent_unit, ~[], false); } -pub fn print_block_unclosed_indent(s: @ps, blk: ast::blk, indented: uint) { +pub fn print_block_unclosed_indent(s: @ps, blk: &ast::blk, indented: uint) { print_possibly_embedded_block_(s, blk, block_normal, indented, ~[], false); } pub fn print_block_with_attrs(s: @ps, - blk: ast::blk, + blk: &ast::blk, attrs: ~[ast::attribute]) { print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs, true); @@ -959,7 +959,7 @@ pub fn print_block_with_attrs(s: @ps, pub enum embed_type { block_block_fn, block_normal, } pub fn print_possibly_embedded_block(s: @ps, - blk: ast::blk, + blk: &ast::blk, embedded: embed_type, indented: uint) { print_possibly_embedded_block_( @@ -967,7 +967,7 @@ pub fn print_possibly_embedded_block(s: @ps, } pub fn print_possibly_embedded_block_(s: @ps, - blk: ast::blk, + blk: &ast::blk, embedded: embed_type, indented: uint, attrs: ~[ast::attribute], @@ -1002,7 +1002,7 @@ pub fn print_possibly_embedded_block_(s: @ps, (s.ann.post)(ann_node); } -pub fn print_if(s: @ps, test: @ast::expr, blk: ast::blk, +pub fn print_if(s: @ps, test: @ast::expr, blk: &ast::blk, elseopt: Option<@ast::expr>, chk: bool) { head(s, ~"if"); if chk { word_nbsp(s, ~"check"); } @@ -1020,7 +1020,7 @@ pub fn print_if(s: @ps, test: @ast::expr, blk: ast::blk, word(s.s, ~" else if "); print_expr(s, i); space(s.s); - print_block(s, (*t)); + print_block(s, t); do_else(s, e); } // "final else" @@ -1028,7 +1028,7 @@ pub fn print_if(s: @ps, test: @ast::expr, blk: ast::blk, cbox(s, indent_unit - 1u); ibox(s, 0u); word(s.s, ~" else "); - print_block(s, (*b)); + print_block(s, b); } // BLEAH, constraints would be great here _ => { @@ -1263,13 +1263,13 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { print_type_ex(s, ty, true); } ast::expr_if(test, ref blk, elseopt) => { - print_if(s, test, (*blk), elseopt, false); + print_if(s, test, blk, elseopt, false); } ast::expr_while(test, ref blk) => { head(s, ~"while"); print_expr(s, test); space(s.s); - print_block(s, (*blk)); + print_block(s, blk); } ast::expr_loop(ref blk, opt_ident) => { head(s, ~"loop"); @@ -1278,7 +1278,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { print_ident(s, *ident); word_space(s, ~":"); }); - print_block(s, (*blk)); + print_block(s, blk); } ast::expr_match(expr, ref arms) => { cbox(s, match_indent_unit); @@ -1323,7 +1323,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { ast::expr_block(ref blk) => { // the block will close the pattern's ibox print_block_unclosed_indent( - s, (*blk), match_indent_unit); + s, blk, match_indent_unit); } _ => { end(s); // close the ibox for the pattern @@ -1340,7 +1340,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { } } else { // the block will close the pattern's ibox - print_block_unclosed_indent(s, arm.body, match_indent_unit); + print_block_unclosed_indent(s, &arm.body, match_indent_unit); } } bclose_(s, expr.span, match_indent_unit); @@ -1354,7 +1354,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { Some(sigil), ast::inherited); print_fn_args_and_ret(s, /* FIXME (#2543) */ copy *decl, None); space(s.s); - print_block(s, (*body)); + print_block(s, body); } ast::expr_fn_block(ref decl, ref body) => { // in do/for blocks we don't want to show an empty @@ -1365,16 +1365,16 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { print_fn_block_args(s, /* FIXME (#2543) */ copy *decl); space(s.s); // } - assert (*body).node.stmts.is_empty(); - assert (*body).node.expr.is_some(); + assert body.node.stmts.is_empty(); + assert body.node.expr.is_some(); // we extract the block, so as not to create another set of boxes - match (*body).node.expr.get().node { + match body.node.expr.get().node { ast::expr_block(ref blk) => { - print_block_unclosed(s, (*blk)); + print_block_unclosed(s, blk); } _ => { // this is a bare expression - print_expr(s, (*body).node.expr.get()); + print_expr(s, body.node.expr.get()); end(s); // need to close a box } } @@ -1394,7 +1394,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { cbox(s, indent_unit); // head-box, will be closed by print-block after { ibox(s, 0u); - print_block(s, (*blk)); + print_block(s, blk); } ast::expr_copy(e) => { word_space(s, ~"copy"); print_expr(s, e); } ast::expr_assign(lhs, rhs) => { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index d79a2bbf174..1b0842dbd86 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -67,18 +67,18 @@ pub struct Visitor<E> { visit_foreign_item: fn@(@foreign_item, E, vt<E>), visit_item: fn@(@item, E, vt<E>), visit_local: fn@(@local, E, vt<E>), - visit_block: fn@(ast::blk, E, vt<E>), + visit_block: fn@(&blk, E, vt<E>), visit_stmt: fn@(@stmt, E, vt<E>), - visit_arm: fn@(arm, E, vt<E>), + visit_arm: fn@(&arm, E, vt<E>), visit_pat: fn@(@pat, E, vt<E>), visit_decl: fn@(@decl, E, vt<E>), visit_expr: fn@(@expr, E, vt<E>), visit_expr_post: fn@(@expr, E, vt<E>), visit_ty: fn@(@Ty, E, vt<E>), visit_ty_params: fn@(&[ty_param], E, vt<E>), - visit_fn: fn@(&fn_kind, fn_decl, blk, span, node_id, E, vt<E>), - visit_ty_method: fn@(ty_method, E, vt<E>), - visit_trait_method: fn@(trait_method, E, vt<E>), + visit_fn: fn@(&fn_kind, &fn_decl, &blk, span, node_id, E, vt<E>), + visit_ty_method: fn@(&ty_method, E, vt<E>), + visit_trait_method: fn@(&trait_method, E, vt<E>), visit_struct_def: fn@(@struct_def, ident, &[ty_param], node_id, E, vt<E>), visit_struct_field: fn@(@struct_field, E, vt<E>), @@ -146,8 +146,8 @@ pub fn visit_item<E>(i: @item, e: E, v: vt<E>) { *tps, purity ), - /* FIXME (#2543) */ copy *decl, - *body, + decl, + body, i.span, i.id, e, @@ -190,7 +190,7 @@ pub fn visit_item<E>(i: @item, e: E, v: vt<E>) { (v.visit_ty_params)(*tps, e, v); for traits.each |p| { visit_path(p.path, e, v); } for (*methods).each |m| { - (v.visit_trait_method)(*m, e, v); + (v.visit_trait_method)(m, e, v); } } item_mac(ref m) => visit_mac((*m), e, v) @@ -198,12 +198,12 @@ pub fn visit_item<E>(i: @item, e: E, v: vt<E>) { } pub fn visit_enum_def<E>(enum_definition: ast::enum_def, - tps: ~[ast::ty_param], + tps: &[ast::ty_param], e: E, v: vt<E>) { for enum_definition.variants.each |vr| { match vr.node.kind { - tuple_variant_kind(variant_args) => { + tuple_variant_kind(ref variant_args) => { for variant_args.each |va| { (v.visit_ty)(va.ty, e, v); } } struct_variant_kind(struct_def) => { @@ -223,30 +223,31 @@ pub fn skip_ty<E>(_t: @Ty, _e: E, _v: vt<E>) {} pub fn visit_ty<E>(t: @Ty, e: E, v: vt<E>) { match t.node { - ty_box(mt) | ty_uniq(mt) | - ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => { - (v.visit_ty)(mt.ty, e, v); - } - ty_rec(ref flds) => for (*flds).each |f| { - (v.visit_ty)(f.node.mt.ty, e, v); - }, - ty_tup(ts) => for ts.each |tt| { - (v.visit_ty)(*tt, e, v); - }, - ty_closure(f) => { - for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } - (v.visit_ty)(f.decl.output, e, v); - } - ty_bare_fn(f) => { - for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } - (v.visit_ty)(f.decl.output, e, v); - } - ty_path(p, _) => visit_path(p, e, v), - ty_fixed_length_vec(mt, _) => (v.visit_ty)(mt.ty, e, v), - ty_nil | - ty_bot | - ty_mac(_) | - ty_infer => () + ty_box(mt) | ty_uniq(mt) | + ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => { + (v.visit_ty)(mt.ty, e, v); + }, + ty_rec(ref flds) => { + for flds.each |f| { + (v.visit_ty)(f.node.mt.ty, e, v); + } + }, + ty_tup(ref ts) => { + for ts.each |tt| { + (v.visit_ty)(*tt, e, v); + } + }, + ty_closure(ref f) => { + for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } + (v.visit_ty)(f.decl.output, e, v); + }, + ty_bare_fn(ref f) => { + for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } + (v.visit_ty)(f.decl.output, e, v); + }, + ty_path(p, _) => visit_path(p, e, v), + ty_fixed_length_vec(ref mt, _) => (v.visit_ty)(mt.ty, e, v), + ty_nil | ty_bot | ty_mac(_) | ty_infer => () } } @@ -256,49 +257,55 @@ pub fn visit_path<E>(p: @path, e: E, v: vt<E>) { pub fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { match p.node { - pat_enum(path, children) => { - visit_path(path, e, v); - do option::iter(&children) |children| { - for children.each |child| { (v.visit_pat)(*child, e, v); }} - } - pat_rec(fields, _) => for fields.each |f| { - (v.visit_pat)(f.pat, e, v) - }, - pat_struct(path, fields, _) => { - visit_path(path, e, v); - for fields.each |f| { - (v.visit_pat)(f.pat, e, v); + pat_enum(path, ref children) => { + visit_path(path, e, v); + do children.iter |children| { + for children.each |child| { (v.visit_pat)(*child, e, v); } + } } - } - pat_tup(elts) => for elts.each |elt| { - (v.visit_pat)(*elt, e, v) - }, - pat_box(inner) | pat_uniq(inner) | pat_region(inner) => - (v.visit_pat)(inner, e, v), - pat_ident(_, path, inner) => { - visit_path(path, e, v); - do option::iter(&inner) |subpat| { (v.visit_pat)(*subpat, e, v)}; - } - pat_lit(ex) => (v.visit_expr)(ex, e, v), - pat_range(e1, e2) => { - (v.visit_expr)(e1, e, v); - (v.visit_expr)(e2, e, v); - } - pat_wild => (), - pat_vec(elts, tail) => { - for elts.each |elt| { - (v.visit_pat)(*elt, e, v); + pat_rec(ref fields, _) => { + for fields.each |f| { + (v.visit_pat)(f.pat, e, v) + } + }, + pat_struct(path, ref fields, _) => { + visit_path(path, e, v); + for fields.each |f| { + (v.visit_pat)(f.pat, e, v); + } + } + pat_tup(ref elts) => { + for elts.each |elt| { + (v.visit_pat)(*elt, e, v) + } + }, + pat_box(inner) | pat_uniq(inner) | pat_region(inner) => { + (v.visit_pat)(inner, e, v) + }, + pat_ident(_, path, ref inner) => { + visit_path(path, e, v); + do inner.iter |subpat| { (v.visit_pat)(*subpat, e, v) } } - do option::iter(&tail) |tail| { - (v.visit_pat)(*tail, e, v); + pat_lit(ex) => (v.visit_expr)(ex, e, v), + pat_range(e1, e2) => { + (v.visit_expr)(e1, e, v); + (v.visit_expr)(e2, e, v); + } + pat_wild => (), + pat_vec(ref elts, ref tail) => { + for elts.each |elt| { + (v.visit_pat)(*elt, e, v); + } + do tail.iter |tail| { + (v.visit_pat)(*tail, e, v); + } } - } } } pub fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) { match ni.node { - foreign_item_fn(fd, _, ref tps) => { + foreign_item_fn(ref fd, _, ref tps) => { (v.visit_ty_params)(*tps, e, v); visit_fn_decl(fd, e, v); } @@ -323,7 +330,7 @@ pub fn visit_ty_params<E>(tps: &[ty_param], e: E, v: vt<E>) { } } -pub fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) { +pub fn visit_fn_decl<E>(fd: &fn_decl, e: E, v: vt<E>) { for fd.inputs.each |a| { (v.visit_pat)(a.pat, e, v); (v.visit_ty)(a.ty, e, v); @@ -342,8 +349,8 @@ pub fn visit_method_helper<E>(m: &method, e: E, v: vt<E>) { m.tps, m ), - m.decl, - m.body, + &m.decl, + &m.body, m.span, m.id, e, @@ -360,8 +367,8 @@ pub fn visit_struct_dtor_helper<E>(dtor: struct_dtor, tps: &[ty_param], dtor.node.self_id, parent_id ), - ast_util::dtor_dec(), - dtor.node.body, + &ast_util::dtor_dec(), + &dtor.node.body, dtor.span, dtor.node.id, e, @@ -370,22 +377,22 @@ pub fn visit_struct_dtor_helper<E>(dtor: struct_dtor, tps: &[ty_param], } -pub fn visit_fn<E>(fk: &fn_kind, decl: fn_decl, body: blk, _sp: span, +pub fn visit_fn<E>(fk: &fn_kind, decl: &fn_decl, body: &blk, _sp: span, _id: node_id, e: E, v: vt<E>) { visit_fn_decl(decl, e, v); (v.visit_ty_params)(tps_of_fn(fk), e, v); (v.visit_block)(body, e, v); } -pub fn visit_ty_method<E>(m: ty_method, e: E, v: vt<E>) { +pub fn visit_ty_method<E>(m: &ty_method, e: E, v: vt<E>) { for m.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } (v.visit_ty_params)(m.tps, e, v); (v.visit_ty)(m.decl.output, e, v); } -pub fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) { - match m { - required(ref ty_m) => (v.visit_ty_method)((*ty_m), e, v), +pub fn visit_trait_method<E>(m: &trait_method, e: E, v: vt<E>) { + match *m { + required(ref ty_m) => (v.visit_ty_method)(ty_m, e, v), provided(m) => visit_method_helper(m, e, v) } } @@ -408,7 +415,7 @@ pub fn visit_struct_method<E>(m: @method, e: E, v: vt<E>) { visit_method_helper(m, e, v); } -pub fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) { +pub fn visit_block<E>(b: &blk, e: E, v: vt<E>) { for b.node.view_items.each |vi| { (v.visit_view_item)(*vi, e, v); } @@ -429,10 +436,12 @@ pub fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { pub fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { match d.node { - decl_local(locs) => for locs.each |loc| { - (v.visit_local)(*loc, e, v) - }, - decl_item(it) => (v.visit_item)(it, e, v) + decl_local(ref locs) => { + for locs.each |loc| { + (v.visit_local)(*loc, e, v) + } + }, + decl_item(it) => (v.visit_item)(it, e, v) } } @@ -440,7 +449,7 @@ pub fn visit_expr_opt<E>(eo: Option<@expr>, e: E, v: vt<E>) { match eo { None => (), Some(ex) => (v.visit_expr)(ex, e, v) } } -pub fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) { +pub fn visit_exprs<E>(exprs: &[@expr], e: E, v: vt<E>) { for exprs.each |ex| { (v.visit_expr)(*ex, e, v); } } @@ -450,112 +459,121 @@ pub fn visit_mac<E>(_m: mac, _e: E, _v: vt<E>) { pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { match ex.node { - expr_vstore(x, _) => (v.visit_expr)(x, e, v), - expr_vec(es, _) => visit_exprs(es, e, v), - expr_repeat(element, count, _) => { - (v.visit_expr)(element, e, v); - (v.visit_expr)(count, e, v); - } - expr_rec(ref flds, base) => { - for (*flds).each |f| { (v.visit_expr)(f.node.expr, e, v); } - visit_expr_opt(base, e, v); - } - expr_struct(p, ref flds, base) => { - visit_path(p, e, v); - for (*flds).each |f| { (v.visit_expr)(f.node.expr, e, v); } - visit_expr_opt(base, e, v); - } - expr_tup(elts) => for elts.each |el| { (v.visit_expr)(*el, e, v); }, - expr_call(callee, args, _) => { - visit_exprs(args, e, v); - (v.visit_expr)(callee, e, v); - } - expr_method_call(callee, _, tys, args, _) => { - visit_exprs(args, e, v); - for tys.each |tp| { (v.visit_ty)(*tp, e, v); } - (v.visit_expr)(callee, e, v); - } - expr_binary(_, a, b) => { - (v.visit_expr)(a, e, v); (v.visit_expr)(b, e, v); - } - expr_addr_of(_, x) | expr_unary(_, x) | - expr_loop_body(x) | expr_do_body(x) | - expr_assert(x) => (v.visit_expr)(x, e, v), - expr_lit(_) => (), - expr_cast(x, t) => { (v.visit_expr)(x, e, v); (v.visit_ty)(t, e, v); } - expr_if(x, ref b, eo) => { - (v.visit_expr)(x, e, v); - (v.visit_block)((*b), e, v); - visit_expr_opt(eo, e, v); - } - expr_while(x, ref b) => { - (v.visit_expr)(x, e, v); - (v.visit_block)((*b), e, v); - } - expr_loop(ref b, _) => (v.visit_block)((*b), e, v), - expr_match(x, ref arms) => { - (v.visit_expr)(x, e, v); - for (*arms).each |a| { (v.visit_arm)(*a, e, v); } - } - expr_fn(proto, ref decl, ref body, _) => { - (v.visit_fn)( - &fk_anon(proto), - /* FIXME (#2543) */ copy *decl, - *body, - ex.span, - ex.id, - e, - v - ); - } - expr_fn_block(ref decl, ref body) => { - (v.visit_fn)( - &fk_fn_block, - /* FIXME (#2543) */ copy *decl, - *body, - ex.span, - ex.id, - e, - v - ); - } - expr_block(ref b) => (v.visit_block)((*b), e, v), - expr_assign(a, b) => { - (v.visit_expr)(b, e, v); - (v.visit_expr)(a, e, v); - } - expr_copy(a) => (v.visit_expr)(a, e, v), - expr_swap(a, b) => { (v.visit_expr)(a, e, v); (v.visit_expr)(b, e, v); } - expr_assign_op(_, a, b) => { - (v.visit_expr)(b, e, v); - (v.visit_expr)(a, e, v); - } - expr_field(x, _, tys) => { - (v.visit_expr)(x, e, v); - for tys.each |tp| { (v.visit_ty)(*tp, e, v); } - } - expr_index(a, b) => { - (v.visit_expr)(a, e, v); - (v.visit_expr)(b, e, v); - } - expr_path(p) => visit_path(p, e, v), - expr_break(_) => (), - expr_again(_) => (), - expr_ret(eo) => visit_expr_opt(eo, e, v), - expr_log(_, lv, x) => { - (v.visit_expr)(lv, e, v); - (v.visit_expr)(x, e, v); - } - expr_mac(ref mac) => visit_mac((*mac), e, v), - expr_paren(x) => (v.visit_expr)(x, e, v), + expr_vstore(x, _) => (v.visit_expr)(x, e, v), + expr_vec(ref es, _) => visit_exprs(*es, e, v), + expr_repeat(element, count, _) => { + (v.visit_expr)(element, e, v); + (v.visit_expr)(count, e, v); + } + expr_rec(ref flds, base) => { + for flds.each |f| { (v.visit_expr)(f.node.expr, e, v); } + visit_expr_opt(base, e, v); + } + expr_struct(p, ref flds, base) => { + visit_path(p, e, v); + for flds.each |f| { (v.visit_expr)(f.node.expr, e, v); } + visit_expr_opt(base, e, v); + } + expr_tup(ref elts) => { + for elts.each |el| { (v.visit_expr)(*el, e, v) } + } + expr_call(callee, ref args, _) => { + visit_exprs(*args, e, v); + (v.visit_expr)(callee, e, v); + } + expr_method_call(callee, _, ref tys, ref args, _) => { + visit_exprs(*args, e, v); + for tys.each |tp| { (v.visit_ty)(*tp, e, v); } + (v.visit_expr)(callee, e, v); + } + expr_binary(_, a, b) => { + (v.visit_expr)(a, e, v); + (v.visit_expr)(b, e, v); + } + expr_addr_of(_, x) | expr_unary(_, x) | + expr_loop_body(x) | expr_do_body(x) | + expr_assert(x) => (v.visit_expr)(x, e, v), + expr_lit(_) => (), + expr_cast(x, t) => { + (v.visit_expr)(x, e, v); + (v.visit_ty)(t, e, v); + } + expr_if(x, ref b, eo) => { + (v.visit_expr)(x, e, v); + (v.visit_block)(b, e, v); + visit_expr_opt(eo, e, v); + } + expr_while(x, ref b) => { + (v.visit_expr)(x, e, v); + (v.visit_block)(b, e, v); + } + expr_loop(ref b, _) => (v.visit_block)(b, e, v), + expr_match(x, ref arms) => { + (v.visit_expr)(x, e, v); + for arms.each |a| { (v.visit_arm)(a, e, v); } + } + expr_fn(proto, ref decl, ref body, _) => { + (v.visit_fn)( + &fk_anon(proto), + decl, + body, + ex.span, + ex.id, + e, + v + ); + } + expr_fn_block(ref decl, ref body) => { + (v.visit_fn)( + &fk_fn_block, + decl, + body, + ex.span, + ex.id, + e, + v + ); + } + expr_block(ref b) => (v.visit_block)(b, e, v), + expr_assign(a, b) => { + (v.visit_expr)(b, e, v); + (v.visit_expr)(a, e, v); + } + expr_copy(a) => (v.visit_expr)(a, e, v), + expr_swap(a, b) => { + (v.visit_expr)(a, e, v); + (v.visit_expr)(b, e, v); + } + expr_assign_op(_, a, b) => { + (v.visit_expr)(b, e, v); + (v.visit_expr)(a, e, v); + } + expr_field(x, _, ref tys) => { + (v.visit_expr)(x, e, v); + for tys.each |tp| { (v.visit_ty)(*tp, e, v); } + } + expr_index(a, b) => { + (v.visit_expr)(a, e, v); + (v.visit_expr)(b, e, v); + } + expr_path(p) => visit_path(p, e, v), + expr_break(_) => (), + expr_again(_) => (), + expr_ret(eo) => visit_expr_opt(eo, e, v), + expr_log(_, lv, x) => { + (v.visit_expr)(lv, e, v); + (v.visit_expr)(x, e, v); + } + expr_mac(ref mac) => visit_mac((*mac), e, v), + expr_paren(x) => (v.visit_expr)(x, e, v), } (v.visit_expr_post)(ex, e, v); } -pub fn visit_arm<E>(a: arm, e: E, v: vt<E>) { +pub fn visit_arm<E>(a: &arm, e: E, v: vt<E>) { for a.pats.each |p| { (v.visit_pat)(*p, e, v); } visit_expr_opt(a.guard, e, v); - (v.visit_block)(a.body, e, v); + (v.visit_block)(&a.body, e, v); } // Simpler, non-context passing interface. Always walks the whole tree, simply @@ -567,18 +585,18 @@ pub struct SimpleVisitor { visit_foreign_item: fn@(@foreign_item), visit_item: fn@(@item), visit_local: fn@(@local), - visit_block: fn@(ast::blk), + visit_block: fn@(&blk), visit_stmt: fn@(@stmt), - visit_arm: fn@(arm), + visit_arm: fn@(&arm), visit_pat: fn@(@pat), visit_decl: fn@(@decl), visit_expr: fn@(@expr), visit_expr_post: fn@(@expr), visit_ty: fn@(@Ty), visit_ty_params: fn@(&[ty_param]), - visit_fn: fn@(&fn_kind, fn_decl, blk, span, node_id), - visit_ty_method: fn@(ty_method), - visit_trait_method: fn@(trait_method), + visit_fn: fn@(&fn_kind, &fn_decl, &blk, span, node_id), + visit_ty_method: fn@(&ty_method), + visit_trait_method: fn@(&trait_method), visit_struct_def: fn@(@struct_def, ident, &[ty_param], node_id), visit_struct_field: fn@(@struct_field), visit_struct_method: fn@(@method) @@ -604,10 +622,10 @@ pub fn default_simple_visitor() -> @SimpleVisitor { visit_expr_post: |_e| { }, visit_ty: simple_ignore_ty, visit_ty_params: fn@(_ps: &[ty_param]) { }, - visit_fn: fn@(_fk: &fn_kind, _d: fn_decl, _b: blk, _sp: span, + visit_fn: fn@(_fk: &fn_kind, _d: &fn_decl, _b: &blk, _sp: span, _id: node_id) { }, - visit_ty_method: fn@(_m: ty_method) { }, - visit_trait_method: fn@(_m: trait_method) { }, + visit_ty_method: fn@(_m: &ty_method) { }, + visit_trait_method: fn@(_m: &trait_method) { }, visit_struct_def: fn@(_sd: @struct_def, _nm: ident, _tps: &[ty_param], _id: node_id) { }, visit_struct_field: fn@(_f: @struct_field) { }, @@ -644,7 +662,7 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { f(l); visit_local(l, e, v); } - fn v_block(f: fn@(ast::blk), bl: ast::blk, &&e: (), v: vt<()>) { + fn v_block(f: fn@(&blk), bl: &blk, &&e: (), v: vt<()>) { f(bl); visit_block(bl, e, v); } @@ -652,7 +670,7 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { f(st); visit_stmt(st, e, v); } - fn v_arm(f: fn@(arm), a: arm, &&e: (), v: vt<()>) { + fn v_arm(f: fn@(&arm), a: &arm, &&e: (), v: vt<()>) { f(a); visit_arm(a, e, v); } @@ -675,11 +693,11 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { f(ty); visit_ty(ty, e, v); } - fn v_ty_method(f: fn@(ty_method), ty: ty_method, &&e: (), v: vt<()>) { + fn v_ty_method(f: fn@(&ty_method), ty: &ty_method, &&e: (), v: vt<()>) { f(ty); visit_ty_method(ty, e, v); } - fn v_trait_method(f: fn@(trait_method), m: trait_method, &&e: (), + fn v_trait_method(f: fn@(&trait_method), m: &trait_method, &&e: (), v: vt<()>) { f(m); visit_trait_method(m, e, v); @@ -697,9 +715,16 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { f(ps); visit_ty_params(ps, e, v); } - fn v_fn(f: fn@(&fn_kind, fn_decl, blk, span, node_id), - fk: &fn_kind, decl: fn_decl, body: blk, sp: span, - id: node_id, &&e: (), v: vt<()>) { + fn v_fn( + f: fn@(&fn_kind, &fn_decl, &blk, span, node_id), + fk: &fn_kind, + decl: &fn_decl, + body: &blk, + sp: span, + id: node_id, + &&e: (), + v: vt<()> + ) { f(fk, decl, body, sp, id); visit_fn(fk, decl, body, sp, id, e, v); } |
