Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,27 +597,7 @@ impl<'b, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_
);
}

fn register_alias_relate_predicate(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
ty::Covariant => ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Subtype,
),
// a :> b is b <: a
ty::Contravariant => ty::PredicateKind::AliasRelate(
b.into(),
a.into(),
ty::AliasRelationDirection::Subtype,
),
ty::Invariant => ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Equate,
),
ty::Bivariant => {
unreachable!("cannot defer an alias-relate goal with Bivariant variance (yet?)")
}
})]);
fn ambient_variance(&self) -> ty::Variance {
self.ambient_variance
}
}
13 changes: 0 additions & 13 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,19 +737,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
{
self.resolve_vars_if_possible(trait_pred)
}
// Eagerly process alias-relate obligations in new trait solver,
// since these can be emitted in the process of solving trait goals,
// but we need to constrain vars before processing goals mentioning
// them.
Some(ty::PredicateKind::AliasRelate(..)) => {
let ocx = ObligationCtxt::new(self);
ocx.register_obligation(obligation);
if !ocx.try_evaluate_obligations().is_empty() {
return Err(TypeError::Mismatch);
}
coercion.obligations.extend(ocx.into_pending_obligations());
continue;
}

@lcnr lcnr Jun 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun, this was dead code before 😁

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yeah, saw this when I was deleting it and I was like "uuuh wait, why... AliasRelate in the old solver?? huh??" :P

_ => {
coercion.obligations.push(obligation);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
| ty::PredicateKind::DynCompatible(..)
| ty::PredicateKind::NormalizesTo(..)
| ty::PredicateKind::AliasRelate(..)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..))
Expand Down
72 changes: 54 additions & 18 deletions compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use rustc_hir::def_id::DefId;
use rustc_middle::bug;
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::{
self, AliasRelationDirection, InferConst, Term, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
TypeVisitableExt, TypeVisitor,
self, InferConst, Term, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
TypeVisitor,
};
use rustc_span::Span;
use tracing::{debug, instrument, warn};
Expand Down Expand Up @@ -168,25 +168,61 @@ impl<'tcx> InferCtxt<'tcx> {
// cyclic type. We instead delay the unification in case
// the alias can be normalized to something which does not
// mention `?0`.
let Some(source_alias) = source_term.to_alias_term() else {
bug!("generalized `{source_term:?} to infer, not an alias");
};
if self.next_trait_solver() {
let (lhs, rhs, direction) = match instantiation_variance {
ty::Invariant => {
(generalized_term, source_term, AliasRelationDirection::Equate)
}
ty::Covariant => {
(generalized_term, source_term, AliasRelationDirection::Subtype)
}
ty::Contravariant => {
(source_term, generalized_term, AliasRelationDirection::Subtype)
if let Some(generalized_ty) = generalized_term.as_type() {
match instantiation_variance {
ty::Invariant => relation.register_predicates([ty::ProjectionPredicate {
projection_term: source_alias.into(),
term: generalized_ty.into(),
}]),
ty::Covariant => {
// Generate a new var, then do:
// `source_alias == ?A && ?A <: generalized_ty`
let new_var = self.next_ty_var(relation.span());
relation.register_predicates([
ty::PredicateKind::Subtype(ty::SubtypePredicate {
a_is_expected: !target_is_expected,
a: new_var,
b: generalized_ty,
}),
ty::PredicateKind::Clause(ty::ClauseKind::Projection(
ty::ProjectionPredicate {
projection_term: source_alias.into(),
term: new_var.into(),
},
)),
]);
}
ty::Contravariant => {
// a :> b is b <: a
let new_var = self.next_ty_var(relation.span());
relation.register_predicates([
ty::PredicateKind::Subtype(ty::SubtypePredicate {
a_is_expected: target_is_expected,
a: generalized_ty,
b: new_var,
}),
ty::PredicateKind::Clause(ty::ClauseKind::Projection(
ty::ProjectionPredicate {
projection_term: source_alias.into(),
term: new_var.into(),
},
)),
]);
}
ty::Bivariant => unreachable!("bivariant generalization"),
}
ty::Bivariant => unreachable!("bivariant generalization"),
};

relation.register_predicates([ty::PredicateKind::AliasRelate(lhs, rhs, direction)]);
} else {
debug_assert_eq!(instantiation_variance, ty::Variance::Invariant);
relation.register_predicates([ty::ProjectionPredicate {
projection_term: source_alias,
term: generalized_term,
}]);
}
} else {
let Some(source_alias) = source_term.to_alias_term() else {
bug!("generalized `{source_term:?} to infer, not an alias");
};
match source_alias.kind {
ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::ProjectionConst { .. } => {
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_infer/src/infer/relate/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,8 @@ impl<'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
}))
}

fn register_alias_relate_predicate(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
// FIXME(deferred_projection_equality): This isn't right, I think?
ty::AliasRelationDirection::Equate,
))]);
fn ambient_variance(&self) -> ty::Variance {
// FIXME(deferred_projection_equality): This isn't right, I think?
ty::Variance::Invariant
}
}
24 changes: 2 additions & 22 deletions compiler/rustc_infer/src/infer/relate/type_relating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,27 +384,7 @@ impl<'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for TypeRelating<'_, 'tcx>
}))
}

fn register_alias_relate_predicate(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
ty::Covariant => ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Subtype,
),
// a :> b is b <: a
ty::Contravariant => ty::PredicateKind::AliasRelate(
b.into(),
a.into(),
ty::AliasRelationDirection::Subtype,
),
ty::Invariant => ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Equate,
),
ty::Bivariant => {
unreachable!("Expected bivariance to be handled in relate_with_variance")
}
})]);
fn ambient_variance(&self) -> ty::Variance {
self.ambient_variance
}
}
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3269,11 +3269,6 @@ define_print! {
}
ty::PredicateKind::Ambiguous => write!(p, "ambiguous")?,
ty::PredicateKind::NormalizesTo(data) => data.print(p)?,
ty::PredicateKind::AliasRelate(t1, t2, dir) => {
t1.print(p)?;
write!(p, " {dir} ")?;
t2.print(p)?;
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_next_trait_solver/src/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ pub(super) fn instantiate_and_apply_query_response<D, I>(
param_env: I::ParamEnv,
original_values: &[I::GenericArg],
response: CanonicalResponse<I>,
visible_for_leak_check: VisibleForLeakCheck,
span: I::Span,
) -> (NestedNormalizationGoals<I>, Certainty)
where
Expand All @@ -121,7 +120,15 @@ where
match region_constraints {
ExternalRegionConstraints::Old(r) => register_region_constraints(
delegate,
r.iter().map(|(c, vis)| (*c, vis.and(visible_for_leak_check))),
r.iter().map(|(c, vis)| {
// FIXME: We should revisit and consider removing this after *assumptions on
// binders* is available, like once we had done in the stabilization of
// `-Znext-solver=coherence`(#121848).
// We ignore constraints from the nested goals in leak check. This is to match with
// the old solver's behavior, which has separated evaluation and fulfillment, and
// the former doesn't consider outlives obligations from the later.
(*c, vis.and(VisibleForLeakCheck::No))
}),
span,
),
ExternalRegionConstraints::NextGen(r) => {
Expand Down
93 changes: 0 additions & 93 deletions compiler/rustc_next_trait_solver/src/solve/alias_relate.rs

This file was deleted.

27 changes: 2 additions & 25 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,29 +729,11 @@ where
let has_changed =
if !has_only_region_constraints(response) { HasChanged::Yes } else { HasChanged::No };

// FIXME: We should revisit and consider removing this after
// *assumptions on binders* is available, like once we had done in the
// stabilization of `-Znext-solver=coherence`(#121848).
// We ignore constraints from the nested goals in leak check. This is to match
// with the old solver's behavior, which has separated evaluation and fulfillment,
// and the former doesn't consider outlives obligations from the later.
let vis = match goal.predicate.kind().skip_binder() {
ty::PredicateKind::Clause(_)
| ty::PredicateKind::DynCompatible(_)
| ty::PredicateKind::Subtype(_)
| ty::PredicateKind::Coerce(_)
| ty::PredicateKind::ConstEquate(_, _)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::NormalizesTo(_) => VisibleForLeakCheck::No,
ty::PredicateKind::AliasRelate(_, _, _) => VisibleForLeakCheck::Yes,
};

let (normalization_nested_goals, certainty) = instantiate_and_apply_query_response(
self.delegate,
goal.param_env,
&orig_values,
response,
vis,
self.origin_span,
);

Expand Down Expand Up @@ -961,11 +943,6 @@ where
ty::PredicateKind::NormalizesTo(predicate) => {
ecx.compute_normalizes_to_goal(Goal { param_env, predicate })?
}
ty::PredicateKind::AliasRelate(lhs, rhs, direction) => ecx
.compute_alias_relate_goal(Goal {
param_env,
predicate: (lhs, rhs, direction),
})?,
ty::PredicateKind::Ambiguous => {
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)?
}
Expand Down Expand Up @@ -1272,7 +1249,8 @@ where
let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
for &goal in goals.iter() {
let source = match goal.predicate.kind().skip_binder() {
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {
ty::PredicateKind::Subtype { .. }
| ty::PredicateKind::Clause(ty::ClauseKind::Projection(..)) => {
GoalSource::TypeRelating
}
// FIXME(-Znext-solver=coinductive): should these WF goals also be unproductive?
Expand Down Expand Up @@ -1810,7 +1788,6 @@ pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>,
goal.param_env,
&proof_tree.orig_values,
response,
VisibleForLeakCheck::Yes,
origin_span,
);

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_next_trait_solver/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! For a high-level overview of how this solver works, check out the relevant
//! section of the rustc-dev-guide.

mod alias_relate;
mod assembly;
mod effect_goals;
mod eval_ctxt;
Expand Down
Loading
Loading