Skip to content

Commit d39fa4d

Browse files
Remove StructurallyRelateAliases from non-SolverRelating relations
1 parent 81d9951 commit d39fa4d

File tree

12 files changed

+85
-124
lines changed

12 files changed

+85
-124
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
134134

135135
self.type_checker.infcx.instantiate_ty_var(
136136
self,
137+
StructurallyRelateAliases::No,
137138
opaque_is_expected,
138139
ty_vid,
139140
variance,
@@ -353,9 +354,14 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
353354
);
354355
}
355356

356-
(&ty::Infer(ty::TyVar(a_vid)), _) => {
357-
infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?
358-
}
357+
(&ty::Infer(ty::TyVar(a_vid)), _) => infcx.instantiate_ty_var(
358+
self,
359+
StructurallyRelateAliases::No,
360+
true,
361+
a_vid,
362+
self.ambient_variance,
363+
b,
364+
)?,
359365

360366
(
361367
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
@@ -524,10 +530,6 @@ impl<'bccx, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating
524530
self.locations.span(self.type_checker.body)
525531
}
526532

527-
fn structurally_relate_aliases(&self) -> StructurallyRelateAliases {
528-
StructurallyRelateAliases::No
529-
}
530-
531533
fn param_env(&self) -> ty::ParamEnv<'tcx> {
532534
self.type_checker.param_env
533535
}

compiler/rustc_infer/src/infer/at.rs

+2-43
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_middle::bug;
2929
use rustc_middle::ty::{Const, ImplSubject};
3030

3131
use super::*;
32-
use crate::infer::relate::{Relate, StructurallyRelateAliases, TypeRelation};
32+
use crate::infer::relate::{Relate, TypeRelation};
3333
use crate::traits::Obligation;
3434

3535
/// Whether we should define opaque types or just treat them opaquely.
@@ -160,7 +160,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
160160
self.param_env,
161161
define_opaque_types,
162162
);
163-
fields.equate(StructurallyRelateAliases::No).relate(expected, actual)?;
163+
fields.equate().relate(expected, actual)?;
164164
Ok(InferOk {
165165
value: (),
166166
obligations: fields
@@ -178,28 +178,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
178178
})
179179
}
180180

181-
/// Equates `expected` and `found` while structurally relating aliases.
182-
/// This should only be used inside of the next generation trait solver
183-
/// when relating rigid aliases.
184-
pub fn eq_structurally_relating_aliases<T>(
185-
self,
186-
expected: T,
187-
actual: T,
188-
) -> InferResult<'tcx, ()>
189-
where
190-
T: ToTrace<'tcx>,
191-
{
192-
assert!(self.infcx.next_trait_solver());
193-
let mut fields = CombineFields::new(
194-
self.infcx,
195-
ToTrace::to_trace(self.cause, true, expected, actual),
196-
self.param_env,
197-
DefineOpaqueTypes::Yes,
198-
);
199-
fields.equate(StructurallyRelateAliases::Yes).relate(expected, actual)?;
200-
Ok(InferOk { value: (), obligations: fields.into_obligations() })
201-
}
202-
203181
pub fn relate<T>(
204182
self,
205183
define_opaque_types: DefineOpaqueTypes,
@@ -249,25 +227,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
249227
Ok(fields.goals)
250228
}
251229

252-
/// Used in the new solver since we don't care about tracking an `ObligationCause`.
253-
pub fn eq_structurally_relating_aliases_no_trace<T>(
254-
self,
255-
expected: T,
256-
actual: T,
257-
) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, NoSolution>
258-
where
259-
T: Relate<TyCtxt<'tcx>>,
260-
{
261-
let mut fields = CombineFields::new(
262-
self.infcx,
263-
TypeTrace::dummy(self.cause),
264-
self.param_env,
265-
DefineOpaqueTypes::Yes,
266-
);
267-
fields.equate(StructurallyRelateAliases::Yes).relate(expected, actual)?;
268-
Ok(fields.goals)
269-
}
270-
271230
/// Computes the least-upper-bound, or mutual supertype, of two
272231
/// values. The order of the arguments doesn't matter, but since
273232
/// this can result in an error (e.g., if asked to compute LUB of

compiler/rustc_infer/src/infer/context.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_middle::ty::fold::TypeFoldable;
77
use rustc_middle::ty::{self, Ty, TyCtxt};
88
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
99
use rustc_type_ir::relate::combine::PredicateEmittingRelation;
10+
use rustc_type_ir::relate::StructurallyRelateAliases;
1011
use rustc_type_ir::InferCtxtLike;
1112

1213
use super::{BoundRegionConversionTime, InferCtxt, SubregionOrigin};
@@ -195,13 +196,15 @@ impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
195196
fn instantiate_ty_var_raw<R: PredicateEmittingRelation<Self>>(
196197
&self,
197198
relation: &mut R,
199+
structurally_relate_aliases: StructurallyRelateAliases,
198200
target_is_expected: bool,
199201
target_vid: rustc_type_ir::TyVid,
200202
instantiation_variance: rustc_type_ir::Variance,
201203
source_ty: Ty<'tcx>,
202204
) -> RelateResult<'tcx, ()> {
203205
self.instantiate_ty_var(
204206
relation,
207+
structurally_relate_aliases,
205208
target_is_expected,
206209
target_vid,
207210
instantiation_variance,
@@ -235,11 +238,18 @@ impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
235238
fn instantiate_const_var_raw<R: PredicateEmittingRelation<Self>>(
236239
&self,
237240
relation: &mut R,
241+
structurally_relate_aliases: StructurallyRelateAliases,
238242
target_is_expected: bool,
239243
target_vid: rustc_type_ir::ConstVid,
240244
source_ct: ty::Const<'tcx>,
241245
) -> RelateResult<'tcx, ()> {
242-
self.instantiate_const_var(relation, target_is_expected, target_vid, source_ct)
246+
self.instantiate_const_var(
247+
relation,
248+
structurally_relate_aliases,
249+
target_is_expected,
250+
target_vid,
251+
source_ct,
252+
)
243253
}
244254

245255
fn set_tainted_by_errors(&self, e: ErrorGuaranteed) {

compiler/rustc_infer/src/infer/relate/combine.rs

+19-36
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,8 @@ impl<'tcx> InferCtxt<'tcx> {
134134
}
135135

136136
(_, ty::Alias(..)) | (ty::Alias(..), _) if self.next_trait_solver() => {
137-
match relation.structurally_relate_aliases() {
138-
StructurallyRelateAliases::Yes => {
139-
relate::structurally_relate_tys(relation, a, b)
140-
}
141-
StructurallyRelateAliases::No => {
142-
relation.register_alias_relate_predicate(a, b);
143-
Ok(a)
144-
}
145-
}
137+
relation.register_alias_relate_predicate(a, b);
138+
Ok(a)
146139
}
147140

148141
// All other cases of inference are errors
@@ -215,12 +208,12 @@ impl<'tcx> InferCtxt<'tcx> {
215208
}
216209

217210
(ty::ConstKind::Infer(InferConst::Var(vid)), _) => {
218-
self.instantiate_const_var(relation, true, vid, b)?;
211+
self.instantiate_const_var(relation, StructurallyRelateAliases::No, true, vid, b)?;
219212
Ok(b)
220213
}
221214

222215
(_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
223-
self.instantiate_const_var(relation, false, vid, a)?;
216+
self.instantiate_const_var(relation, StructurallyRelateAliases::No, false, vid, a)?;
224217
Ok(a)
225218
}
226219

@@ -235,24 +228,17 @@ impl<'tcx> InferCtxt<'tcx> {
235228
(ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..))
236229
if self.tcx.features().generic_const_exprs || self.next_trait_solver() =>
237230
{
238-
match relation.structurally_relate_aliases() {
239-
StructurallyRelateAliases::No => {
240-
relation.register_predicates([if self.next_trait_solver() {
241-
ty::PredicateKind::AliasRelate(
242-
a.into(),
243-
b.into(),
244-
ty::AliasRelationDirection::Equate,
245-
)
246-
} else {
247-
ty::PredicateKind::ConstEquate(a, b)
248-
}]);
249-
250-
Ok(b)
251-
}
252-
StructurallyRelateAliases::Yes => {
253-
relate::structurally_relate_consts(relation, a, b)
254-
}
255-
}
231+
relation.register_predicates([if self.next_trait_solver() {
232+
ty::PredicateKind::AliasRelate(
233+
a.into(),
234+
b.into(),
235+
ty::AliasRelationDirection::Equate,
236+
)
237+
} else {
238+
ty::PredicateKind::ConstEquate(a, b)
239+
}]);
240+
241+
Ok(b)
256242
}
257243
_ => relate::structurally_relate_consts(relation, a, b),
258244
}
@@ -282,19 +268,16 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
282268
self.infcx.tcx
283269
}
284270

285-
pub fn equate<'a>(
286-
&'a mut self,
287-
structurally_relate_aliases: StructurallyRelateAliases,
288-
) -> TypeRelating<'a, 'infcx, 'tcx> {
289-
TypeRelating::new(self, structurally_relate_aliases, ty::Invariant)
271+
pub fn equate<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> {
272+
TypeRelating::new(self, ty::Invariant)
290273
}
291274

292275
pub fn sub<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> {
293-
TypeRelating::new(self, StructurallyRelateAliases::No, ty::Covariant)
276+
TypeRelating::new(self, ty::Covariant)
294277
}
295278

296279
pub fn sup<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> {
297-
TypeRelating::new(self, StructurallyRelateAliases::No, ty::Contravariant)
280+
TypeRelating::new(self, ty::Contravariant)
298281
}
299282

300283
pub fn lub<'a>(&'a mut self) -> Lub<'a, 'infcx, 'tcx> {

compiler/rustc_infer/src/infer/relate/generalize.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl<'tcx> InferCtxt<'tcx> {
3535
pub fn instantiate_ty_var<R: PredicateEmittingRelation<InferCtxt<'tcx>>>(
3636
&self,
3737
relation: &mut R,
38+
structurally_relate_aliases: StructurallyRelateAliases,
3839
target_is_expected: bool,
3940
target_vid: ty::TyVid,
4041
instantiation_variance: ty::Variance,
@@ -53,7 +54,7 @@ impl<'tcx> InferCtxt<'tcx> {
5354
let Generalization { value_may_be_infer: generalized_ty, has_unconstrained_ty_var } = self
5455
.generalize(
5556
relation.span(),
56-
relation.structurally_relate_aliases(),
57+
structurally_relate_aliases,
5758
target_vid,
5859
instantiation_variance,
5960
source_ty,
@@ -183,6 +184,7 @@ impl<'tcx> InferCtxt<'tcx> {
183184
pub(crate) fn instantiate_const_var<R: PredicateEmittingRelation<InferCtxt<'tcx>>>(
184185
&self,
185186
relation: &mut R,
187+
structurally_relate_aliases: StructurallyRelateAliases,
186188
target_is_expected: bool,
187189
target_vid: ty::ConstVid,
188190
source_ct: ty::Const<'tcx>,
@@ -192,7 +194,7 @@ impl<'tcx> InferCtxt<'tcx> {
192194
let Generalization { value_may_be_infer: generalized_ct, has_unconstrained_ty_var } = self
193195
.generalize(
194196
relation.span(),
195-
relation.structurally_relate_aliases(),
197+
structurally_relate_aliases,
196198
target_vid,
197199
ty::Invariant,
198200
source_ct,

compiler/rustc_infer/src/infer/relate/glb.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_span::Span;
77

88
use super::combine::{CombineFields, PredicateEmittingRelation};
99
use super::lattice::{self, LatticeDir};
10-
use super::StructurallyRelateAliases;
1110
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
1211
use crate::traits::ObligationCause;
1312

@@ -35,7 +34,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
3534
b: T,
3635
) -> RelateResult<'tcx, T> {
3736
match variance {
38-
ty::Invariant => self.fields.equate(StructurallyRelateAliases::No).relate(a, b),
37+
ty::Invariant => self.fields.equate().relate(a, b),
3938
ty::Covariant => self.relate(a, b),
4039
// FIXME(#41044) -- not correct, need test
4140
ty::Bivariant => Ok(a),
@@ -125,10 +124,6 @@ impl<'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
125124
self.fields.trace.span()
126125
}
127126

128-
fn structurally_relate_aliases(&self) -> StructurallyRelateAliases {
129-
StructurallyRelateAliases::No
130-
}
131-
132127
fn param_env(&self) -> ty::ParamEnv<'tcx> {
133128
self.fields.param_env
134129
}

compiler/rustc_infer/src/infer/relate/lub.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_span::Span;
77

88
use super::combine::{CombineFields, PredicateEmittingRelation};
99
use super::lattice::{self, LatticeDir};
10-
use super::StructurallyRelateAliases;
1110
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
1211
use crate::traits::ObligationCause;
1312

@@ -35,7 +34,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
3534
b: T,
3635
) -> RelateResult<'tcx, T> {
3736
match variance {
38-
ty::Invariant => self.fields.equate(StructurallyRelateAliases::No).relate(a, b),
37+
ty::Invariant => self.fields.equate().relate(a, b),
3938
ty::Covariant => self.relate(a, b),
4039
// FIXME(#41044) -- not correct, need test
4140
ty::Bivariant => Ok(a),
@@ -124,10 +123,6 @@ impl<'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
124123
self.fields.trace.span()
125124
}
126125

127-
fn structurally_relate_aliases(&self) -> StructurallyRelateAliases {
128-
StructurallyRelateAliases::No
129-
}
130-
131126
fn param_env(&self) -> ty::ParamEnv<'tcx> {
132127
self.fields.param_env
133128
}

compiler/rustc_infer/src/infer/relate/type_relating.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
1313
/// Enforce that `a` is equal to or a subtype of `b`.
1414
pub struct TypeRelating<'combine, 'a, 'tcx> {
1515
fields: &'combine mut CombineFields<'a, 'tcx>,
16-
structurally_relate_aliases: StructurallyRelateAliases,
1716
ambient_variance: ty::Variance,
1817
}
1918

2019
impl<'combine, 'infcx, 'tcx> TypeRelating<'combine, 'infcx, 'tcx> {
2120
pub fn new(
2221
f: &'combine mut CombineFields<'infcx, 'tcx>,
23-
structurally_relate_aliases: StructurallyRelateAliases,
2422
ambient_variance: ty::Variance,
2523
) -> TypeRelating<'combine, 'infcx, 'tcx> {
26-
TypeRelating { fields: f, structurally_relate_aliases, ambient_variance }
24+
TypeRelating { fields: f, ambient_variance }
2725
}
2826
}
2927

@@ -116,11 +114,19 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
116114
}
117115

118116
(&ty::Infer(TyVar(a_vid)), _) => {
119-
infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?;
117+
infcx.instantiate_ty_var(
118+
self,
119+
StructurallyRelateAliases::No,
120+
true,
121+
a_vid,
122+
self.ambient_variance,
123+
b,
124+
)?;
120125
}
121126
(_, &ty::Infer(TyVar(b_vid))) => {
122127
infcx.instantiate_ty_var(
123128
self,
129+
StructurallyRelateAliases::No,
124130
false,
125131
b_vid,
126132
self.ambient_variance.xform(ty::Contravariant),
@@ -302,10 +308,6 @@ impl<'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for TypeRelating<'_, '_, '
302308
self.fields.param_env
303309
}
304310

305-
fn structurally_relate_aliases(&self) -> StructurallyRelateAliases {
306-
self.structurally_relate_aliases
307-
}
308-
309311
fn register_predicates(
310312
&mut self,
311313
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,

0 commit comments

Comments
 (0)