@@ -17,7 +17,7 @@ use dataflow::MaybeInitializedLvals;
17
17
use dataflow:: flow_in_progress:: FlowInProgress ;
18
18
use dataflow:: move_paths:: MoveData ;
19
19
use rustc:: infer:: { InferCtxt , InferOk , InferResult , LateBoundRegionConversionTime , UnitResult } ;
20
- use rustc:: infer:: region_constraints:: RegionConstraintData ;
20
+ use rustc:: infer:: region_constraints:: { GenericKind , RegionConstraintData } ;
21
21
use rustc:: traits:: { self , FulfillmentContext } ;
22
22
use rustc:: ty:: error:: TypeError ;
23
23
use rustc:: ty:: fold:: TypeFoldable ;
@@ -54,6 +54,8 @@ mod liveness;
54
54
/// - `body_id` -- body-id of the MIR being checked
55
55
/// - `param_env` -- parameter environment to use for trait solving
56
56
/// - `mir` -- MIR to type-check
57
+ /// - `region_bound_pairs` -- the implied outlives obligations between type parameters
58
+ /// and lifetimes (e.g., `&'a T` implies `T: 'a`)
57
59
/// - `implicit_region_bound` -- a region which all generic parameters are assumed
58
60
/// to outlive; should represent the fn body
59
61
/// - `input_tys` -- fully liberated, but **not** normalized, expected types of the arguments;
@@ -69,6 +71,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
69
71
body_id : ast:: NodeId ,
70
72
param_env : ty:: ParamEnv < ' gcx > ,
71
73
mir : & Mir < ' tcx > ,
74
+ region_bound_pairs : & [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
72
75
implicit_region_bound : ty:: Region < ' tcx > ,
73
76
input_tys : & [ Ty < ' tcx > ] ,
74
77
output_ty : Ty < ' tcx > ,
@@ -81,6 +84,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
81
84
body_id,
82
85
param_env,
83
86
mir,
87
+ region_bound_pairs,
84
88
Some ( implicit_region_bound) ,
85
89
& mut |cx| {
86
90
liveness:: generate ( cx, mir, liveness, flow_inits, move_data) ;
@@ -100,10 +104,17 @@ fn type_check_internal<'gcx, 'tcx>(
100
104
body_id : ast:: NodeId ,
101
105
param_env : ty:: ParamEnv < ' gcx > ,
102
106
mir : & Mir < ' tcx > ,
107
+ region_bound_pairs : & [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
103
108
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
104
109
extra : & mut FnMut ( & mut TypeChecker < ' _ , ' gcx , ' tcx > ) ,
105
110
) -> MirTypeckRegionConstraints < ' tcx > {
106
- let mut checker = TypeChecker :: new ( infcx, body_id, param_env, implicit_region_bound) ;
111
+ let mut checker = TypeChecker :: new (
112
+ infcx,
113
+ body_id,
114
+ param_env,
115
+ region_bound_pairs,
116
+ implicit_region_bound,
117
+ ) ;
107
118
let errors_reported = {
108
119
let mut verifier = TypeVerifier :: new ( & mut checker, mir) ;
109
120
verifier. visit_mir ( mir) ;
@@ -563,6 +574,7 @@ struct TypeChecker<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
563
574
param_env : ty:: ParamEnv < ' gcx > ,
564
575
last_span : Span ,
565
576
body_id : ast:: NodeId ,
577
+ region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
566
578
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
567
579
reported_errors : FxHashSet < ( Ty < ' tcx > , Span ) > ,
568
580
constraints : MirTypeckRegionConstraints < ' tcx > ,
@@ -617,13 +629,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
617
629
infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
618
630
body_id : ast:: NodeId ,
619
631
param_env : ty:: ParamEnv < ' gcx > ,
632
+ region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
620
633
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
621
634
) -> Self {
622
635
TypeChecker {
623
636
infcx,
624
637
last_span : DUMMY_SP ,
625
638
body_id,
626
639
param_env,
640
+ region_bound_pairs,
627
641
implicit_region_bound,
628
642
reported_errors : FxHashSet ( ) ,
629
643
constraints : MirTypeckRegionConstraints :: default ( ) ,
@@ -650,7 +664,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
650
664
}
651
665
652
666
self . infcx . process_registered_region_obligations (
653
- & [ ] ,
667
+ self . region_bound_pairs ,
654
668
self . implicit_region_bound ,
655
669
self . param_env ,
656
670
self . body_id ,
@@ -756,12 +770,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
756
770
) ;
757
771
} ;
758
772
}
759
- StatementKind :: StorageLive ( _) |
760
- StatementKind :: StorageDead ( _) |
761
- StatementKind :: InlineAsm { .. } |
762
- StatementKind :: EndRegion ( _) |
763
- StatementKind :: Validate ( ..) |
764
- StatementKind :: Nop => { }
773
+ StatementKind :: StorageLive ( _)
774
+ | StatementKind :: StorageDead ( _)
775
+ | StatementKind :: InlineAsm { .. }
776
+ | StatementKind :: EndRegion ( _)
777
+ | StatementKind :: Validate ( ..)
778
+ | StatementKind :: Nop => { }
765
779
}
766
780
}
767
781
@@ -774,13 +788,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
774
788
debug ! ( "check_terminator: {:?}" , term) ;
775
789
let tcx = self . tcx ( ) ;
776
790
match term. kind {
777
- TerminatorKind :: Goto { .. } |
778
- TerminatorKind :: Resume |
779
- TerminatorKind :: Return |
780
- TerminatorKind :: GeneratorDrop |
781
- TerminatorKind :: Unreachable |
782
- TerminatorKind :: Drop { .. } |
783
- TerminatorKind :: FalseEdges { .. } => {
791
+ TerminatorKind :: Goto { .. }
792
+ | TerminatorKind :: Resume
793
+ | TerminatorKind :: Return
794
+ | TerminatorKind :: GeneratorDrop
795
+ | TerminatorKind :: Unreachable
796
+ | TerminatorKind :: Drop { .. }
797
+ | TerminatorKind :: FalseEdges { .. } => {
784
798
// no checks needed for these
785
799
}
786
800
@@ -880,9 +894,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
880
894
// output) types in the signature must be live, since
881
895
// all the inputs that fed into it were live.
882
896
for & late_bound_region in map. values ( ) {
883
- self . constraints
884
- . liveness_set
885
- . push ( ( late_bound_region, term_location, Cause :: LiveOther ( term_location) ) ) ;
897
+ self . constraints . liveness_set . push ( (
898
+ late_bound_region,
899
+ term_location,
900
+ Cause :: LiveOther ( term_location) ,
901
+ ) ) ;
886
902
}
887
903
888
904
if self . is_box_free ( func) {
@@ -1092,9 +1108,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1092
1108
}
1093
1109
}
1094
1110
TerminatorKind :: Unreachable => { }
1095
- TerminatorKind :: Drop { target, unwind, .. } |
1096
- TerminatorKind :: DropAndReplace { target, unwind, .. } |
1097
- TerminatorKind :: Assert {
1111
+ TerminatorKind :: Drop { target, unwind, .. }
1112
+ | TerminatorKind :: DropAndReplace { target, unwind, .. }
1113
+ | TerminatorKind :: Assert {
1098
1114
target,
1099
1115
cleanup : unwind,
1100
1116
..
@@ -1350,13 +1366,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1350
1366
} ,
1351
1367
1352
1368
// FIXME: These other cases have to be implemented in future PRs
1353
- Rvalue :: Use ( ..) |
1354
- Rvalue :: Ref ( ..) |
1355
- Rvalue :: Len ( ..) |
1356
- Rvalue :: BinaryOp ( ..) |
1357
- Rvalue :: CheckedBinaryOp ( ..) |
1358
- Rvalue :: UnaryOp ( ..) |
1359
- Rvalue :: Discriminant ( ..) => { }
1369
+ Rvalue :: Use ( ..)
1370
+ | Rvalue :: Ref ( ..)
1371
+ | Rvalue :: Len ( ..)
1372
+ | Rvalue :: BinaryOp ( ..)
1373
+ | Rvalue :: CheckedBinaryOp ( ..)
1374
+ | Rvalue :: UnaryOp ( ..)
1375
+ | Rvalue :: Discriminant ( ..) => { }
1360
1376
}
1361
1377
}
1362
1378
@@ -1490,9 +1506,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1490
1506
let cause = this. misc ( this. last_span ) ;
1491
1507
let obligations = predicates
1492
1508
. iter ( )
1493
- . map ( |& p| {
1494
- traits:: Obligation :: new ( cause. clone ( ) , this. param_env , p)
1495
- } )
1509
+ . map ( |& p| traits:: Obligation :: new ( cause. clone ( ) , this. param_env , p) )
1496
1510
. collect ( ) ;
1497
1511
Ok ( InferOk {
1498
1512
value : ( ) ,
@@ -1556,7 +1570,7 @@ impl MirPass for TypeckMir {
1556
1570
}
1557
1571
let param_env = tcx. param_env ( def_id) ;
1558
1572
tcx. infer_ctxt ( ) . enter ( |infcx| {
1559
- let _ = type_check_internal ( & infcx, id, param_env, mir, None , & mut |_| ( ) ) ;
1573
+ let _ = type_check_internal ( & infcx, id, param_env, mir, & [ ] , None , & mut |_| ( ) ) ;
1560
1574
1561
1575
// For verification purposes, we just ignore the resulting
1562
1576
// region constraint sets. Not our problem. =)
0 commit comments