17
17
//!
18
18
//! On success, the LUB/GLB operations return the appropriate bound. The
19
19
//! 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.
26
20
27
21
use super :: glb:: Glb ;
28
22
use super :: lub:: Lub ;
@@ -57,7 +51,6 @@ impl<'tcx> InferCtxt<'tcx> {
57
51
where
58
52
R : ObligationEmittingRelation < ' tcx > ,
59
53
{
60
- let a_is_expected = relation. a_is_expected ( ) ;
61
54
debug_assert ! ( !a. has_escaping_bound_vars( ) ) ;
62
55
debug_assert ! ( !b. has_escaping_bound_vars( ) ) ;
63
56
@@ -68,20 +61,20 @@ impl<'tcx> InferCtxt<'tcx> {
68
61
. borrow_mut ( )
69
62
. int_unification_table ( )
70
63
. 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) ) ?;
72
65
Ok ( a)
73
66
}
74
67
( & 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) )
76
69
}
77
70
( & 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) )
79
72
}
80
73
( & 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) )
82
75
}
83
76
( & 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) )
85
78
}
86
79
87
80
// Relate floating-point variables to other types
@@ -90,14 +83,14 @@ impl<'tcx> InferCtxt<'tcx> {
90
83
. borrow_mut ( )
91
84
. float_unification_table ( )
92
85
. 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) ) ?;
94
87
Ok ( a)
95
88
}
96
89
( & 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)
98
91
}
99
92
( & 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)
101
94
}
102
95
103
96
// We don't expect `TyVar` or `Fresh*` vars at this point with lazy norm.
@@ -130,7 +123,7 @@ impl<'tcx> InferCtxt<'tcx> {
130
123
131
124
// All other cases of inference are errors
132
125
( & 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) ) )
134
127
}
135
128
136
129
// During coherence, opaque types should be treated as *possibly*
@@ -228,12 +221,12 @@ impl<'tcx> InferCtxt<'tcx> {
228
221
}
229
222
230
223
( 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) ?;
232
225
Ok ( b)
233
226
}
234
227
235
228
( _, 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) ?;
237
230
Ok ( a)
238
231
}
239
232
@@ -250,8 +243,6 @@ impl<'tcx> InferCtxt<'tcx> {
250
243
{
251
244
match relation. structurally_relate_aliases ( ) {
252
245
StructurallyRelateAliases :: No => {
253
- let ( a, b) = if relation. a_is_expected ( ) { ( a, b) } else { ( b, a) } ;
254
-
255
246
relation. register_predicates ( [ if self . next_trait_solver ( ) {
256
247
ty:: PredicateKind :: AliasRelate (
257
248
a. into ( ) ,
0 commit comments