Skip to content

Commit 8b468fd

Browse files
committed
---
yaml --- r: 85365 b: refs/heads/dist-snap c: 3563411 h: refs/heads/master i: 85363: 90267ae v: v3
1 parent ed6a32e commit 8b468fd

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 4127c67406d305f6c4fc452787d0a5ca8a3de049
9+
refs/heads/dist-snap: 356341192fdf8234b6a6ff8c3385ba227928ae9a
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/check_loop.rs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,64 @@
1212
use middle::ty;
1313

1414
use syntax::ast::*;
15-
use syntax::oldvisit;
15+
use syntax::visit;
16+
use syntax::visit::Visitor;
1617

1718
#[deriving(Clone)]
1819
pub struct Context {
1920
in_loop: bool,
2021
can_ret: bool
2122
}
2223

24+
struct CheckLoopVisitor {
25+
tcx: ty::ctxt,
26+
}
27+
2328
pub fn check_crate(tcx: ty::ctxt, crate: &Crate) {
24-
oldvisit::visit_crate(crate,
25-
(Context { in_loop: false, can_ret: true },
26-
oldvisit::mk_vt(@oldvisit::Visitor {
27-
visit_item: |i, (_cx, v)| {
28-
oldvisit::visit_item(i, (Context {
29+
visit::walk_crate(&mut CheckLoopVisitor { tcx: tcx },
30+
crate,
31+
Context { in_loop: false, can_ret: true });
32+
}
33+
34+
impl Visitor<Context> for CheckLoopVisitor {
35+
fn visit_item(&mut self, i:@item, _cx:Context) {
36+
visit::walk_item(self, i, Context {
2937
in_loop: false,
3038
can_ret: true
31-
}, v));
32-
},
33-
visit_expr: |e: @expr, (cx, v): (Context, oldvisit::vt<Context>)| {
39+
});
40+
}
41+
42+
fn visit_expr(&mut self, e:@expr, cx:Context) {
43+
3444
match e.node {
3545
expr_while(e, ref b) => {
36-
(v.visit_expr)(e, (cx, v));
37-
(v.visit_block)(b, (Context { in_loop: true,.. cx }, v));
46+
self.visit_expr(e, cx);
47+
self.visit_block(b, Context { in_loop: true,.. cx });
3848
}
3949
expr_loop(ref b, _) => {
40-
(v.visit_block)(b, (Context { in_loop: true,.. cx }, v));
50+
self.visit_block(b, Context { in_loop: true,.. cx });
4151
}
4252
expr_fn_block(_, ref b) => {
43-
(v.visit_block)(b, (Context {
44-
in_loop: false,
45-
can_ret: false
46-
}, v));
53+
self.visit_block(b, Context { in_loop: false, can_ret: false });
4754
}
4855
expr_break(_) => {
4956
if !cx.in_loop {
50-
tcx.sess.span_err(e.span, "`break` outside of loop");
57+
self.tcx.sess.span_err(e.span, "`break` outside of loop");
5158
}
5259
}
5360
expr_again(_) => {
5461
if !cx.in_loop {
55-
tcx.sess.span_err(e.span, "`loop` outside of loop");
62+
self.tcx.sess.span_err(e.span, "`loop` outside of loop");
5663
}
5764
}
5865
expr_ret(oe) => {
5966
if !cx.can_ret {
60-
tcx.sess.span_err(e.span, "`return` in block function");
67+
self.tcx.sess.span_err(e.span, "`return` in block function");
6168
}
62-
oldvisit::visit_expr_opt(oe, (cx, v));
69+
visit::walk_expr_opt(self, oe, cx);
6370
}
64-
_ => oldvisit::visit_expr(e, (cx, v))
71+
_ => visit::walk_expr(self, e, cx)
6572
}
66-
},
67-
.. *oldvisit::default_visitor()
68-
})));
73+
74+
}
6975
}

0 commit comments

Comments
 (0)