1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
22 pub fn check_crate(tcx: ty::ctxt, crate: @crate) {
23 visit::visit_crate(crate,
24 Context { in_loop: false, can_ret: true },
25 visit::mk_vt(@visit::Visitor {
26 visit_item: |i, _cx, v| {
27 visit::visit_item(i, Context {
32 visit_expr: |e: @expr, cx: Context, v: visit::vt<Context>| {
34 expr_while(e, ref b) => {
35 (v.visit_expr)(e, cx, v);
36 (v.visit_block)(b, Context { in_loop: true,.. cx }, v);
38 expr_loop(ref b, _) => {
39 (v.visit_block)(b, Context { in_loop: true,.. cx }, v);
41 expr_fn_block(_, ref b) => {
42 (v.visit_block)(b, Context {
47 expr_loop_body(@expr {node: expr_fn_block(_, ref b), _}) => {
48 let sigil = ty::ty_closure_sigil(ty::expr_ty(tcx, e));
49 let blk = (sigil == BorrowedSigil);
50 (v.visit_block)(b, Context {
57 tcx.sess.span_err(e.span, "`break` outside of loop");
62 tcx.sess.span_err(e.span, "`again` outside of loop");
67 tcx.sess.span_err(e.span, "`return` in block function");
69 visit::visit_expr_opt(oe, cx, v);
71 _ => visit::visit_expr(e, cx, v)
74 .. *visit::default_visitor()