@@ -17,7 +17,9 @@ use borrow_check::nll::constraints::{ConstraintSet, OutlivesConstraint};
1717use borrow_check:: nll:: facts:: AllFacts ;
1818use borrow_check:: nll:: region_infer:: values:: { LivenessValues , RegionValueElements } ;
1919use borrow_check:: nll:: region_infer:: { ClosureRegionRequirementsExt , TypeTest } ;
20- use borrow_check:: nll:: type_check:: free_region_relations:: { CreateResult , UniversalRegionRelations } ;
20+ use borrow_check:: nll:: type_check:: free_region_relations:: {
21+ CreateResult , UniversalRegionRelations ,
22+ } ;
2123use borrow_check:: nll:: universal_regions:: UniversalRegions ;
2224use borrow_check:: nll:: ToRegionVid ;
2325use dataflow:: move_paths:: MoveData ;
@@ -246,10 +248,12 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
246248 self . sanitize_type ( constant, constant. ty ) ;
247249
248250 if let Some ( user_ty) = constant. user_ty {
249- if let Err ( terr) =
250- self . cx
251- . eq_user_type_and_type ( user_ty, constant. ty , location. boring ( ) )
252- {
251+ if let Err ( terr) = self . cx . relate_type_and_user_type (
252+ constant. ty ,
253+ ty:: Variance :: Invariant ,
254+ user_ty,
255+ location. boring ( ) ,
256+ ) {
253257 span_mirbug ! (
254258 self ,
255259 constant,
@@ -850,30 +854,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
850854 )
851855 }
852856
853- fn sub_type_and_user_type (
857+ fn relate_type_and_user_type (
854858 & mut self ,
855859 a : Ty < ' tcx > ,
860+ v : ty:: Variance ,
856861 b : CanonicalTy < ' tcx > ,
857862 locations : Locations ,
858863 ) -> Fallible < ( ) > {
859- relate_tys:: sub_type_and_user_type (
860- self . infcx ,
861- a,
862- b,
863- locations,
864- self . borrowck_context . as_mut ( ) . map ( |x| & mut * * x) ,
865- )
866- }
867-
868- fn eq_user_type_and_type (
869- & mut self ,
870- a : CanonicalTy < ' tcx > ,
871- b : Ty < ' tcx > ,
872- locations : Locations ,
873- ) -> Fallible < ( ) > {
874- relate_tys:: eq_user_type_and_type (
864+ relate_tys:: relate_type_and_user_type (
875865 self . infcx ,
876866 a,
867+ v,
877868 b,
878869 locations,
879870 self . borrowck_context . as_mut ( ) . map ( |x| & mut * * x) ,
@@ -894,8 +885,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
894885 // of lowering. Assignments to other sorts of places *are* interesting
895886 // though.
896887 let is_temp = if let Place :: Local ( l) = * place {
897- l != RETURN_PLACE &&
898- !mir. local_decls [ l] . is_user_variable . is_some ( )
888+ l != RETURN_PLACE && !mir. local_decls [ l] . is_user_variable . is_some ( )
899889 } else {
900890 false
901891 } ;
@@ -920,9 +910,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
920910 }
921911
922912 if let Some ( user_ty) = self . rvalue_user_ty ( rv) {
923- if let Err ( terr) = self . eq_user_type_and_type (
924- user_ty,
913+ if let Err ( terr) = self . relate_type_and_user_type (
925914 rv_ty,
915+ ty:: Variance :: Invariant ,
916+ user_ty,
926917 location. boring ( ) ,
927918 ) {
928919 span_mirbug ! (
@@ -970,9 +961,11 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
970961 ) ;
971962 } ;
972963 }
973- StatementKind :: AscribeUserType ( ref place, c_ty) => {
964+ StatementKind :: AscribeUserType ( ref place, variance , c_ty) => {
974965 let place_ty = place. ty ( mir, tcx) . to_ty ( tcx) ;
975- if let Err ( terr) = self . sub_type_and_user_type ( place_ty, c_ty, Locations :: All ) {
966+ if let Err ( terr) =
967+ self . relate_type_and_user_type ( place_ty, variance, c_ty, Locations :: All )
968+ {
976969 span_mirbug ! (
977970 self ,
978971 stmt,
@@ -1157,8 +1150,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11571150 Some ( ( ref dest, _target_block) ) => {
11581151 let dest_ty = dest. ty ( mir, tcx) . to_ty ( tcx) ;
11591152 let is_temp = if let Place :: Local ( l) = * dest {
1160- l != RETURN_PLACE &&
1161- !mir. local_decls [ l] . is_user_variable . is_some ( )
1153+ l != RETURN_PLACE && !mir. local_decls [ l] . is_user_variable . is_some ( )
11621154 } else {
11631155 false
11641156 } ;
@@ -1577,30 +1569,26 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15771569 /// If this rvalue supports a user-given type annotation, then
15781570 /// extract and return it. This represents the final type of the
15791571 /// rvalue and will be unified with the inferred type.
1580- fn rvalue_user_ty (
1581- & self ,
1582- rvalue : & Rvalue < ' tcx > ,
1583- ) -> Option < CanonicalTy < ' tcx > > {
1572+ fn rvalue_user_ty ( & self , rvalue : & Rvalue < ' tcx > ) -> Option < CanonicalTy < ' tcx > > {
15841573 match rvalue {
1585- Rvalue :: Use ( _) |
1586- Rvalue :: Repeat ( ..) |
1587- Rvalue :: Ref ( ..) |
1588- Rvalue :: Len ( ..) |
1589- Rvalue :: Cast ( ..) |
1590- Rvalue :: BinaryOp ( ..) |
1591- Rvalue :: CheckedBinaryOp ( ..) |
1592- Rvalue :: NullaryOp ( ..) |
1593- Rvalue :: UnaryOp ( ..) |
1594- Rvalue :: Discriminant ( ..) =>
1595- None ,
1574+ Rvalue :: Use ( _)
1575+ | Rvalue :: Repeat ( ..)
1576+ | Rvalue :: Ref ( ..)
1577+ | Rvalue :: Len ( ..)
1578+ | Rvalue :: Cast ( ..)
1579+ | Rvalue :: BinaryOp ( ..)
1580+ | Rvalue :: CheckedBinaryOp ( ..)
1581+ | Rvalue :: NullaryOp ( ..)
1582+ | Rvalue :: UnaryOp ( ..)
1583+ | Rvalue :: Discriminant ( ..) => None ,
15961584
15971585 Rvalue :: Aggregate ( aggregate, _) => match * * aggregate {
15981586 AggregateKind :: Adt ( _, _, _, user_ty, _) => user_ty,
15991587 AggregateKind :: Array ( _) => None ,
16001588 AggregateKind :: Tuple => None ,
16011589 AggregateKind :: Closure ( _, _) => None ,
16021590 AggregateKind :: Generator ( _, _, _) => None ,
1603- }
1591+ } ,
16041592 }
16051593 }
16061594
0 commit comments