File tree Expand file tree Collapse file tree 1 file changed +21
-14
lines changed Expand file tree Collapse file tree 1 file changed +21
-14
lines changed Original file line number Diff line number Diff line change 1
1
// A pass that annotates for each loops and functions with the free
2
2
// variables that they contain.
3
3
4
+ import syntax:: print:: pprust:: path_to_str;
4
5
import int;
5
6
import std:: map:: * ;
6
7
import option:: * ;
@@ -47,21 +48,27 @@ fn collect_freevars(def_map: resolve::def_map, blk: ast::blk)
47
48
visit:: visit_expr ( expr, depth + 1 , v) ;
48
49
}
49
50
ast:: expr_path ( path) {
50
- let def = def_map. get ( expr. id ) , i = 0 ;
51
- while i < depth {
52
- alt copy def {
53
- ast : : def_upvar ( _, inner, _) { def = * inner; }
54
- _ { break; }
51
+ let i = 0 ;
52
+ alt def_map. find ( expr. id ) {
53
+ none. { fail ( "Not found: " + path_to_str ( path) ) }
54
+ some ( df) {
55
+ let def = df;
56
+ while i < depth {
57
+ alt copy def {
58
+ ast : : def_upvar ( _, inner, _) { def = * inner; }
59
+ _ { break; }
60
+ }
61
+ i += 1 ;
62
+ }
63
+ if i == depth { // Made it to end of loop
64
+ let dnum = ast_util:: def_id_of_def ( def) . node ;
65
+ if !seen. contains_key ( dnum) {
66
+ * refs += [ @{ def: def, span: expr. span } ] ;
67
+ seen. insert ( dnum, ( ) ) ;
68
+ }
69
+ }
55
70
}
56
- i += 1 ;
57
- }
58
- if i == depth { // Made it to end of loop
59
- let dnum = ast_util:: def_id_of_def ( def) . node ;
60
- if !seen. contains_key ( dnum) {
61
- * refs += [ @{ def: def, span: expr. span } ] ;
62
- seen. insert ( dnum, ( ) ) ;
63
- }
64
- }
71
+ }
65
72
}
66
73
_ { visit : : visit_expr ( expr, depth, v) ; }
67
74
}
You can’t perform that action at this time.
0 commit comments