@@ -66,7 +66,7 @@ pub enum categorization {
66
66
cat_local( ast:: node_id ) , // local variable
67
67
cat_arg( ast:: node_id ) , // formal argument
68
68
cat_deref( cmt , uint , ptr_kind ) , // deref of a ptr
69
- cat_interior( cmt , interior_kind ) , // something interior
69
+ cat_interior( cmt , interior_kind ) , // something interior
70
70
cat_discr( cmt , ast:: node_id ) , // match discriminant (see preserve())
71
71
cat_self( ast:: node_id ) , // explicit `self`
72
72
}
@@ -94,8 +94,7 @@ pub enum interior_kind {
94
94
interior_anon_field, // anonymous field (in e.g.
95
95
// struct Foo(int, int);
96
96
interior_variant( ast:: def_id ) , // internals to a variant of given enum
97
- interior_field( ast:: ident , // name of field
98
- ast:: mutability ) , // declared mutability of field
97
+ interior_field( ast:: ident ) , // name of field
99
98
interior_index( ty:: t , // type of vec/str/etc being deref'd
100
99
ast:: mutability ) // mutability of vec content
101
100
}
@@ -395,8 +394,7 @@ pub impl mem_categorization_ctxt {
395
394
assert ! ( !self . method_map. contains_key( & expr. id) ) ;
396
395
397
396
let base_cmt = self . cat_expr ( base) ;
398
- self . cat_field ( expr, base_cmt, f_name,
399
- self . expr_ty ( expr) , expr. id )
397
+ self . cat_field ( expr, base_cmt, f_name, self . expr_ty ( expr) )
400
398
}
401
399
402
400
ast:: expr_index( base, _) => {
@@ -405,7 +403,7 @@ pub impl mem_categorization_ctxt {
405
403
}
406
404
407
405
let base_cmt = self . cat_expr ( base) ;
408
- self . cat_index ( expr, base_cmt)
406
+ self . cat_index ( expr, base_cmt, 0 )
409
407
}
410
408
411
409
ast:: expr_path( _) => {
@@ -579,16 +577,12 @@ pub impl mem_categorization_ctxt {
579
577
node : N ,
580
578
base_cmt : cmt ,
581
579
f_name : ast:: ident ,
582
- f_ty : ty:: t ,
583
- field_id : ast:: node_id ) -> cmt {
584
- let f_mutbl = m_imm;
585
- let m = self . inherited_mutability ( base_cmt. mutbl , f_mutbl) ;
586
- let f_interior = interior_field ( f_name, f_mutbl) ;
580
+ f_ty : ty:: t ) -> cmt {
587
581
@cmt_ {
588
582
id : node. id ( ) ,
589
583
span : node. span ( ) ,
590
- cat : cat_interior ( base_cmt, f_interior ) ,
591
- mutbl : m ,
584
+ cat : cat_interior ( base_cmt, interior_field ( f_name ) ) ,
585
+ mutbl : base_cmt . mutbl . inherit ( ) ,
592
586
ty : f_ty
593
587
}
594
588
}
@@ -670,7 +664,39 @@ pub impl mem_categorization_ctxt {
670
664
671
665
fn cat_index < N : ast_node > ( & self ,
672
666
elt : N ,
673
- base_cmt : cmt ) -> cmt {
667
+ base_cmt : cmt ,
668
+ derefs : uint ) -> cmt {
669
+ //! Creates a cmt for an indexing operation (`[]`); this
670
+ //! indexing operation may occurs as part of an
671
+ //! AutoBorrowVec, which when converting a `~[]` to an `&[]`
672
+ //! effectively takes the address of the 0th element.
673
+ //!
674
+ //! One subtle aspect of indexing that may not be
675
+ //! immediately obvious: for anything other than a fixed-length
676
+ //! vector, an operation like `x[y]` actually consists of two
677
+ //! disjoint (from the point of view of borrowck) operations.
678
+ //! The first is a deref of `x` to create a pointer `p` that points
679
+ //! at the first element in the array. The second operation is
680
+ //! an index which adds `y*sizeof(T)` to `p` to obtain the
681
+ //! pointer to `x[y]`. `cat_index` will produce a resulting
682
+ //! cmt containing both this deref and the indexing,
683
+ //! presuming that `base_cmt` is not of fixed-length type.
684
+ //!
685
+ //! In the event that a deref is needed, the "deref count"
686
+ //! is taken from the parameter `derefs`. See the comment
687
+ //! on the def'n of `root_map_key` in borrowck/mod.rs
688
+ //! for more details about deref counts; the summary is
689
+ //! that `derefs` should be 0 for an explicit indexing
690
+ //! operation and N+1 for an indexing that is part of
691
+ //! an auto-adjustment, where N is the number of autoderefs
692
+ //! in that adjustment.
693
+ //!
694
+ //! # Parameters
695
+ //! - `elt`: the AST node being indexed
696
+ //! - `base_cmt`: the cmt of `elt`
697
+ //! - `derefs`: the deref number to be used for
698
+ //! the implicit index deref, if any (see above)
699
+
674
700
let mt = match ty:: index ( base_cmt. ty ) {
675
701
Some ( mt) => mt,
676
702
None => {
@@ -698,7 +724,7 @@ pub impl mem_categorization_ctxt {
698
724
let deref_cmt = @cmt_ {
699
725
id : elt. id ( ) ,
700
726
span : elt. span ( ) ,
701
- cat : cat_deref ( base_cmt, 0 u , ptr) ,
727
+ cat : cat_deref ( base_cmt, derefs , ptr) ,
702
728
mutbl : m,
703
729
ty : mt. ty
704
730
} ;
@@ -854,8 +880,7 @@ pub impl mem_categorization_ctxt {
854
880
// {f1: p1, ..., fN: pN}
855
881
for field_pats. each |fp| {
856
882
let field_ty = self . pat_ty ( fp. pat ) ; // see (*)
857
- let cmt_field = self . cat_field ( pat, cmt, fp. ident ,
858
- field_ty, pat. id ) ;
883
+ let cmt_field = self . cat_field ( pat, cmt, fp. ident , field_ty) ;
859
884
self . cat_pattern ( cmt_field, fp. pat , op) ;
860
885
}
861
886
}
@@ -878,8 +903,8 @@ pub impl mem_categorization_ctxt {
878
903
}
879
904
880
905
ast:: pat_vec( ref before, slice, ref after) => {
906
+ let elt_cmt = self . cat_index ( pat, cmt, 0 ) ;
881
907
for before. each |& before_pat| {
882
- let elt_cmt = self . cat_index ( pat, cmt) ;
883
908
self . cat_pattern ( elt_cmt, before_pat, op) ;
884
909
}
885
910
for slice. each |& slice_pat| {
@@ -888,7 +913,6 @@ pub impl mem_categorization_ctxt {
888
913
self . cat_pattern ( slice_cmt, slice_pat, op) ;
889
914
}
890
915
for after. each |& after_pat| {
891
- let elt_cmt = self . cat_index ( pat, cmt) ;
892
916
self . cat_pattern ( elt_cmt, after_pat, op) ;
893
917
}
894
918
}
@@ -1110,7 +1134,7 @@ pub fn ptr_sigil(ptr: ptr_kind) -> ~str {
1110
1134
impl Repr for interior_kind {
1111
1135
fn repr(&self, tcx: ty::ctxt) -> ~str {
1112
1136
match *self {
1113
- interior_field(fld, _ ) => copy *tcx.sess.str_of(fld),
1137
+ interior_field(fld) => copy *tcx.sess.str_of(fld),
1114
1138
interior_index(*) => ~" [ ] ",
1115
1139
interior_tuple => ~"( ) ",
1116
1140
interior_anon_field => ~"<anonymous field>",
0 commit comments