@@ -42,7 +42,7 @@ use rustc::traits::query::type_op::custom::CustomTypeOp;
42
42
use rustc:: traits:: query:: { Fallible , NoSolution } ;
43
43
use rustc:: traits:: { ObligationCause , PredicateObligations } ;
44
44
use rustc:: ty:: fold:: TypeFoldable ;
45
- use rustc:: ty:: subst:: { Subst , Substs , UnpackedKind , UserSelfTy , UserSubsts } ;
45
+ use rustc:: ty:: subst:: { Subst , Substs , UnpackedKind } ;
46
46
use rustc:: ty:: { self , RegionVid , ToPolyTraitRef , Ty , TyCtxt , TyKind } ;
47
47
use std:: rc:: Rc ;
48
48
use std:: { fmt, iter} ;
@@ -975,127 +975,43 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
975
975
locations : Locations ,
976
976
category : ConstraintCategory ,
977
977
) -> Fallible < ( ) > {
978
- let tcx = self . tcx ( ) ;
979
-
980
978
debug ! (
981
- "relate_type_and_user_type(a={:?}, v={:?}, b ={:?}, locations={:?})" ,
982
- a, v, user_ty, locations
979
+ "relate_type_and_user_type(a={:?}, v={:?}, user_ty ={:?}, locations={:?})" ,
980
+ a, v, user_ty, locations,
983
981
) ;
984
982
985
- // The `TypeRelating` code assumes that "unresolved inference
986
- // variables" appear in the "a" side, so flip `Contravariant`
987
- // ambient variance to get the right relationship.
988
- let v1 = ty:: Contravariant . xform ( v) ;
989
-
990
983
match user_ty {
991
984
UserTypeAnnotation :: Ty ( canonical_ty) => {
992
985
let ( ty, _) = self . infcx
993
986
. instantiate_canonical_with_fresh_inference_vars ( DUMMY_SP , & canonical_ty) ;
994
987
995
- self . relate_types ( ty, v1, a, locations, category) ?;
988
+ // The `TypeRelating` code assumes that "unresolved inference
989
+ // variables" appear in the "a" side, so flip `Contravariant`
990
+ // ambient variance to get the right relationship.
991
+ let v1 = ty:: Contravariant . xform ( v) ;
996
992
997
- self . prove_predicate ( ty:: Predicate :: WellFormed ( ty ) , locations, category) ;
993
+ self . relate_types ( ty, v1 , a , locations, category) ? ;
998
994
}
999
995
UserTypeAnnotation :: TypeOf ( def_id, canonical_substs) => {
1000
996
let (
1001
- UserSubsts {
1002
- substs,
1003
- user_self_ty,
1004
- } ,
997
+ user_substs,
1005
998
_,
1006
999
) = self . infcx
1007
1000
. instantiate_canonical_with_fresh_inference_vars ( DUMMY_SP , & canonical_substs) ;
1008
1001
1009
- let ty = self . tcx ( ) . type_of ( def_id) ;
1010
- let ty = ty. subst ( tcx, substs) ;
1011
- debug ! ( "relate_type_and_user_type: ty of def-id is {:?}" , ty) ;
1012
- let ty = self . normalize ( ty, locations) ;
1013
-
1014
- self . relate_types ( ty, v1, a, locations, category) ?;
1015
-
1016
- if let Some ( UserSelfTy {
1017
- impl_def_id,
1018
- self_ty,
1019
- } ) = user_self_ty
1020
- {
1021
- let impl_self_ty = tcx. type_of ( impl_def_id) ;
1022
- let impl_self_ty = impl_self_ty. subst ( tcx, & substs) ;
1023
- let impl_self_ty = self . normalize ( impl_self_ty, locations) ;
1024
-
1025
- // There may be type variables in `substs` and hence
1026
- // in `impl_self_ty`, but they should all have been
1027
- // resolved to some fixed value during the first call
1028
- // to `relate`, above. Therefore, if we use
1029
- // `resolve_type_vars_if_possible` we should get to
1030
- // something without type variables. This is important
1031
- // because the `b` type in `relate_with_variance`
1032
- // below is not permitted to have inference variables.
1033
- let impl_self_ty = self . infcx . resolve_type_vars_if_possible ( & impl_self_ty) ;
1034
- assert ! ( !impl_self_ty. has_infer_types( ) ) ;
1035
-
1036
- self . eq_types ( self_ty, impl_self_ty, locations, category) ?;
1037
-
1038
- self . prove_predicate (
1039
- ty:: Predicate :: WellFormed ( impl_self_ty) ,
1040
- locations,
1041
- category,
1042
- ) ;
1043
- }
1044
-
1045
- // Prove the predicates coming along with `def_id`.
1046
- //
1047
- // Also, normalize the `instantiated_predicates`
1048
- // because otherwise we wind up with duplicate "type
1049
- // outlives" error messages.
1050
- let instantiated_predicates = tcx. predicates_of ( def_id) . instantiate ( tcx, substs) ;
1051
- let instantiated_predicates = self . fold_to_region_vid ( instantiated_predicates) ;
1052
- self . normalize_and_prove_instantiated_predicates (
1053
- instantiated_predicates,
1002
+ self . fully_perform_op (
1054
1003
locations,
1055
- ) ;
1056
-
1057
- // In addition to proving the predicates, we have to
1058
- // prove that `ty` is well-formed -- this is because
1059
- // the WF of `ty` is predicated on the substs being
1060
- // well-formed, and we haven't proven *that*. We don't
1061
- // want to prove the WF of types from `substs` directly because they
1062
- // haven't been normalized.
1063
- //
1064
- // FIXME(nmatsakis): Well, perhaps we should normalize
1065
- // them? This would only be relevant if some input
1066
- // type were ill-formed but did not appear in `ty`,
1067
- // which...could happen with normalization...
1068
- self . prove_predicate ( ty:: Predicate :: WellFormed ( ty) , locations, category) ;
1004
+ category,
1005
+ self . param_env . and ( type_op:: ascribe_user_type:: AscribeUserType :: new (
1006
+ a, v, def_id, user_substs,
1007
+ ) ) ,
1008
+ ) ?;
1069
1009
}
1070
1010
}
1071
1011
1072
1012
Ok ( ( ) )
1073
1013
}
1074
1014
1075
- /// Replace all free regions in `value` with their NLL `RegionVid`
1076
- /// equivalents; if not in NLL, does nothing. This is never
1077
- /// particularly necessary -- we'll do it lazilly as we process
1078
- /// the value anyway -- but in some specific cases it is useful to
1079
- /// normalize so we can suppress duplicate error messages.
1080
- fn fold_to_region_vid < T > ( & self , value : T ) -> T
1081
- where
1082
- T : TypeFoldable < ' tcx > ,
1083
- {
1084
- if let Some ( borrowck_context) = & self . borrowck_context {
1085
- self . tcx ( ) . fold_regions ( & value, & mut false , |r, _debruijn| {
1086
- if r. has_free_regions ( ) {
1087
- self . tcx ( ) . mk_region ( ty:: RegionKind :: ReVar (
1088
- borrowck_context. universal_regions . to_region_vid ( r) ,
1089
- ) )
1090
- } else {
1091
- r
1092
- }
1093
- } )
1094
- } else {
1095
- value
1096
- }
1097
- }
1098
-
1099
1015
fn eq_opaque_type_and_type (
1100
1016
& mut self ,
1101
1017
revealed_ty : Ty < ' tcx > ,
0 commit comments