@@ -36,20 +36,25 @@ type scope = @[restrict];
36
36
37
37
tag local_info { arg( ast:: mode) ; objfield ( ast:: mutability) ; }
38
38
39
- type ctx = { tcx: ty:: ctxt, local_map: std:: map:: hashmap<node_id, local_info>} ;
39
+ type mut_map = std:: map:: hashmap < node_id , ( ) > ;
40
+ type ctx = { tcx : ty:: ctxt ,
41
+ local_map : std:: map:: hashmap < node_id , local_info > ,
42
+ mut_map : mut_map } ;
40
43
41
- fn check_crate ( tcx : ty:: ctxt , crate : & @ast:: crate ) {
44
+ fn check_crate ( tcx : ty:: ctxt , crate : & @ast:: crate ) -> mut_map {
42
45
// Stores information about object fields and function
43
46
// arguments that's otherwise not easily available.
44
- let cx = @{ tcx: tcx, local_map: std:: map:: new_int_hash ( ) } ;
45
- let v =
46
- @{ visit_fn: bind visit_fn ( cx, _, _, _, _, _, _, _) ,
47
- visit_item: bind visit_item ( cx, _, _, _) ,
48
- visit_expr: bind visit_expr ( cx, _, _, _) ,
49
- visit_decl: bind visit_decl ( cx, _, _, _)
50
- with * visit:: default_visitor :: < scope > ( ) } ;
47
+ let cx = @{ tcx: tcx,
48
+ local_map: std:: map:: new_int_hash ( ) ,
49
+ mut_map: std:: map:: new_int_hash ( ) } ;
50
+ let v = @{ visit_fn: bind visit_fn ( cx, _, _, _, _, _, _, _) ,
51
+ visit_item: bind visit_item ( cx, _, _, _) ,
52
+ visit_expr: bind visit_expr ( cx, _, _, _) ,
53
+ visit_decl: bind visit_decl ( cx, _, _, _)
54
+ with * visit:: default_visitor :: < scope > ( ) } ;
51
55
visit:: visit_crate ( * crate , @[ ] , visit:: mk_vt ( v) ) ;
52
56
tcx. sess . abort_if_errors ( ) ;
57
+ ret cx. mut_map ;
53
58
}
54
59
55
60
fn visit_fn ( cx : & @ctx , f : & ast:: _fn , _tp : & [ ast:: ty_param ] , _sp : & span ,
@@ -425,6 +430,7 @@ fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt<scope>) {
425
430
alt dest. node {
426
431
ast:: expr_path ( p) {
427
432
let dnum = ast:: def_id_of_def ( cx. tcx . def_map . get ( dest. id ) ) . node ;
433
+ cx. mut_map . insert ( dnum, ( ) ) ;
428
434
if is_immutable_alias ( * cx, sc, dnum) {
429
435
cx. tcx . sess . span_err ( dest. span , "assigning to immutable alias" ) ;
430
436
} else if is_immutable_objfield ( * cx, dnum) {
0 commit comments