@@ -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,126 +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
- let ty = self . normalize ( ty, locations) ;
1012
-
1013
- self . relate_types ( ty, v1, a, locations, category) ?;
1014
-
1015
- if let Some ( UserSelfTy {
1016
- impl_def_id,
1017
- self_ty,
1018
- } ) = user_self_ty
1019
- {
1020
- let impl_self_ty = tcx. type_of ( impl_def_id) ;
1021
- let impl_self_ty = impl_self_ty. subst ( tcx, & substs) ;
1022
- let impl_self_ty = self . normalize ( impl_self_ty, locations) ;
1023
-
1024
- // There may be type variables in `substs` and hence
1025
- // in `impl_self_ty`, but they should all have been
1026
- // resolved to some fixed value during the first call
1027
- // to `relate`, above. Therefore, if we use
1028
- // `resolve_type_vars_if_possible` we should get to
1029
- // something without type variables. This is important
1030
- // because the `b` type in `relate_with_variance`
1031
- // below is not permitted to have inference variables.
1032
- let impl_self_ty = self . infcx . resolve_type_vars_if_possible ( & impl_self_ty) ;
1033
- assert ! ( !impl_self_ty. has_infer_types( ) ) ;
1034
-
1035
- self . eq_types ( self_ty, impl_self_ty, locations, category) ?;
1036
-
1037
- self . prove_predicate (
1038
- ty:: Predicate :: WellFormed ( impl_self_ty) ,
1039
- locations,
1040
- category,
1041
- ) ;
1042
- }
1043
-
1044
- // Prove the predicates coming along with `def_id`.
1045
- //
1046
- // Also, normalize the `instantiated_predicates`
1047
- // because otherwise we wind up with duplicate "type
1048
- // outlives" error messages.
1049
- let instantiated_predicates = tcx. predicates_of ( def_id) . instantiate ( tcx, substs) ;
1050
- let instantiated_predicates = self . fold_to_region_vid ( instantiated_predicates) ;
1051
- self . normalize_and_prove_instantiated_predicates (
1052
- instantiated_predicates,
1002
+ self . fully_perform_op (
1053
1003
locations,
1054
- ) ;
1055
-
1056
- // In addition to proving the predicates, we have to
1057
- // prove that `ty` is well-formed -- this is because
1058
- // the WF of `ty` is predicated on the substs being
1059
- // well-formed, and we haven't proven *that*. We don't
1060
- // want to prove the WF of types from `substs` directly because they
1061
- // haven't been normalized.
1062
- //
1063
- // FIXME(nmatsakis): Well, perhaps we should normalize
1064
- // them? This would only be relevant if some input
1065
- // type were ill-formed but did not appear in `ty`,
1066
- // which...could happen with normalization...
1067
- 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
+ ) ?;
1068
1009
}
1069
1010
}
1070
1011
1071
1012
Ok ( ( ) )
1072
1013
}
1073
1014
1074
- /// Replace all free regions in `value` with their NLL `RegionVid`
1075
- /// equivalents; if not in NLL, does nothing. This is never
1076
- /// particularly necessary -- we'll do it lazilly as we process
1077
- /// the value anyway -- but in some specific cases it is useful to
1078
- /// normalize so we can suppress duplicate error messages.
1079
- fn fold_to_region_vid < T > ( & self , value : T ) -> T
1080
- where
1081
- T : TypeFoldable < ' tcx > ,
1082
- {
1083
- if let Some ( borrowck_context) = & self . borrowck_context {
1084
- self . tcx ( ) . fold_regions ( & value, & mut false , |r, _debruijn| {
1085
- if r. has_free_regions ( ) {
1086
- self . tcx ( ) . mk_region ( ty:: RegionKind :: ReVar (
1087
- borrowck_context. universal_regions . to_region_vid ( r) ,
1088
- ) )
1089
- } else {
1090
- r
1091
- }
1092
- } )
1093
- } else {
1094
- value
1095
- }
1096
- }
1097
-
1098
1015
fn eq_opaque_type_and_type (
1099
1016
& mut self ,
1100
1017
revealed_ty : Ty < ' tcx > ,
0 commit comments