@@ -306,6 +306,29 @@ impl MutabilityCategory {
306
306
}
307
307
}
308
308
309
+ fn from_def ( def : & def:: Def ) -> MutabilityCategory {
310
+ match * def {
311
+ def:: DefFn ( ..) | def:: DefStaticMethod ( ..) | def:: DefSelfTy ( ..) |
312
+ def:: DefMod ( ..) | def:: DefForeignMod ( ..) | def:: DefVariant ( ..) |
313
+ def:: DefTy ( ..) | def:: DefTrait ( ..) | def:: DefPrimTy ( ..) |
314
+ def:: DefTyParam ( ..) | def:: DefUse ( ..) | def:: DefStruct ( ..) |
315
+ def:: DefTyParamBinder ( ..) | def:: DefRegion ( ..) | def:: DefLabel ( ..) |
316
+ def:: DefMethod ( ..) => fail ! ( "no MutabilityCategory for def: {}" , * def) ,
317
+
318
+ def:: DefStatic ( _, false ) => McImmutable ,
319
+ def:: DefStatic ( _, true ) => McDeclared ,
320
+
321
+ def:: DefArg ( _, binding_mode) |
322
+ def:: DefBinding ( _, binding_mode) |
323
+ def:: DefLocal ( _, binding_mode) => match binding_mode {
324
+ ast:: BindByValue ( ast:: MutMutable ) => McDeclared ,
325
+ _ => McImmutable
326
+ } ,
327
+
328
+ def:: DefUpvar ( _, def, _, _) => MutabilityCategory :: from_def ( & * def)
329
+ }
330
+ }
331
+
309
332
pub fn inherit ( & self ) -> MutabilityCategory {
310
333
match * self {
311
334
McImmutable => McImmutable ,
@@ -503,8 +526,8 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
503
526
def:: DefStaticMethod ( ..) => {
504
527
Ok ( self . cat_rvalue_node ( id, span, expr_ty) )
505
528
}
506
- def:: DefMod ( _) | def:: DefForeignMod ( _) | def:: DefStatic ( _ , false ) |
507
- def:: DefUse ( _ ) | def :: DefTrait ( _) | def:: DefTy ( _) | def:: DefPrimTy ( _) |
529
+ def:: DefMod ( _) | def:: DefForeignMod ( _) | def:: DefUse ( _ ) |
530
+ def:: DefTrait ( _) | def:: DefTy ( _) | def:: DefPrimTy ( _) |
508
531
def:: DefTyParam ( ..) | def:: DefTyParamBinder ( ..) | def:: DefRegion ( _) |
509
532
def:: DefLabel ( _) | def:: DefSelfTy ( ..) | def:: DefMethod ( ..) => {
510
533
Ok ( Rc :: new ( cmt_ {
@@ -516,30 +539,25 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
516
539
} ) )
517
540
}
518
541
519
- def:: DefStatic ( _, true ) => {
542
+ def:: DefStatic ( _, _ ) => {
520
543
Ok ( Rc :: new ( cmt_ {
521
544
id : id,
522
545
span : span,
523
546
cat : cat_static_item,
524
- mutbl : McDeclared ,
547
+ mutbl : MutabilityCategory :: from_def ( & def ) ,
525
548
ty : expr_ty
526
549
} ) )
527
550
}
528
551
529
- def:: DefArg ( vid, binding_mode ) => {
552
+ def:: DefArg ( vid, _ ) => {
530
553
// Idea: make this could be rewritten to model by-ref
531
554
// stuff as `&const` and `&mut`?
532
555
533
- // m: mutability of the argument
534
- let m = match binding_mode {
535
- ast:: BindByValue ( ast:: MutMutable ) => McDeclared ,
536
- _ => McImmutable
537
- } ;
538
556
Ok ( Rc :: new ( cmt_ {
539
557
id : id,
540
558
span : span,
541
559
cat : cat_arg ( vid) ,
542
- mutbl : m ,
560
+ mutbl : MutabilityCategory :: from_def ( & def ) ,
543
561
ty : expr_ty
544
562
} ) )
545
563
}
@@ -564,7 +582,6 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
564
582
if var_is_refd {
565
583
self . cat_upvar ( id, span, var_id, fn_node_id)
566
584
} else {
567
- // FIXME #2152 allow mutation of moved upvars
568
585
Ok ( Rc :: new ( cmt_ {
569
586
id : id,
570
587
span : span,
@@ -573,13 +590,12 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
573
590
onceness : closure_ty. onceness ,
574
591
capturing_proc : fn_node_id,
575
592
} ) ,
576
- mutbl : McImmutable ,
593
+ mutbl : MutabilityCategory :: from_def ( & def ) ,
577
594
ty : expr_ty
578
595
} ) )
579
596
}
580
597
}
581
598
ty:: ty_unboxed_closure( _) => {
582
- // FIXME #2152 allow mutation of moved upvars
583
599
Ok ( Rc :: new ( cmt_ {
584
600
id : id,
585
601
span : span,
@@ -588,7 +604,7 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
588
604
onceness : ast:: Many ,
589
605
capturing_proc : fn_node_id,
590
606
} ) ,
591
- mutbl : McImmutable ,
607
+ mutbl : MutabilityCategory :: from_def ( & def ) ,
592
608
ty : expr_ty
593
609
} ) )
594
610
}
@@ -602,19 +618,14 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
602
618
}
603
619
}
604
620
605
- def:: DefLocal ( vid, binding_mode ) |
606
- def:: DefBinding ( vid, binding_mode ) => {
621
+ def:: DefLocal ( vid, _ ) |
622
+ def:: DefBinding ( vid, _ ) => {
607
623
// by-value/by-ref bindings are local variables
608
- let m = match binding_mode {
609
- ast:: BindByValue ( ast:: MutMutable ) => McDeclared ,
610
- _ => McImmutable
611
- } ;
612
-
613
624
Ok ( Rc :: new ( cmt_ {
614
625
id : id,
615
626
span : span,
616
627
cat : cat_local ( vid) ,
617
- mutbl : m ,
628
+ mutbl : MutabilityCategory :: from_def ( & def ) ,
618
629
ty : expr_ty
619
630
} ) )
620
631
}
0 commit comments