@@ -83,7 +83,7 @@ pub enum categorization {
83
83
cat_rvalue( ty:: Region ) , // temporary val, argument is its scope
84
84
cat_static_item,
85
85
cat_copied_upvar( CopiedUpvar ) , // upvar copied into proc env
86
- cat_upvar( ty:: UpvarId , ty:: UpvarBorrow ) , // by ref upvar from stack closure
86
+ cat_upvar( ty:: UpvarId , ty:: UpvarBorrow , Option < ty :: UnboxedClosureKind > ) , // by ref upvar from stack or unboxed closure
87
87
cat_local( ast:: NodeId ) , // local variable
88
88
cat_deref( cmt , uint , PointerKind ) , // deref of a ptr
89
89
cat_interior( cmt , InteriorKind ) , // something interior: field, tuple, etc
@@ -93,10 +93,27 @@ pub enum categorization {
93
93
// (*1) downcast is only required if the enum has more than one variant
94
94
}
95
95
96
+ #[ deriving( Clone , PartialEq ) ]
97
+ pub enum CopiedUpvarKind {
98
+ Boxed ( ast:: Onceness ) ,
99
+ Unboxed ( ty:: UnboxedClosureKind )
100
+ }
101
+
102
+ impl CopiedUpvarKind {
103
+ pub fn onceness ( & self ) -> ast:: Onceness {
104
+ match * self {
105
+ Boxed ( onceness) => onceness,
106
+ Unboxed ( ty:: FnUnboxedClosureKind ) |
107
+ Unboxed ( ty:: FnMutUnboxedClosureKind ) => ast:: Many ,
108
+ Unboxed ( ty:: FnOnceUnboxedClosureKind ) => ast:: Once
109
+ }
110
+ }
111
+ }
112
+
96
113
#[ deriving( Clone , PartialEq ) ]
97
114
pub struct CopiedUpvar {
98
115
pub upvar_id : ast:: NodeId ,
99
- pub onceness : ast :: Onceness ,
116
+ pub kind : CopiedUpvarKind ,
100
117
pub capturing_proc : ast:: NodeId ,
101
118
}
102
119
@@ -571,14 +588,14 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
571
588
572
589
} ;
573
590
if var_is_refd {
574
- self . cat_upvar ( id, span, var_id, fn_node_id)
591
+ self . cat_upvar ( id, span, var_id, fn_node_id, None )
575
592
} else {
576
593
Ok ( Rc :: new ( cmt_ {
577
594
id : id,
578
595
span : span,
579
596
cat : cat_copied_upvar ( CopiedUpvar {
580
597
upvar_id : var_id,
581
- onceness : closure_ty. onceness ,
598
+ kind : Boxed ( closure_ty. onceness ) ,
582
599
capturing_proc : fn_node_id,
583
600
} ) ,
584
601
mutbl : MutabilityCategory :: from_local ( self . tcx ( ) , var_id) ,
@@ -591,20 +608,15 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
591
608
. unboxed_closures ( )
592
609
. borrow ( ) ;
593
610
let kind = unboxed_closures. get ( & closure_id) . kind ;
594
- let onceness = match kind {
595
- ty:: FnUnboxedClosureKind |
596
- ty:: FnMutUnboxedClosureKind => ast:: Many ,
597
- ty:: FnOnceUnboxedClosureKind => ast:: Once ,
598
- } ;
599
611
if self . typer . capture_mode ( fn_node_id) == ast:: CaptureByRef {
600
- self . cat_upvar ( id, span, var_id, fn_node_id)
612
+ self . cat_upvar ( id, span, var_id, fn_node_id, Some ( kind ) )
601
613
} else {
602
614
Ok ( Rc :: new ( cmt_ {
603
615
id : id,
604
616
span : span,
605
617
cat : cat_copied_upvar ( CopiedUpvar {
606
618
upvar_id : var_id,
607
- onceness : onceness ,
619
+ kind : Unboxed ( kind ) ,
608
620
capturing_proc : fn_node_id,
609
621
} ) ,
610
622
mutbl : MutabilityCategory :: from_local ( self . tcx ( ) , var_id) ,
@@ -638,7 +650,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
638
650
id : ast:: NodeId ,
639
651
span : Span ,
640
652
var_id : ast:: NodeId ,
641
- fn_node_id : ast:: NodeId )
653
+ fn_node_id : ast:: NodeId ,
654
+ kind : Option < ty:: UnboxedClosureKind > )
642
655
-> McResult < cmt > {
643
656
/*!
644
657
* Upvars through a closure are in fact indirect
@@ -666,7 +679,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
666
679
let base_cmt = Rc :: new ( cmt_ {
667
680
id : id,
668
681
span : span,
669
- cat : cat_upvar ( upvar_id, upvar_borrow) ,
682
+ cat : cat_upvar ( upvar_id, upvar_borrow, kind ) ,
670
683
mutbl : McImmutable ,
671
684
ty : upvar_ty,
672
685
} ) ;
@@ -1287,16 +1300,21 @@ impl cmt_ {
1287
1300
b. freely_aliasable ( ctxt)
1288
1301
}
1289
1302
1290
- cat_copied_upvar( CopiedUpvar { onceness : ast:: Once , ..} ) |
1291
1303
cat_rvalue( ..) |
1292
1304
cat_local( ..) |
1293
1305
cat_upvar( ..) |
1294
1306
cat_deref( _, _, UnsafePtr ( ..) ) => { // yes, it's aliasable, but...
1295
1307
None
1296
1308
}
1297
1309
1298
- cat_copied_upvar( CopiedUpvar { onceness : ast:: Many , ..} ) => {
1299
- Some ( AliasableOther )
1310
+ cat_copied_upvar( CopiedUpvar { kind : kind, capturing_proc : id, ..} ) => {
1311
+ match kind {
1312
+ Boxed ( ast:: Once ) |
1313
+ Unboxed ( ty:: FnOnceUnboxedClosureKind ) |
1314
+ Unboxed ( ty:: FnMutUnboxedClosureKind ) => None ,
1315
+ Boxed ( _) => Some ( AliasableOther ) ,
1316
+ Unboxed ( _) => Some ( AliasableClosure ( id) )
1317
+ }
1300
1318
}
1301
1319
1302
1320
cat_static_item( ..) => {
0 commit comments