@@ -47,7 +47,6 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> copy_map {
47
47
copy_map: std:: map:: new_int_hash ( ) } ;
48
48
let v = @{ visit_fn: bind visit_fn ( cx, _, _, _, _, _, _, _) ,
49
49
visit_expr: bind visit_expr ( cx, _, _, _) ,
50
- visit_decl: bind visit_decl ( cx, _, _, _) ,
51
50
visit_block: bind visit_block ( cx, _, _, _)
52
51
with * visit:: default_visitor :: < scope > ( ) } ;
53
52
visit:: visit_crate ( * crate , { bs: [ ] , ret_style: ast:: return_val} ,
@@ -132,46 +131,38 @@ fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) {
132
131
if !handled { visit:: visit_expr ( ex, sc, v) ; }
133
132
}
134
133
135
- fn visit_decl ( cx : @ctx , d : @ast:: decl , sc : scope , v : vt < scope > ) {
136
- visit:: visit_decl ( d, sc, v) ;
137
- alt d. node {
138
- ast:: decl_local ( locs) {
139
- for ( _, loc) in locs {
140
- alt loc. node . init {
141
- some ( init) {
142
- if init. op == ast:: init_move {
143
- check_lval ( cx, init. expr , sc, v) ;
144
- }
145
- }
146
- none. { }
147
- }
148
- }
149
- }
150
- _ { }
151
- }
152
- }
153
-
154
134
fn visit_block ( cx : @ctx , b : ast:: blk , sc : scope , v : vt < scope > ) {
155
- let ref_locs = [ ] ;
135
+ let bs = sc . bs ;
156
136
for stmt in b. node . stmts {
157
137
alt stmt. node {
158
- ast:: stmt_decl ( @{ node: ast:: decl_local ( ls) , _} , _) {
159
- for ( st, loc) in ls {
138
+ ast:: stmt_decl ( @{ node: ast:: decl_item ( it) , _} , _) {
139
+ v. visit_item ( it, sc, v) ;
140
+ }
141
+ ast:: stmt_decl ( @{ node: ast:: decl_local ( locs) , _} , _) {
142
+ for ( st, loc) in locs {
160
143
if st == ast:: let_ref {
161
- ref_locs += [ loc] ;
144
+ add_bindings_for_let ( * cx, bs, loc) ;
145
+ sc = { bs: bs with sc} ;
146
+ }
147
+ alt loc. node . init {
148
+ some ( init) {
149
+ if init. op == ast:: init_move {
150
+ check_lval ( cx, init. expr , sc, v) ;
151
+ }
152
+ }
153
+ none. { }
162
154
}
163
155
}
164
156
}
165
- _ { }
157
+ ast:: stmt_expr ( ex, _) {
158
+ v. visit_expr ( ex, sc, v) ;
159
+ }
160
+ ast:: stmt_crate_directive ( cd) {
161
+ visit:: visit_crate_directive ( cd, sc, v) ;
162
+ }
166
163
}
167
164
}
168
- if vec:: len ( ref_locs) > 0 u {
169
- let bindings = sc. bs ;
170
- for loc in ref_locs { add_bindings_for_let ( * cx, bindings, loc) ; }
171
- visit:: visit_block ( b, { bs: bindings with sc} , v) ;
172
- } else {
173
- visit:: visit_block ( b, sc, v) ;
174
- }
165
+ visit:: visit_expr_opt ( b. node . expr , sc, v) ;
175
166
}
176
167
177
168
fn add_bindings_for_let ( cx : ctx , & bs: [ binding ] , loc : @ast:: local ) {
@@ -192,12 +183,14 @@ fn add_bindings_for_let(cx: ctx, &bs: [binding], loc: @ast::local) {
192
183
let ret_style = ty:: ty_fn_ret_style ( cx. tcx , fty) ;
193
184
if ast_util:: ret_by_ref ( ret_style) {
194
185
// FIXME pick right arg
195
- let arg_root = expr_root ( cx. tcx , args[ 0 ] , false ) ;
186
+ let arg = args[ 0 ] ;
187
+ let arg_root = expr_root ( cx. tcx , arg, false ) ;
196
188
root_var = path_def_id ( cx, arg_root. ex ) ;
197
189
if !is_none ( root_var) {
198
190
is_temp = false ;
199
191
if ret_style == ast:: return_ref ( true ) {
200
- outer_ds = [ @{ mut: true with * arg_root. ds [ 0 ] } ] ;
192
+ outer_ds = [ @{ mut: true , kind: unbox,
193
+ outer_t: ty:: expr_ty ( cx. tcx , arg) } ] ;
201
194
}
202
195
outer_ds = * arg_root. ds + outer_ds;
203
196
}
0 commit comments