@@ -15,13 +15,11 @@ import std::option::{some, none, is_none};
15
15
tag valid { valid; overwritten ( span, ast:: path) ; val_taken ( span, ast:: path) ; }
16
16
tag copied { not_allowed; copied; not_copied; }
17
17
18
- type restrict = @{ root_var: option:: t<node_id>,
19
- node_id: node_id,
18
+ type restrict = @{ node_id: node_id,
20
19
span: span,
21
20
local_id: uint,
22
- binding : option:: t<node_id>,
21
+ root_var : option:: t<node_id>,
23
22
unsafe_tys: [ ty:: t] ,
24
- depends_on: [ uint] ,
25
23
mutable ok: valid,
26
24
mutable copied: copied} ;
27
25
@@ -71,7 +69,7 @@ fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) {
71
69
let handled = true ;
72
70
alt ex. node {
73
71
ast:: expr_call ( f, args) {
74
- check_call ( * cx, f, args, sc ) ;
72
+ check_call ( * cx, f, args) ;
75
73
handled = false ;
76
74
}
77
75
ast:: expr_alt ( input, arms) { check_alt ( * cx, input, arms, sc, v) ; }
@@ -160,8 +158,7 @@ fn cant_copy(cx: ctx, r: restrict) -> bool {
160
158
} else { ret true ; }
161
159
}
162
160
163
- fn check_call ( cx : ctx , f : @ast:: expr , args : [ @ast:: expr ] , sc : scope ) ->
164
- [ restrict ] {
161
+ fn check_call ( cx : ctx , f : @ast:: expr , args : [ @ast:: expr ] ) -> [ restrict ] {
165
162
let fty = ty:: type_autoderef ( cx. tcx , ty:: expr_ty ( cx. tcx , f) ) ;
166
163
let arg_ts = ty:: ty_fn_args ( cx. tcx , fty) ;
167
164
let mut_roots: [ { arg : uint , node : node_id } ] = [ ] ;
@@ -180,13 +177,11 @@ fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr], sc: scope) ->
180
177
}
181
178
}
182
179
let root_var = path_def_id ( cx, root. ex ) ;
183
- restricts += [ @{ root_var: root_var,
184
- node_id: arg. id ,
180
+ restricts += [ @{ node_id: arg. id ,
185
181
span: arg. span ,
186
182
local_id: cx. next_local ,
187
- binding : none :: < node_id > ,
183
+ root_var : root_var ,
188
184
unsafe_tys: inner_mut ( root. ds ) ,
189
- depends_on: deps ( sc, root_var) ,
190
185
mutable ok: valid,
191
186
mutable copied: alt arg_t. mode {
192
187
ast:: by_move. { copied }
@@ -284,13 +279,11 @@ fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope,
284
279
}
285
280
}
286
281
for info in binding_info {
287
- new_sc += [ @{ root_var: root_var,
288
- node_id: info. id ,
282
+ new_sc += [ @{ node_id: info. id ,
289
283
span: info. span ,
290
284
local_id: cx. next_local ,
291
- binding : some ( info . id ) ,
285
+ root_var : root_var ,
292
286
unsafe_tys: info. unsafe ,
293
- depends_on: deps ( sc, root_var) ,
294
287
mutable ok: valid,
295
288
mutable copied: not_copied} ] ;
296
289
}
@@ -304,9 +297,18 @@ fn check_for_each(cx: ctx, local: @ast::local, call: @ast::expr,
304
297
v. visit_expr ( call, sc, v) ;
305
298
alt call. node {
306
299
ast:: expr_call ( f, args) {
307
- let restricts = check_call ( cx, f, args, sc) ;
300
+ let new_sc = * sc + check_call ( cx, f, args) ;
301
+ for proot in * pattern_roots ( cx. tcx , [ ] , local. node . pat ) {
302
+ new_sc += [ @{ node_id: proot. id ,
303
+ span: proot. span ,
304
+ local_id: cx. next_local ,
305
+ root_var : none:: < node_id > ,
306
+ unsafe_tys: inner_mut ( proot. ds ) ,
307
+ mutable ok: valid,
308
+ mutable copied: not_copied} ] ;
309
+ }
308
310
register_locals ( cx, local. node . pat ) ;
309
- visit:: visit_block ( blk, @( * sc + restricts ) , v) ;
311
+ visit:: visit_block ( blk, @new_sc , v) ;
310
312
}
311
313
}
312
314
}
@@ -330,13 +332,11 @@ fn check_for(cx: ctx, local: @ast::local, seq: @ast::expr, blk: ast::blk,
330
332
let root_var = path_def_id ( cx, root. ex ) ;
331
333
let new_sc = * sc;
332
334
for proot in * pattern_roots ( cx. tcx , ext_ds, local. node . pat ) {
333
- new_sc += [ @{ root_var: root_var,
334
- node_id: proot. id ,
335
+ new_sc += [ @{ node_id: proot. id ,
335
336
span: proot. span ,
336
337
local_id: cx. next_local ,
337
- binding : some ( proot . id ) ,
338
+ root_var : root_var ,
338
339
unsafe_tys: inner_mut ( proot. ds ) ,
339
- depends_on: deps ( sc, root_var) ,
340
340
mutable ok: valid,
341
341
mutable copied: not_copied} ] ;
342
342
}
@@ -360,7 +360,7 @@ fn check_var(cx: ctx, ex: @ast::expr, p: ast::path, id: ast::node_id,
360
360
r. ok = val_taken ( ex. span , p) ;
361
361
}
362
362
}
363
- } else if r. binding == some ( my_defnum) {
363
+ } else if r. node_id == my_defnum {
364
364
test_scope ( cx, sc, r, p) ;
365
365
}
366
366
}
@@ -387,9 +387,16 @@ fn check_assign(cx: @ctx, dest: @ast::expr, src: @ast::expr, sc: scope,
387
387
388
388
fn test_scope ( cx : ctx , sc : scope , r : restrict , p : ast:: path ) {
389
389
let prob = r. ok ;
390
- for dep: uint in r. depends_on {
391
- if prob != valid { break ; }
392
- prob = sc[ dep] . ok ;
390
+ alt r. root_var {
391
+ some ( dn) {
392
+ for other in * sc {
393
+ if other. node_id == dn {
394
+ prob = other. ok ;
395
+ if prob != valid { break ; }
396
+ }
397
+ }
398
+ }
399
+ _ { }
393
400
}
394
401
if prob != valid && cant_copy ( cx, r) {
395
402
let msg =
@@ -409,21 +416,6 @@ fn test_scope(cx: ctx, sc: scope, r: restrict, p: ast::path) {
409
416
}
410
417
}
411
418
412
- fn deps ( sc : scope , root : option:: t < node_id > ) -> [ uint ] {
413
- let result = [ ] ;
414
- alt root {
415
- some( dn) {
416
- let i = 0 u;
417
- for r: restrict in * sc {
418
- if r. binding == some ( dn) { result += [ i] ; }
419
- i += 1 u;
420
- }
421
- }
422
- _ { }
423
- }
424
- ret result;
425
- }
426
-
427
419
fn path_def ( cx : ctx , ex : @ast:: expr ) -> option:: t < ast:: def > {
428
420
ret alt ex. node {
429
421
ast:: expr_path ( _) { some ( cx. tcx . def_map . get ( ex. id ) ) }
0 commit comments