@@ -17,12 +17,12 @@ use borrow_check::nll::constraints::{ConstraintCategory, ConstraintSet, Outlives
17
17
use borrow_check:: nll:: facts:: AllFacts ;
18
18
use borrow_check:: nll:: region_infer:: values:: { LivenessValues , RegionValueElements } ;
19
19
use borrow_check:: nll:: region_infer:: { ClosureRegionRequirementsExt , TypeTest } ;
20
+ use borrow_check:: nll:: renumber;
20
21
use borrow_check:: nll:: type_check:: free_region_relations:: {
21
22
CreateResult , UniversalRegionRelations ,
22
23
} ;
23
24
use borrow_check:: nll:: universal_regions:: UniversalRegions ;
24
25
use borrow_check:: nll:: ToRegionVid ;
25
- use borrow_check:: nll:: renumber;
26
26
use dataflow:: move_paths:: MoveData ;
27
27
use dataflow:: FlowAtLocation ;
28
28
use dataflow:: MaybeInitializedPlaces ;
@@ -35,13 +35,13 @@ use rustc::mir::interpret::EvalErrorKind::BoundsCheck;
35
35
use rustc:: mir:: tcx:: PlaceTy ;
36
36
use rustc:: mir:: visit:: { PlaceContext , Visitor } ;
37
37
use rustc:: mir:: * ;
38
- use rustc:: traits:: { ObligationCause , PredicateObligations } ;
39
38
use rustc:: traits:: query:: type_op;
40
39
use rustc:: traits:: query:: type_op:: custom:: CustomTypeOp ;
41
40
use rustc:: traits:: query:: { Fallible , NoSolution } ;
41
+ use rustc:: traits:: { ObligationCause , PredicateObligations } ;
42
42
use rustc:: ty:: fold:: TypeFoldable ;
43
- use rustc:: ty:: { self , CanonicalTy , RegionVid , ToPolyTraitRef , Ty , TyCtxt , TyKind } ;
44
43
use rustc:: ty:: subst:: Subst ;
44
+ use rustc:: ty:: { self , CanonicalTy , RegionVid , ToPolyTraitRef , Ty , TyCtxt , TyKind } ;
45
45
use std:: fmt;
46
46
use std:: rc:: Rc ;
47
47
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -161,11 +161,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
161
161
Some ( & mut borrowck_context) ,
162
162
Some ( & universal_region_relations) ,
163
163
|cx| {
164
- cx. equate_inputs_and_outputs (
165
- mir,
166
- universal_regions,
167
- & normalized_inputs_and_output,
168
- ) ;
164
+ cx. equate_inputs_and_outputs ( mir, universal_regions, & normalized_inputs_and_output) ;
169
165
liveness:: generate ( cx, mir, elements, flow_inits, move_data) ;
170
166
} ,
171
167
) ;
@@ -377,14 +373,12 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
377
373
378
374
debug ! ( "sanitize_constant: expected_ty={:?}" , constant. literal. ty) ;
379
375
380
- if let Err ( terr) = self . cx
381
- . eq_types (
382
- constant. literal . ty ,
383
- constant. ty ,
384
- location. to_locations ( ) ,
385
- ConstraintCategory :: Boring ,
386
- )
387
- {
376
+ if let Err ( terr) = self . cx . eq_types (
377
+ constant. literal . ty ,
378
+ constant. ty ,
379
+ location. to_locations ( ) ,
380
+ ConstraintCategory :: Boring ,
381
+ ) {
388
382
span_mirbug ! (
389
383
self ,
390
384
constant,
@@ -429,12 +423,10 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
429
423
let sty = self . sanitize_type ( place, sty) ;
430
424
let ty = self . tcx ( ) . type_of ( def_id) ;
431
425
let ty = self . cx . normalize ( ty, location) ;
432
- if let Err ( terr) = self . cx . eq_types (
433
- ty,
434
- sty,
435
- location. to_locations ( ) ,
436
- ConstraintCategory :: Boring ,
437
- ) {
426
+ if let Err ( terr) =
427
+ self . cx
428
+ . eq_types ( ty, sty, location. to_locations ( ) , ConstraintCategory :: Boring )
429
+ {
438
430
span_mirbug ! (
439
431
self ,
440
432
place,
@@ -955,66 +947,55 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
955
947
let tcx = infcx. tcx ;
956
948
let param_env = self . param_env ;
957
949
let parent_def_id = infcx. tcx . closure_base_def_id ( self . mir_def_id ) ;
958
- let opaque_type_map =
959
- self . fully_perform_op (
960
- locations,
961
- category,
962
- CustomTypeOp :: new (
963
- |infcx| {
964
- let mut obligations = ObligationAccumulator :: default ( ) ;
965
-
966
- let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
967
- let ( output_ty, opaque_type_map) =
968
- obligations. add ( infcx. instantiate_opaque_types (
969
- parent_def_id,
970
- dummy_body_id,
971
- param_env,
972
- & anon_ty,
973
- ) ) ;
950
+ let opaque_type_map = self . fully_perform_op (
951
+ locations,
952
+ category,
953
+ CustomTypeOp :: new (
954
+ |infcx| {
955
+ let mut obligations = ObligationAccumulator :: default ( ) ;
956
+
957
+ let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
958
+ let ( output_ty, opaque_type_map) =
959
+ obligations. add ( infcx. instantiate_opaque_types (
960
+ parent_def_id,
961
+ dummy_body_id,
962
+ param_env,
963
+ & anon_ty,
964
+ ) ) ;
965
+ debug ! (
966
+ "eq_opaque_type_and_type: \
967
+ instantiated output_ty={:?} \
968
+ opaque_type_map={:#?} \
969
+ revealed_ty={:?}",
970
+ output_ty, opaque_type_map, revealed_ty
971
+ ) ;
972
+ obligations. add ( infcx
973
+ . at ( & ObligationCause :: dummy ( ) , param_env)
974
+ . eq ( output_ty, revealed_ty) ?) ;
975
+
976
+ for ( & opaque_def_id, opaque_decl) in & opaque_type_map {
977
+ let opaque_defn_ty = tcx. type_of ( opaque_def_id) ;
978
+ let opaque_defn_ty = opaque_defn_ty. subst ( tcx, opaque_decl. substs ) ;
979
+ let opaque_defn_ty = renumber:: renumber_regions ( infcx, & opaque_defn_ty) ;
974
980
debug ! (
975
- "eq_opaque_type_and_type: \
976
- instantiated output_ty={:?} \
977
- opaque_type_map={:#?} \
978
- revealed_ty={:?}",
979
- output_ty,
980
- opaque_type_map,
981
- revealed_ty
982
- ) ;
983
- obligations. add (
984
- infcx
985
- . at ( & ObligationCause :: dummy ( ) , param_env)
986
- . eq ( output_ty, revealed_ty) ?,
981
+ "eq_opaque_type_and_type: concrete_ty={:?} opaque_defn_ty={:?}" ,
982
+ opaque_decl. concrete_ty, opaque_defn_ty
987
983
) ;
984
+ obligations. add ( infcx
985
+ . at ( & ObligationCause :: dummy ( ) , param_env)
986
+ . eq ( opaque_decl. concrete_ty , opaque_defn_ty) ?) ;
987
+ }
988
988
989
- for ( & opaque_def_id, opaque_decl) in & opaque_type_map {
990
- let opaque_defn_ty = tcx. type_of ( opaque_def_id) ;
991
- let opaque_defn_ty = opaque_defn_ty. subst ( tcx, opaque_decl. substs ) ;
992
- let opaque_defn_ty = renumber:: renumber_regions (
993
- infcx,
994
- & opaque_defn_ty,
995
- ) ;
996
- debug ! (
997
- "eq_opaque_type_and_type: concrete_ty={:?} opaque_defn_ty={:?}" ,
998
- opaque_decl. concrete_ty,
999
- opaque_defn_ty
1000
- ) ;
1001
- obligations. add (
1002
- infcx
1003
- . at ( & ObligationCause :: dummy ( ) , param_env)
1004
- . eq ( opaque_decl. concrete_ty , opaque_defn_ty) ?,
1005
- ) ;
1006
- }
1007
-
1008
- debug ! ( "eq_opaque_type_and_type: equated" ) ;
989
+ debug ! ( "eq_opaque_type_and_type: equated" ) ;
1009
990
1010
- Ok ( InferOk {
1011
- value : Some ( opaque_type_map) ,
1012
- obligations : obligations. into_vec ( ) ,
1013
- } )
1014
- } ,
1015
- || "input_output" . to_string ( ) ,
1016
- ) ,
1017
- ) ?;
991
+ Ok ( InferOk {
992
+ value : Some ( opaque_type_map) ,
993
+ obligations : obligations. into_vec ( ) ,
994
+ } )
995
+ } ,
996
+ || "input_output" . to_string ( ) ,
997
+ ) ,
998
+ ) ?;
1018
999
1019
1000
let universal_region_relations = match self . universal_region_relations {
1020
1001
Some ( rel) => rel,
@@ -1035,7 +1016,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1035
1016
infcx. constrain_opaque_type (
1036
1017
opaque_def_id,
1037
1018
& opaque_decl,
1038
- universal_region_relations
1019
+ universal_region_relations,
1039
1020
) ;
1040
1021
Ok ( InferOk {
1041
1022
value : ( ) ,
@@ -1073,12 +1054,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1073
1054
1074
1055
let place_ty = place. ty ( mir, tcx) . to_ty ( tcx) ;
1075
1056
let rv_ty = rv. ty ( mir, tcx) ;
1076
- if let Err ( terr) = self . sub_types_or_anon (
1077
- rv_ty,
1078
- place_ty,
1079
- location. to_locations ( ) ,
1080
- category,
1081
- ) {
1057
+ if let Err ( terr) =
1058
+ self . sub_types_or_anon ( rv_ty, place_ty, location. to_locations ( ) , category)
1059
+ {
1082
1060
span_mirbug ! (
1083
1061
self ,
1084
1062
stmt,
@@ -1117,7 +1095,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1117
1095
self . prove_trait_ref (
1118
1096
trait_ref,
1119
1097
location. to_locations ( ) ,
1120
- ConstraintCategory :: SizedBound ,
1098
+ ConstraintCategory :: SizedBound ,
1121
1099
) ;
1122
1100
}
1123
1101
}
@@ -1148,15 +1126,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1148
1126
}
1149
1127
StatementKind :: AscribeUserType ( ref place, variance, c_ty) => {
1150
1128
let place_ty = place. ty ( mir, tcx) . to_ty ( tcx) ;
1151
- if let Err ( terr) =
1152
- self . relate_type_and_user_type (
1153
- place_ty,
1154
- variance,
1155
- c_ty,
1156
- Locations :: All ( stmt. source_info . span ) ,
1157
- ConstraintCategory :: TypeAnnotation ,
1158
- )
1159
- {
1129
+ if let Err ( terr) = self . relate_type_and_user_type (
1130
+ place_ty,
1131
+ variance,
1132
+ c_ty,
1133
+ Locations :: All ( stmt. source_info . span ) ,
1134
+ ConstraintCategory :: TypeAnnotation ,
1135
+ ) {
1160
1136
span_mirbug ! (
1161
1137
self ,
1162
1138
stmt,
@@ -1208,12 +1184,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1208
1184
let rv_ty = value. ty ( mir, tcx) ;
1209
1185
1210
1186
let locations = term_location. to_locations ( ) ;
1211
- if let Err ( terr) = self . sub_types (
1212
- rv_ty,
1213
- place_ty,
1214
- locations,
1215
- ConstraintCategory :: Assignment ,
1216
- ) {
1187
+ if let Err ( terr) =
1188
+ self . sub_types ( rv_ty, place_ty, locations, ConstraintCategory :: Assignment )
1189
+ {
1217
1190
span_mirbug ! (
1218
1191
self ,
1219
1192
term,
@@ -1327,8 +1300,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1327
1300
ty,
1328
1301
term_location. to_locations ( ) ,
1329
1302
ConstraintCategory :: Return ,
1330
- )
1331
- {
1303
+ ) {
1332
1304
span_mirbug ! (
1333
1305
self ,
1334
1306
term,
@@ -1366,12 +1338,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1366
1338
1367
1339
let locations = term_location. to_locations ( ) ;
1368
1340
1369
- if let Err ( terr) = self . sub_types_or_anon (
1370
- sig. output ( ) ,
1371
- dest_ty,
1372
- locations,
1373
- category,
1374
- ) {
1341
+ if let Err ( terr) =
1342
+ self . sub_types_or_anon ( sig. output ( ) , dest_ty, locations, category)
1343
+ {
1375
1344
span_mirbug ! (
1376
1345
self ,
1377
1346
term,
@@ -1539,12 +1508,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1539
1508
}
1540
1509
}
1541
1510
1542
- fn check_local (
1543
- & mut self ,
1544
- mir : & Mir < ' tcx > ,
1545
- local : Local ,
1546
- local_decl : & LocalDecl < ' tcx > ,
1547
- ) {
1511
+ fn check_local ( & mut self , mir : & Mir < ' tcx > , local : Local , local_decl : & LocalDecl < ' tcx > ) {
1548
1512
match mir. local_kind ( local) {
1549
1513
LocalKind :: ReturnPointer | LocalKind :: Arg => {
1550
1514
// return values of normal functions are required to be
@@ -1713,13 +1677,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1713
1677
ConstraintCategory :: Cast ,
1714
1678
) {
1715
1679
span_mirbug ! (
1716
- self ,
1717
- rvalue,
1718
- "equating {:?} with {:?} yields {:?}" ,
1719
- ty_fn_ptr_from,
1720
- ty,
1721
- terr
1722
- ) ;
1680
+ self ,
1681
+ rvalue,
1682
+ "equating {:?} with {:?} yields {:?}" ,
1683
+ ty_fn_ptr_from,
1684
+ ty,
1685
+ terr
1686
+ ) ;
1723
1687
}
1724
1688
}
1725
1689
@@ -1739,13 +1703,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1739
1703
ConstraintCategory :: Cast ,
1740
1704
) {
1741
1705
span_mirbug ! (
1742
- self ,
1743
- rvalue,
1744
- "equating {:?} with {:?} yields {:?}" ,
1745
- ty_fn_ptr_from,
1746
- ty,
1747
- terr
1748
- ) ;
1706
+ self ,
1707
+ rvalue,
1708
+ "equating {:?} with {:?} yields {:?}" ,
1709
+ ty_fn_ptr_from,
1710
+ ty,
1711
+ terr
1712
+ ) ;
1749
1713
}
1750
1714
}
1751
1715
@@ -1768,13 +1732,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1768
1732
ConstraintCategory :: Cast ,
1769
1733
) {
1770
1734
span_mirbug ! (
1771
- self ,
1772
- rvalue,
1773
- "equating {:?} with {:?} yields {:?}" ,
1774
- ty_fn_ptr_from,
1775
- ty,
1776
- terr
1777
- ) ;
1735
+ self ,
1736
+ rvalue,
1737
+ "equating {:?} with {:?} yields {:?}" ,
1738
+ ty_fn_ptr_from,
1739
+ ty,
1740
+ terr
1741
+ ) ;
1778
1742
}
1779
1743
}
1780
1744
@@ -2277,4 +2241,3 @@ impl<'tcx> ObligationAccumulator<'tcx> {
2277
2241
self . obligations
2278
2242
}
2279
2243
}
2280
-
0 commit comments