@@ -293,6 +293,18 @@ impl public_methods for borrowck_ctxt {
293
293
ret @{ cat : cat_discr ( cmt, alt_id) with * cmt} ;
294
294
}
295
295
296
+ /// inherited mutability: used in cases where the mutability of a
297
+ /// component is inherited from the base it is a part of. For
298
+ /// example, a record field is mutable if it is declared mutable
299
+ /// or if the container is mutable.
300
+ fn inherited_mutability ( base_m : ast:: mutability ,
301
+ comp_m : ast:: mutability ) -> ast:: mutability {
302
+ alt comp_m {
303
+ m_imm => { base_m} // imm: as mutable as the container
304
+ m_mutbl | m_const => { comp_m}
305
+ }
306
+ }
307
+
296
308
fn cat_field < N : ast_node > ( node : N , base_cmt : cmt ,
297
309
f_name : ast:: ident ) -> cmt {
298
310
let f_mutbl = alt field_mutbl ( self . tcx , base_cmt. ty , f_name) {
@@ -304,10 +316,7 @@ impl public_methods for borrowck_ctxt {
304
316
* f_name, ty_to_str ( self . tcx , base_cmt. ty ) ] ) ;
305
317
}
306
318
} ;
307
- let m = alt f_mutbl {
308
- m_imm { base_cmt. mutbl } // imm: as mutable as the container
309
- m_mutbl | m_const { f_mutbl }
310
- } ;
319
+ let m = self . inherited_mutability ( base_cmt. mutbl , f_mutbl) ;
311
320
let f_comp = comp_field ( f_name, f_mutbl) ;
312
321
let lp = base_cmt. lp . map ( |lp| @lp_comp ( lp, f_comp) ) ;
313
322
@{ id: node. id ( ) , span: node. span ( ) ,
@@ -327,20 +336,22 @@ impl public_methods for borrowck_ctxt {
327
336
// Other ptr types admit aliases and are therefore
328
337
// not loanable.
329
338
alt ptr {
330
- uniq_ptr { some( @lp_deref( l, ptr) ) }
331
- gc_ptr | region_ptr | unsafe_ptr { none}
339
+ uniq_ptr => { some ( @lp_deref ( l, ptr) ) }
340
+ gc_ptr | region_ptr | unsafe_ptr => { none}
332
341
}
333
342
} ;
343
+
334
344
@{ id: node. id ( ) , span: node. span ( ) ,
335
345
cat: cat_deref ( base_cmt, derefs, ptr) , lp: lp,
336
346
mutbl: mt. mutbl , ty: mt. ty }
337
347
}
338
348
339
349
deref_comp ( comp) {
340
350
let lp = base_cmt. lp . map ( |l| @lp_comp ( l, comp) ) ;
351
+ let m = self . inherited_mutability ( base_cmt. mutbl , mt. mutbl ) ;
341
352
@{ id: node. id ( ) , span: node. span ( ) ,
342
353
cat: cat_comp ( base_cmt, comp) , lp: lp,
343
- mutbl: mt . mutbl , ty: mt. ty }
354
+ mutbl: m , ty: mt. ty }
344
355
}
345
356
}
346
357
}
0 commit comments