1717//!
1818//! On success, the LUB/GLB operations return the appropriate bound. The
1919//! return value of `Equate` or `Sub` shouldn't really be used.
20- //!
21- //! ## Contravariance
22- //!
23- //! We explicitly track which argument is expected using
24- //! [TypeRelation::a_is_expected], so when dealing with contravariance
25- //! this should be correctly updated.
2620
2721use super :: glb:: Glb ;
2822use super :: lub:: Lub ;
@@ -57,7 +51,6 @@ impl<'tcx> InferCtxt<'tcx> {
5751 where
5852 R : ObligationEmittingRelation < ' tcx > ,
5953 {
60- let a_is_expected = relation. a_is_expected ( ) ;
6154 debug_assert ! ( !a. has_escaping_bound_vars( ) ) ;
6255 debug_assert ! ( !b. has_escaping_bound_vars( ) ) ;
6356
@@ -68,20 +61,20 @@ impl<'tcx> InferCtxt<'tcx> {
6861 . borrow_mut ( )
6962 . int_unification_table ( )
7063 . unify_var_var ( a_id, b_id)
71- . map_err ( |e| int_unification_error ( a_is_expected , e) ) ?;
64+ . map_err ( |e| int_unification_error ( true , e) ) ?;
7265 Ok ( a)
7366 }
7467 ( & ty:: Infer ( ty:: IntVar ( v_id) ) , & ty:: Int ( v) ) => {
75- self . unify_integral_variable ( a_is_expected , v_id, IntType ( v) )
68+ self . unify_integral_variable ( true , v_id, IntType ( v) )
7669 }
7770 ( & ty:: Int ( v) , & ty:: Infer ( ty:: IntVar ( v_id) ) ) => {
78- self . unify_integral_variable ( !a_is_expected , v_id, IntType ( v) )
71+ self . unify_integral_variable ( false , v_id, IntType ( v) )
7972 }
8073 ( & ty:: Infer ( ty:: IntVar ( v_id) ) , & ty:: Uint ( v) ) => {
81- self . unify_integral_variable ( a_is_expected , v_id, UintType ( v) )
74+ self . unify_integral_variable ( true , v_id, UintType ( v) )
8275 }
8376 ( & ty:: Uint ( v) , & ty:: Infer ( ty:: IntVar ( v_id) ) ) => {
84- self . unify_integral_variable ( !a_is_expected , v_id, UintType ( v) )
77+ self . unify_integral_variable ( false , v_id, UintType ( v) )
8578 }
8679
8780 // Relate floating-point variables to other types
@@ -90,14 +83,14 @@ impl<'tcx> InferCtxt<'tcx> {
9083 . borrow_mut ( )
9184 . float_unification_table ( )
9285 . unify_var_var ( a_id, b_id)
93- . map_err ( |e| float_unification_error ( a_is_expected , e) ) ?;
86+ . map_err ( |e| float_unification_error ( true , e) ) ?;
9487 Ok ( a)
9588 }
9689 ( & ty:: Infer ( ty:: FloatVar ( v_id) ) , & ty:: Float ( v) ) => {
97- self . unify_float_variable ( a_is_expected , v_id, v)
90+ self . unify_float_variable ( true , v_id, v)
9891 }
9992 ( & ty:: Float ( v) , & ty:: Infer ( ty:: FloatVar ( v_id) ) ) => {
100- self . unify_float_variable ( !a_is_expected , v_id, v)
93+ self . unify_float_variable ( false , v_id, v)
10194 }
10295
10396 // We don't expect `TyVar` or `Fresh*` vars at this point with lazy norm.
@@ -130,7 +123,7 @@ impl<'tcx> InferCtxt<'tcx> {
130123
131124 // All other cases of inference are errors
132125 ( & ty:: Infer ( _) , _) | ( _, & ty:: Infer ( _) ) => {
133- Err ( TypeError :: Sorts ( ty:: relate:: expected_found ( relation , a, b) ) )
126+ Err ( TypeError :: Sorts ( ty:: relate:: expected_found ( a, b) ) )
134127 }
135128
136129 // During coherence, opaque types should be treated as *possibly*
@@ -228,12 +221,12 @@ impl<'tcx> InferCtxt<'tcx> {
228221 }
229222
230223 ( ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) , _) => {
231- self . instantiate_const_var ( relation, relation . a_is_expected ( ) , vid, b) ?;
224+ self . instantiate_const_var ( relation, true , vid, b) ?;
232225 Ok ( b)
233226 }
234227
235228 ( _, ty:: ConstKind :: Infer ( InferConst :: Var ( vid) ) ) => {
236- self . instantiate_const_var ( relation, !relation . a_is_expected ( ) , vid, a) ?;
229+ self . instantiate_const_var ( relation, false , vid, a) ?;
237230 Ok ( a)
238231 }
239232
@@ -250,8 +243,6 @@ impl<'tcx> InferCtxt<'tcx> {
250243 {
251244 match relation. structurally_relate_aliases ( ) {
252245 StructurallyRelateAliases :: No => {
253- let ( a, b) = if relation. a_is_expected ( ) { ( a, b) } else { ( b, a) } ;
254-
255246 relation. register_predicates ( [ if self . next_trait_solver ( ) {
256247 ty:: PredicateKind :: AliasRelate (
257248 a. into ( ) ,
0 commit comments