Skip to content

Commit 83c5653

Browse files
committed
Reproduce direct solver region registration failures
1 parent c5f2ffd commit 83c5653

2 files changed

Lines changed: 46 additions & 286 deletions

File tree

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 3 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,78 +1251,6 @@ where
12511251
self.relate(param_env, lhs, ty::Variance::Invariant, rhs)
12521252
}
12531253

1254-
/// This should be used when relating a rigid alias with another type.
1255-
///
1256-
/// Normally we emit a nested `AliasRelate` when equating an inference
1257-
/// variable and an alias. This causes us to instead constrain the inference
1258-
/// variable to the alias without emitting a nested alias relate goals.
1259-
#[instrument(level = "trace", skip(self, param_env), ret)]
1260-
pub(super) fn relate_rigid_alias_non_alias(
1261-
&mut self,
1262-
param_env: I::ParamEnv,
1263-
alias: ty::AliasTerm<I>,
1264-
variance: ty::Variance,
1265-
term: I::Term,
1266-
) -> Result<(), NoSolutionOrRerunNonErased> {
1267-
// NOTE: this check is purely an optimization, the structural eq would
1268-
// always fail if the term is not an inference variable.
1269-
if term.is_infer() {
1270-
let cx = self.cx();
1271-
// We need to relate `alias` to `term` treating only the outermost
1272-
// constructor as rigid, relating any contained generic arguments as
1273-
// normal. We do this by first structurally equating the `term`
1274-
// with the alias constructor instantiated with unconstrained infer vars,
1275-
// and then relate this with the whole `alias`.
1276-
//
1277-
// Alternatively we could modify `Equate` for this case by adding another
1278-
// variant to `StructurallyRelateAliases`.
1279-
let def_id = match alias.kind {
1280-
ty::AliasTermKind::ProjectionTy { def_id } => def_id.into(),
1281-
ty::AliasTermKind::InherentTy { def_id } => def_id.into(),
1282-
ty::AliasTermKind::OpaqueTy { def_id } => def_id.into(),
1283-
ty::AliasTermKind::FreeTy { def_id } => def_id.into(),
1284-
ty::AliasTermKind::AnonConst { def_id } => def_id.into(),
1285-
ty::AliasTermKind::ProjectionConst { def_id } => def_id.into(),
1286-
ty::AliasTermKind::FreeConst { def_id } => def_id.into(),
1287-
ty::AliasTermKind::InherentConst { def_id } => def_id.into(),
1288-
};
1289-
let identity_args = self.fresh_args_for_item(def_id);
1290-
let rigid_ctor = alias.with_args(cx, identity_args);
1291-
let ctor_term = rigid_ctor.to_term(cx);
1292-
self.eq_structurally_relating_aliases(param_env, term, ctor_term)?;
1293-
self.relate(param_env, alias, variance, rigid_ctor)
1294-
} else {
1295-
Err(NoSolution.into())
1296-
}
1297-
}
1298-
1299-
/// This should only be used when we're either instantiating a previously
1300-
/// unconstrained "return value" or when we're sure that all aliases in
1301-
/// the types are rigid.
1302-
#[instrument(level = "trace", skip(self, param_env), ret)]
1303-
pub(super) fn eq_structurally_relating_aliases<T: Relate<I>>(
1304-
&mut self,
1305-
param_env: I::ParamEnv,
1306-
lhs: T,
1307-
rhs: T,
1308-
) -> Result<(), NoSolutionOrRerunNonErased> {
1309-
let result = if self.cx().assumptions_on_binders() {
1310-
let (goals, region_constraints) =
1311-
self.delegate.eq_structurally_relating_aliases_with_region_constraints(
1312-
param_env,
1313-
lhs,
1314-
rhs,
1315-
self.origin_span,
1316-
)?;
1317-
self.register_solver_region_constraint(region_constraints);
1318-
goals
1319-
} else {
1320-
self.delegate.eq_structurally_relating_aliases(param_env, lhs, rhs, self.origin_span)?
1321-
};
1322-
assert_eq!(result, vec![]);
1323-
Ok(())
1324-
}
1325-
13261254
#[instrument(level = "trace", skip(self, param_env), ret)]
13271255
pub(super) fn sub<T: Relate<I>>(
13281256
&mut self,
@@ -1341,19 +1269,7 @@ where
13411269
variance: ty::Variance,
13421270
rhs: T,
13431271
) -> Result<(), NoSolutionOrRerunNonErased> {
1344-
let goals = if self.cx().assumptions_on_binders() {
1345-
let (goals, region_constraints) = self.delegate.relate_with_region_constraints(
1346-
param_env,
1347-
lhs,
1348-
variance,
1349-
rhs,
1350-
self.origin_span,
1351-
)?;
1352-
self.register_solver_region_constraint(region_constraints);
1353-
goals
1354-
} else {
1355-
self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?
1356-
};
1272+
let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
13571273
for &goal in goals.iter() {
13581274
let source = match goal.predicate.kind().skip_binder() {
13591275
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {
@@ -1375,30 +1291,12 @@ where
13751291
/// goals correctly.
13761292
#[instrument(level = "trace", skip(self, param_env), ret)]
13771293
pub(super) fn eq_and_get_goals<T: Relate<I>>(
1378-
&mut self,
1294+
&self,
13791295
param_env: I::ParamEnv,
13801296
lhs: T,
13811297
rhs: T,
13821298
) -> Result<Vec<Goal<I, I::Predicate>>, NoSolution> {
1383-
if self.cx().assumptions_on_binders() {
1384-
let (goals, region_constraints) = self.delegate.relate_with_region_constraints(
1385-
param_env,
1386-
lhs,
1387-
ty::Variance::Invariant,
1388-
rhs,
1389-
self.origin_span,
1390-
)?;
1391-
self.register_solver_region_constraint(region_constraints);
1392-
Ok(goals)
1393-
} else {
1394-
Ok(self.delegate.relate(
1395-
param_env,
1396-
lhs,
1397-
ty::Variance::Invariant,
1398-
rhs,
1399-
self.origin_span,
1400-
)?)
1401-
}
1299+
Ok(self.delegate.relate(param_env, lhs, ty::Variance::Invariant, rhs, self.origin_span)?)
14021300
}
14031301

14041302
pub(super) fn instantiate_binder_with_infer<T: TypeFoldable<I> + Copy>(

0 commit comments

Comments
 (0)