Skip to content

Commit b153656

Browse files
Fallout from removing a_is_expected
1 parent 04e2262 commit b153656

File tree

12 files changed

+46
-127
lines changed

12 files changed

+46
-127
lines changed

Diff for: compiler/rustc_borrowck/src/type_check/relate_tys.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
160160
),
161161
};
162162
let cause = ObligationCause::dummy_with_span(self.span());
163-
let obligations =
164-
infcx.handle_opaque_type(a, b, true, &cause, self.param_env())?.obligations;
163+
let obligations = infcx.handle_opaque_type(a, b, &cause, self.param_env())?.obligations;
165164
self.register_obligations(obligations);
166165
Ok(())
167166
}
@@ -330,10 +329,6 @@ impl<'bccx, 'tcx> TypeRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
330329
"nll::subtype"
331330
}
332331

333-
fn a_is_expected(&self) -> bool {
334-
true
335-
}
336-
337332
#[instrument(skip(self, info), level = "trace", ret)]
338333
fn relate_with_variance<T: Relate<'tcx>>(
339334
&mut self,

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2654,10 +2654,6 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
26542654
"SameTypeModuloInfer"
26552655
}
26562656

2657-
fn a_is_expected(&self) -> bool {
2658-
true
2659-
}
2660-
26612657
fn relate_with_variance<T: relate::Relate<'tcx>>(
26622658
&mut self,
26632659
_variance: ty::Variance,

Diff for: compiler/rustc_infer/src/infer/opaque_types.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ impl<'tcx> InferCtxt<'tcx> {
7878
span,
7979
});
8080
obligations.extend(
81-
self.handle_opaque_type(ty, ty_var, true, &cause, param_env)
82-
.unwrap()
83-
.obligations,
81+
self.handle_opaque_type(ty, ty_var, &cause, param_env).unwrap().obligations,
8482
);
8583
ty_var
8684
}
@@ -94,14 +92,12 @@ impl<'tcx> InferCtxt<'tcx> {
9492
&self,
9593
a: Ty<'tcx>,
9694
b: Ty<'tcx>,
97-
a_is_expected: bool,
9895
cause: &ObligationCause<'tcx>,
9996
param_env: ty::ParamEnv<'tcx>,
10097
) -> InferResult<'tcx, ()> {
10198
if a.references_error() || b.references_error() {
10299
return Ok(InferOk { value: (), obligations: vec![] });
103100
}
104-
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
105101
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
106102
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
107103
let def_id = def_id.expect_local();

Diff for: compiler/rustc_infer/src/infer/outlives/test_type_match.rs

-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
144144
self.tcx
145145
}
146146

147-
fn a_is_expected(&self) -> bool {
148-
true
149-
} // irrelevant
150-
151147
#[instrument(level = "trace", skip(self))]
152148
fn relate_with_variance<T: Relate<'tcx>>(
153149
&mut self,

Diff for: compiler/rustc_infer/src/infer/relate/combine.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
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
2721
use super::glb::Glb;
2822
use 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(),

Diff for: compiler/rustc_infer/src/infer/relate/generalize.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'tcx> InferCtxt<'tcx> {
130130
// instantiate_ty_var(?b, A) # expected and variance flipped
131131
// A rel A'
132132
// ```
133-
if target_is_expected == relation.a_is_expected() {
133+
if target_is_expected {
134134
relation.relate(generalized_ty, source_ty)?;
135135
} else {
136136
debug!("flip relation");
@@ -204,9 +204,9 @@ impl<'tcx> InferCtxt<'tcx> {
204204
.const_unification_table()
205205
.union_value(target_vid, ConstVariableValue::Known { value: generalized_ct });
206206

207-
// HACK: make sure that we `a_is_expected` continues to be
208-
// correct when relating the generalized type with the source.
209-
if target_is_expected == relation.a_is_expected() {
207+
// Make sure that the order is correct when relating the
208+
// generalized const and the source.
209+
if target_is_expected {
210210
relation.relate_with_variance(
211211
ty::Variance::Invariant,
212212
ty::VarianceDiagInfo::default(),
@@ -398,10 +398,6 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
398398
"Generalizer"
399399
}
400400

401-
fn a_is_expected(&self) -> bool {
402-
true
403-
}
404-
405401
fn relate_item_args(
406402
&mut self,
407403
item_def_id: DefId,

Diff for: compiler/rustc_infer/src/infer/relate/glb.rs

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
3030
self.fields.tcx()
3131
}
3232

33-
fn a_is_expected(&self) -> bool {
34-
true
35-
}
36-
3733
fn relate_with_variance<T: Relate<'tcx>>(
3834
&mut self,
3935
variance: ty::Variance,

Diff for: compiler/rustc_infer/src/infer/relate/lattice.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ where
116116
&& !this.infcx().next_trait_solver() =>
117117
{
118118
this.register_obligations(
119-
infcx
120-
.handle_opaque_type(a, b, this.a_is_expected(), this.cause(), this.param_env())?
121-
.obligations,
119+
infcx.handle_opaque_type(a, b, this.cause(), this.param_env())?.obligations,
122120
);
123121
Ok(a)
124122
}

Diff for: compiler/rustc_infer/src/infer/relate/lub.rs

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
3030
self.fields.tcx()
3131
}
3232

33-
fn a_is_expected(&self) -> bool {
34-
true
35-
}
36-
3733
fn relate_with_variance<T: Relate<'tcx>>(
3834
&mut self,
3935
variance: ty::Variance,

Diff for: compiler/rustc_infer/src/infer/relate/type_relating.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
3535
self.fields.infcx.tcx
3636
}
3737

38-
fn a_is_expected(&self) -> bool {
39-
true
40-
}
41-
4238
fn relate_with_variance<T: Relate<'tcx>>(
4339
&mut self,
4440
variance: ty::Variance,
@@ -139,7 +135,7 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
139135
{
140136
self.fields.obligations.extend(
141137
infcx
142-
.handle_opaque_type(a, b, true, &self.fields.trace.cause, self.param_env())?
138+
.handle_opaque_type(a, b, &self.fields.trace.cause, self.param_env())?
143139
.obligations,
144140
);
145141
}
@@ -158,10 +154,6 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
158154
b: ty::Region<'tcx>,
159155
) -> RelateResult<'tcx, ty::Region<'tcx>> {
160156
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
161-
162-
// FIXME -- we have more fine-grained information available
163-
// from the "cause" field, we could perhaps give more tailored
164-
// error messages.
165157
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
166158

167159
match self.ambient_variance {
@@ -184,7 +176,6 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
184176
.make_subregion(origin, a, b);
185177
}
186178
ty::Invariant => {
187-
// The order of `make_eqregion` apparently matters.
188179
self.fields
189180
.infcx
190181
.inner

Diff for: compiler/rustc_middle/src/ty/_match.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstFreshVars<'tcx> {
3737
self.tcx
3838
}
3939

40-
fn a_is_expected(&self) -> bool {
41-
true
42-
} // irrelevant
43-
4440
fn relate_with_variance<T: Relate<'tcx>>(
4541
&mut self,
4642
_: ty::Variance,
@@ -75,7 +71,7 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstFreshVars<'tcx> {
7571
) => Ok(a),
7672

7773
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
78-
Err(TypeError::Sorts(relate::expected_found(self, a, b)))
74+
Err(TypeError::Sorts(relate::expected_found(a, b)))
7975
}
8076

8177
(&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(Ty::new_error(self.tcx(), guar)),
@@ -100,7 +96,7 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstFreshVars<'tcx> {
10096
}
10197

10298
(ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => {
103-
return Err(TypeError::ConstMismatch(relate::expected_found(self, a, b)));
99+
return Err(TypeError::ConstMismatch(relate::expected_found(a, b)));
104100
}
105101

106102
_ => {}

0 commit comments

Comments
 (0)