@@ -351,6 +351,27 @@ impl methods for gather_loan_ctxt {
351
351
// been built up and pass it off to guarantee_valid() so that
352
352
// we can be sure that the binding will remain valid for the
353
353
// duration of the arm.
354
+ //
355
+ // The correspondence between the id in the cmt and which
356
+ // pattern is being referred to is somewhat...subtle. In
357
+ // general, the id of the cmt is the id of the node that
358
+ // produces the value. For patterns, that's actually the
359
+ // *subpattern*, generally speaking.
360
+ //
361
+ // To see what I mean about ids etc, consider:
362
+ //
363
+ // let x = @@3;
364
+ // alt x {
365
+ // @@y { ... }
366
+ // }
367
+ //
368
+ // Here the cmt for `y` would be something like
369
+ //
370
+ // local(x)->@->@
371
+ //
372
+ // where the id of `local(x)` is the id of the `x` that appears
373
+ // in the alt, the id of `local(x)->@` is the `@y` pattern,
374
+ // and the id of `local(x)->@->@` is the id of the `y` pattern.
354
375
355
376
#debug[ "gather_pat: id=%d pat=%s cmt=%s arm_id=%d alt_id=%d" ,
356
377
pat. id, pprust:: pat_to_str( pat) ,
@@ -369,7 +390,7 @@ impl methods for gather_loan_ctxt {
369
390
ast:: pat_enum( _, some( subpats) ) {
370
391
// variant(x, y, z)
371
392
for subpats. each { |subpat|
372
- let subcmt = self . bccx. cat_variant( pat , cmt, subpat ) ;
393
+ let subcmt = self . bccx. cat_variant( subpat , cmt) ;
373
394
self . gather_pat( subcmt, subpat, arm_id, alt_id) ;
374
395
}
375
396
}
@@ -396,23 +417,22 @@ impl methods for gather_loan_ctxt {
396
417
ast:: pat_rec( field_pats, _) {
397
418
// {f1: p1, ..., fN: pN}
398
419
for field_pats. each { |fp|
399
- let cmt_field = self . bccx. cat_field( pat, cmt, fp. ident,
400
- tcx. ty( fp. pat) ) ;
420
+ let cmt_field = self . bccx. cat_field( fp. pat, cmt, fp. ident) ;
401
421
self . gather_pat( cmt_field, fp. pat, arm_id, alt_id) ;
402
422
}
403
423
}
404
424
405
425
ast:: pat_tup( subpats) {
406
426
// (p1, ..., pN)
407
427
for subpats. each { |subpat|
408
- let subcmt = self . bccx. cat_tuple_elt( pat , cmt, subpat ) ;
428
+ let subcmt = self . bccx. cat_tuple_elt( subpat , cmt) ;
409
429
self . gather_pat( subcmt, subpat, arm_id, alt_id) ;
410
430
}
411
431
}
412
432
413
433
ast:: pat_box( subpat) | ast:: pat_uniq( subpat) {
414
434
// @p1, ~p1
415
- alt self. bccx. cat_deref( pat , cmt, 0 u, true ) {
435
+ alt self. bccx. cat_deref( subpat , cmt, 0 u, true ) {
416
436
some( subcmt) {
417
437
self . gather_pat( subcmt, subpat, arm_id, alt_id) ;
418
438
}
@@ -998,7 +1018,7 @@ impl categorize_methods for borrowck_ctxt {
998
1018
999
1019
ast:: expr_field( base, f_name, _) {
1000
1020
let base_cmt = self . cat_autoderef( base) ;
1001
- self . cat_field( expr, base_cmt, f_name, expr_ty )
1021
+ self . cat_field( expr, base_cmt, f_name)
1002
1022
}
1003
1023
1004
1024
ast:: expr_index( base, _) {
@@ -1033,8 +1053,7 @@ impl categorize_methods for borrowck_ctxt {
1033
1053
ret @{ cat: cat_discr( cmt, alt_id) with * cmt} ;
1034
1054
}
1035
1055
1036
- fn cat_field < N : ast_node > ( node: N , base_cmt: cmt,
1037
- f_name: str , f_ty: ty:: t) -> cmt {
1056
+ fn cat_field < N : ast_node > ( node: N , base_cmt: cmt, f_name: str ) -> cmt {
1038
1057
let f_mutbl = alt field_mutbl( self . tcx, base_cmt. ty, f_name) {
1039
1058
some( f_mutbl) { f_mutbl }
1040
1059
none {
@@ -1053,7 +1072,7 @@ impl categorize_methods for borrowck_ctxt {
1053
1072
} ;
1054
1073
@{ id: node. id( ) , span: node. span( ) ,
1055
1074
cat: cat_comp( base_cmt, comp_field( f_name) ) , lp: lp,
1056
- mutbl: m, ty: f_ty }
1075
+ mutbl: m, ty: self . tcx . ty ( node ) }
1057
1076
}
1058
1077
1059
1078
fn cat_deref < N : ast_node > ( node: N , base_cmt: cmt, derefs: uint,
@@ -1141,16 +1160,16 @@ impl categorize_methods for borrowck_ctxt {
1141
1160
mutbl: mt. mutbl, ty: mt. ty}
1142
1161
}
1143
1162
1144
- fn cat_variant < N : ast_node > ( variant : N , cmt: cmt, arg : N ) -> cmt {
1145
- @{ id : variant . id( ) , span : variant . span( ) ,
1163
+ fn cat_variant < N : ast_node > ( arg : N , cmt: cmt) -> cmt {
1164
+ @{ id : arg . id( ) , span : arg . span( ) ,
1146
1165
cat : cat_comp( cmt, comp_variant) ,
1147
1166
lp : cmt. lp. map { |l| @lp_comp( l, comp_variant) } ,
1148
1167
mutbl: cmt. mutbl, // imm iff in an immutable context
1149
1168
ty: self . tcx. ty( arg) }
1150
1169
}
1151
1170
1152
- fn cat_tuple_elt< N : ast_node > ( pat : N , cmt: cmt, elt : N ) -> cmt {
1153
- @{ id : pat . id( ) , span : pat . span( ) ,
1171
+ fn cat_tuple_elt < N : ast_node > ( elt : N , cmt: cmt) -> cmt {
1172
+ @{ id : elt . id( ) , span : elt . span( ) ,
1154
1173
cat : cat_comp( cmt, comp_tuple) ,
1155
1174
lp : cmt. lp. map { |l| @lp_comp( l, comp_tuple) } ,
1156
1175
mutbl: cmt. mutbl, // imm iff in an immutable context
0 commit comments