AliasTermTy refactor: fixup compiler

This commit is contained in:
Waffle Lapkin
2026-04-07 14:21:10 +02:00
parent 3484c89c0b
commit d7986943e4
38 changed files with 321 additions and 256 deletions
@@ -2735,7 +2735,7 @@ fn param_env_with_gat_bounds<'tcx>(
_ => predicates.push(
ty::Binder::bind_with_vars(
ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(
projection_term: ty::AliasTerm::new_from_def_id(
tcx,
trait_ty.def_id,
rebased_args,
+2 -2
View File
@@ -370,10 +370,10 @@ fn bounds_from_generic_predicates<'tcx>(
let mut projections_str = vec![];
for projection in &projections {
let p = projection.skip_binder();
if bound == tcx.parent(p.projection_term.def_id)
if bound == tcx.parent(p.projection_term.def_id())
&& p.projection_term.self_ty() == ty
{
let name = tcx.item_name(p.projection_term.def_id);
let name = tcx.item_name(p.projection_term.def_id());
projections_str.push(format!("{} = {}", name, p.term));
}
}
@@ -1655,7 +1655,7 @@ fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
.map_bound(|pred| {
pred.term.as_const().map(|ct| {
let assoc_const_ty = tcx
.type_of(pred.projection_term.def_id)
.type_of(pred.projection_term.def_id())
.instantiate(tcx, pred.projection_term.args)
.skip_norm_wip();
ty::ClauseKind::ConstArgHasType(ct, assoc_const_ty)
@@ -526,7 +526,7 @@ pub(super) fn lower_assoc_item_constraint(
);
debug!(?alias_args);
ty::AliasTerm::new_from_args(tcx, assoc_item.def_id, alias_args)
ty::AliasTerm::new_from_def_id(tcx, assoc_item.def_id, alias_args)
})
};
@@ -543,7 +543,7 @@ pub(super) fn lower_assoc_item_constraint(
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
hir::Term::Const(ct) => {
let ty = projection_term.map_bound(|alias| {
tcx.type_of(alias.def_id).instantiate(tcx, alias.args).skip_norm_wip()
tcx.type_of(alias.def_id()).instantiate(tcx, alias.args).skip_norm_wip()
});
let ty = check_assoc_const_binding_type(
self,
@@ -1364,7 +1364,7 @@ fn probe_single_bound_for_assoc_item<I>(
&item_segment,
trait_ref.args,
);
ty::AliasTerm::new_from_args(
ty::AliasTerm::new_from_def_id(
tcx,
assoc_item.def_id,
alias_args,
@@ -1374,7 +1374,7 @@ fn probe_single_bound_for_assoc_item<I>(
// FIXME(mgca): code duplication with other places we lower
// the rhs' of associated const bindings
let ty = projection_term.map_bound(|alias| {
tcx.type_of(alias.def_id)
tcx.type_of(alias.def_id())
.instantiate(tcx, alias.args)
.skip_norm_wip()
});
+2 -2
View File
@@ -1057,11 +1057,11 @@ fn deduce_future_output_from_projection(
// The `Future` trait has only one associated item, `Output`,
// so check that this is what we see.
let output_assoc_item = self.tcx.associated_item_def_ids(trait_def_id)[0];
if output_assoc_item != predicate.projection_term.def_id {
if output_assoc_item != predicate.projection_term.def_id() {
span_bug!(
cause_span,
"projecting associated item `{:?}` from future, which is not Output `{:?}`",
predicate.projection_term.def_id,
predicate.projection_term.kind,
output_assoc_item,
);
}
+1 -1
View File
@@ -22,7 +22,7 @@ pub fn projection_term_to_infer(
) -> Term<'tcx> {
debug_assert!(!self.next_trait_solver());
let span = self.tcx.def_span(alias_term.def_id);
let span = self.tcx.def_span(alias_term.def_id());
let infer_var = if alias_term.kind(self.tcx).is_type() {
self.next_ty_var(span).into()
} else {
@@ -188,7 +188,8 @@ fn instantiate_var<R: PredicateEmittingRelation<Self>>(
bug!("generalized `{source_term:?} to infer, not an alias");
};
match source_alias.kind(self.tcx) {
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst => {
ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::ProjectionConst { .. } => {
// FIXME: This does not handle subtyping correctly, we could
// instead create a new inference variable `?normalized_source`, emitting
// `Projection(normalized_source, ?ty_normalized)` and
@@ -199,14 +200,14 @@ fn instantiate_var<R: PredicateEmittingRelation<Self>>(
}]);
}
// The old solver only accepts projection predicates for associated types.
ty::AliasTermKind::InherentTy
| ty::AliasTermKind::FreeTy
| ty::AliasTermKind::OpaqueTy => {
ty::AliasTermKind::InherentTy { .. }
| ty::AliasTermKind::FreeTy { .. }
| ty::AliasTermKind::OpaqueTy { .. } => {
return Err(TypeError::CyclicTy(source_term.expect_type()));
}
ty::AliasTermKind::InherentConst
| ty::AliasTermKind::FreeConst
| ty::AliasTermKind::UnevaluatedConst => {
ty::AliasTermKind::InherentConst { .. }
| ty::AliasTermKind::FreeConst { .. }
| ty::AliasTermKind::UnevaluatedConst { .. } => {
return Err(TypeError::CyclicConst(source_term.expect_const()));
}
}
@@ -132,7 +132,7 @@ fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx, AmbigArg>
let proj_ty = Ty::new_projection_from_args(
cx.tcx,
proj.projection_term.def_id,
proj.projection_term.def_id(),
proj.projection_term.args,
);
// For every instance of the projection type in the bounds,
@@ -149,7 +149,7 @@ fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx, AmbigArg>
// with `impl Send: OtherTrait`.
for (assoc_pred, assoc_pred_span) in cx
.tcx
.explicit_item_bounds(proj.projection_term.def_id)
.explicit_item_bounds(proj.projection_term.def_id())
.iter_instantiated_copied(cx.tcx, proj.projection_term.args)
.map(Unnormalized::skip_norm_wip)
{
@@ -166,7 +166,7 @@ fn variances_of(self, def_id: DefId) -> Self::VariancesOf {
fn opt_alias_variances(
self,
kind: impl Into<ty::AliasTermKind>,
kind: impl Into<ty::AliasTermKind<'tcx>>,
def_id: DefId,
) -> Option<&'tcx [ty::Variance]> {
self.opt_alias_variances(kind, def_id)
@@ -205,29 +205,27 @@ fn alias_ty_kind_from_def_id(self, def_id: DefId) -> ty::AliasTyKind<'tcx> {
}
}
fn alias_term_kind(self, alias: ty::AliasTerm<'tcx>) -> ty::AliasTermKind {
match self.def_kind(alias.def_id) {
fn alias_term_kind_from_def_id(self, def_id: DefId) -> ty::AliasTermKind<'tcx> {
match self.def_kind(def_id) {
DefKind::AssocTy => {
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(alias.def_id))
{
ty::AliasTermKind::InherentTy
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) {
ty::AliasTermKind::InherentTy { def_id }
} else {
ty::AliasTermKind::ProjectionTy
ty::AliasTermKind::ProjectionTy { def_id }
}
}
DefKind::AssocConst { .. } => {
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(alias.def_id))
{
ty::AliasTermKind::InherentConst
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) {
ty::AliasTermKind::InherentConst { def_id }
} else {
ty::AliasTermKind::ProjectionConst
ty::AliasTermKind::ProjectionConst { def_id }
}
}
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
DefKind::TyAlias => ty::AliasTermKind::FreeTy,
DefKind::Const { .. } => ty::AliasTermKind::FreeConst,
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy { def_id },
DefKind::TyAlias => ty::AliasTermKind::FreeTy { def_id },
DefKind::Const { .. } => ty::AliasTermKind::FreeConst { def_id },
DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => {
ty::AliasTermKind::UnevaluatedConst
ty::AliasTermKind::UnevaluatedConst { def_id }
}
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
}
+3 -3
View File
@@ -91,9 +91,9 @@
pub use self::opaque_types::OpaqueTypeKey;
pub use self::pattern::{Pattern, PatternKind};
pub use self::predicate::{
AliasTerm, ArgOutlivesPredicate, Clause, ClauseKind, CoercePredicate, ExistentialPredicate,
ExistentialPredicateStableCmpExt, ExistentialProjection, ExistentialTraitRef,
HostEffectPredicate, NormalizesTo, OutlivesPredicate, PolyCoercePredicate,
AliasTerm, AliasTermKind, ArgOutlivesPredicate, Clause, ClauseKind, CoercePredicate,
ExistentialPredicate, ExistentialPredicateStableCmpExt, ExistentialProjection,
ExistentialTraitRef, HostEffectPredicate, NormalizesTo, OutlivesPredicate, PolyCoercePredicate,
PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef,
PolyProjectionPredicate, PolyRegionOutlivesPredicate, PolySubtypePredicate, PolyTraitPredicate,
PolyTraitRef, PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate,
+3 -2
View File
@@ -11,6 +11,7 @@
pub type TraitRef<'tcx> = ir::TraitRef<TyCtxt<'tcx>>;
pub type AliasTerm<'tcx> = ir::AliasTerm<TyCtxt<'tcx>>;
pub type AliasTermKind<'tcx> = ir::AliasTermKind<TyCtxt<'tcx>>;
pub type ProjectionPredicate<'tcx> = ir::ProjectionPredicate<TyCtxt<'tcx>>;
pub type ExistentialPredicate<'tcx> = ir::ExistentialPredicate<TyCtxt<'tcx>>;
pub type ExistentialTraitRef<'tcx> = ir::ExistentialTraitRef<TyCtxt<'tcx>>;
@@ -656,7 +657,7 @@ mod size_asserts {
use super::*;
// tidy-alphabetical-start
static_assert_size!(PredicateKind<'_>, 32);
static_assert_size!(WithCachedTypeInfo<PredicateKind<'_>>, 56);
static_assert_size!(PredicateKind<'_>, 40);
static_assert_size!(WithCachedTypeInfo<PredicateKind<'_>>, 64);
// tidy-alphabetical-end
}
+12 -12
View File
@@ -1346,7 +1346,7 @@ fn pretty_print_inherent_projection(
&mut self,
alias_ty: ty::AliasTerm<'tcx>,
) -> Result<(), PrintError> {
let def_key = self.tcx().def_key(alias_ty.def_id);
let def_key = self.tcx().def_key(alias_ty.def_id());
self.print_path_with_generic_args(
|p| {
p.print_path_with_simple(
@@ -3158,22 +3158,22 @@ macro_rules! define_print_and_forward_display {
ty::AliasTerm<'tcx> {
match self.kind(p.tcx()) {
ty::AliasTermKind::InherentTy | ty::AliasTermKind::InherentConst => p.pretty_print_inherent_projection(*self)?,
ty::AliasTermKind::ProjectionTy => {
ty::AliasTermKind::InherentTy {..} | ty::AliasTermKind::InherentConst {..} => p.pretty_print_inherent_projection(*self)?,
ty::AliasTermKind::ProjectionTy { def_id } => {
if !(p.should_print_verbose() || with_reduced_queries())
&& p.tcx().is_impl_trait_in_trait(self.def_id)
&& p.tcx().is_impl_trait_in_trait(def_id)
{
p.pretty_print_rpitit(self.def_id, self.args)?;
p.pretty_print_rpitit(def_id, self.args)?;
} else {
p.print_def_path(self.def_id, self.args)?;
p.print_def_path(def_id, self.args)?;
}
}
ty::AliasTermKind::FreeTy
| ty::AliasTermKind::FreeConst
| ty::AliasTermKind::OpaqueTy
| ty::AliasTermKind::UnevaluatedConst
| ty::AliasTermKind::ProjectionConst => {
p.print_def_path(self.def_id, self.args)?;
ty::AliasTermKind::FreeTy { def_id }
| ty::AliasTermKind::FreeConst { def_id }
| ty::AliasTermKind::OpaqueTy { def_id }
| ty::AliasTermKind::UnevaluatedConst { def_id }
| ty::AliasTermKind::ProjectionConst { def_id } => {
p.print_def_path(def_id, self.args)?;
}
}
}
+10 -10
View File
@@ -939,24 +939,24 @@ pub fn peel_off_free_alias_tys(self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
// its (un)captured regions.
pub fn opt_alias_variances(
self,
kind: impl Into<ty::AliasTermKind>,
def_id: DefId,
kind: impl Into<ty::AliasTermKind<'tcx>>,
_def_id: DefId,
) -> Option<&'tcx [ty::Variance]> {
match kind.into() {
ty::AliasTermKind::ProjectionTy => {
ty::AliasTermKind::ProjectionTy { def_id } => {
if self.is_impl_trait_in_trait(def_id) {
Some(self.variances_of(def_id))
} else {
None
}
}
ty::AliasTermKind::OpaqueTy => Some(self.variances_of(def_id)),
ty::AliasTermKind::InherentTy
| ty::AliasTermKind::InherentConst
| ty::AliasTermKind::FreeTy
| ty::AliasTermKind::FreeConst
| ty::AliasTermKind::UnevaluatedConst
| ty::AliasTermKind::ProjectionConst => None,
ty::AliasTermKind::OpaqueTy { def_id } => Some(self.variances_of(def_id)),
ty::AliasTermKind::InherentTy { .. }
| ty::AliasTermKind::InherentConst { .. }
| ty::AliasTermKind::FreeTy { .. }
| ty::AliasTermKind::FreeConst { .. }
| ty::AliasTermKind::UnevaluatedConst { .. }
| ty::AliasTermKind::ProjectionConst { .. } => None,
}
}
}
@@ -958,7 +958,7 @@ fn projection_may_match(
source_projection: ty::Binder<I, ty::ProjectionPredicate<I>>,
target_projection: ty::AliasTerm<I>,
) -> bool {
source_projection.item_def_id() == target_projection.def_id
source_projection.item_def_id() == target_projection.def_id()
&& self
.ecx
.probe(|_| ProbeKind::ProjectionCompatibility)
@@ -982,7 +982,7 @@ fn try_eagerly_replace_alias(
return Ok(None);
}
let Some(replacements) = self.mapping.get(&alias_term.def_id) else {
let Some(replacements) = self.mapping.get(&alias_term.def_id()) else {
return Ok(None);
};
@@ -964,8 +964,8 @@ pub(super) fn relate_rigid_alias_non_alias(
//
// Alternatively we could modify `Equate` for this case by adding another
// variant to `StructurallyRelateAliases`.
let identity_args = self.fresh_args_for_item(alias.def_id);
let rigid_ctor = ty::AliasTerm::new_from_args(cx, alias.def_id, identity_args);
let identity_args = self.fresh_args_for_item(alias.def_id());
let rigid_ctor = ty::AliasTerm::new_from_args(cx, alias.kind, identity_args);
let ctor_term = rigid_ctor.to_term(cx);
let obligations = self.delegate.eq_structurally_relating_aliases(
param_env,
@@ -17,7 +17,7 @@ pub(super) fn normalize_anon_const(
if let Some(normalized_const) = self.evaluate_const(
goal.param_env,
ty::UnevaluatedConst::new(
goal.predicate.alias.def_id.try_into().unwrap(),
goal.predicate.alias.def_id().try_into().unwrap(),
goal.predicate.alias.args,
),
) {
@@ -24,16 +24,16 @@ pub(super) fn normalize_free_alias(
// Check where clauses
self.add_goals(
GoalSource::Misc,
cx.predicates_of(free_alias.def_id)
cx.predicates_of(free_alias.def_id())
.iter_instantiated(cx, free_alias.args)
.map(Unnormalized::skip_norm_wip)
.map(|pred| goal.with(cx, pred)),
);
let actual = if free_alias.kind(cx).is_type() {
cx.type_of(free_alias.def_id).instantiate(cx, free_alias.args).skip_norm_wip().into()
cx.type_of(free_alias.def_id()).instantiate(cx, free_alias.args).skip_norm_wip().into()
} else {
cx.const_of_item(free_alias.def_id)
cx.const_of_item(free_alias.def_id())
.instantiate(cx, free_alias.args)
.skip_norm_wip()
.into()
@@ -22,7 +22,7 @@ pub(super) fn normalize_inherent_associated_term(
let cx = self.cx();
let inherent = goal.predicate.alias;
let impl_def_id = cx.parent(inherent.def_id);
let impl_def_id = cx.parent(inherent.def_id());
let impl_args = self.fresh_args_for_item(impl_def_id);
// Equate impl header and add impl where clauses
@@ -46,16 +46,19 @@ pub(super) fn normalize_inherent_associated_term(
// to be very careful when changing the impl where-clauses to be productive.
self.add_goals(
GoalSource::Misc,
cx.predicates_of(inherent.def_id)
cx.predicates_of(inherent.def_id())
.iter_instantiated(cx, inherent_args)
.map(Unnormalized::skip_norm_wip)
.map(|pred| goal.with(cx, pred)),
);
let normalized = if inherent.kind(cx).is_type() {
cx.type_of(inherent.def_id).instantiate(cx, inherent_args).skip_norm_wip().into()
cx.type_of(inherent.def_id()).instantiate(cx, inherent_args).skip_norm_wip().into()
} else {
cx.const_of_item(inherent.def_id).instantiate(cx, inherent_args).skip_norm_wip().into()
cx.const_of_item(inherent.def_id())
.instantiate(cx, inherent_args)
.skip_norm_wip()
.into()
};
self.instantiate_normalizes_to_term(goal, normalized);
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
@@ -34,7 +34,7 @@ pub(super) fn compute_normalizes_to_goal(
debug_assert!(self.term_is_fully_unconstrained(goal));
let cx = self.cx();
match goal.predicate.alias.kind(cx) {
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst => {
ty::AliasTermKind::ProjectionTy { .. } | ty::AliasTermKind::ProjectionConst { .. } => {
let trait_ref = goal.predicate.alias.trait_ref(cx);
let (_, proven_via) =
self.probe(|_| ProbeKind::ShadowedEnvProbing).enter(|ecx| {
@@ -85,14 +85,14 @@ pub(super) fn compute_normalizes_to_goal(
},
)
}
ty::AliasTermKind::InherentTy | ty::AliasTermKind::InherentConst => {
ty::AliasTermKind::InherentTy { .. } | ty::AliasTermKind::InherentConst { .. } => {
self.normalize_inherent_associated_term(goal)
}
ty::AliasTermKind::OpaqueTy => self.normalize_opaque_type(goal),
ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst => {
ty::AliasTermKind::OpaqueTy { .. } => self.normalize_opaque_type(goal),
ty::AliasTermKind::FreeTy { .. } | ty::AliasTermKind::FreeConst { .. } => {
self.normalize_free_alias(goal)
}
ty::AliasTermKind::UnevaluatedConst => self.normalize_anon_const(goal),
ty::AliasTermKind::UnevaluatedConst { .. } => self.normalize_anon_const(goal),
}
}
@@ -268,8 +268,8 @@ fn consider_impl_candidate(
let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| {
let error_term = match goal.predicate.alias.kind(cx) {
ty::AliasTermKind::ProjectionTy => Ty::new_error(cx, guar).into(),
ty::AliasTermKind::ProjectionConst => Const::new_error(cx, guar).into(),
ty::AliasTermKind::ProjectionTy { .. } => Ty::new_error(cx, guar).into(),
ty::AliasTermKind::ProjectionConst { .. } => Const::new_error(cx, guar).into(),
kind => panic!("expected projection, found {kind:?}"),
};
ecx.instantiate_normalizes_to_term(goal, error_term);
@@ -384,10 +384,10 @@ fn consider_impl_candidate(
// Finally we construct the actual value of the associated type.
let term = match goal.predicate.alias.kind(cx) {
ty::AliasTermKind::ProjectionTy => {
ty::AliasTermKind::ProjectionTy { .. } => {
cx.type_of(target_item_def_id).map_bound(|ty| ty.into())
}
ty::AliasTermKind::ProjectionConst => {
ty::AliasTermKind::ProjectionConst { .. } => {
cx.const_of_item(target_item_def_id).map_bound(|ct| ct.into())
}
kind => panic!("expected projection, found {kind:?}"),
@@ -472,7 +472,7 @@ fn consider_builtin_fn_trait_candidates(
let pred = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
[goal.predicate.self_ty(), inputs],
),
term: output.into(),
@@ -526,7 +526,7 @@ fn consider_builtin_async_fn_trait_candidates(
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
[goal.predicate.self_ty(), tupled_inputs_ty],
),
output_coroutine_ty.into(),
@@ -535,7 +535,7 @@ fn consider_builtin_async_fn_trait_candidates(
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
[
I::GenericArg::from(goal.predicate.self_ty()),
tupled_inputs_ty.into(),
@@ -548,7 +548,7 @@ fn consider_builtin_async_fn_trait_candidates(
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
[goal.predicate.self_ty(), tupled_inputs_ty],
),
coroutine_return_ty.into(),
@@ -746,7 +746,11 @@ fn consider_builtin_future_candidate(
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
goal,
ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.def_id(), [self_ty]),
projection_term: ty::AliasTerm::new(
ecx.cx(),
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
[self_ty],
),
term,
}
.upcast(cx),
@@ -778,7 +782,11 @@ fn consider_builtin_iterator_candidate(
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
goal,
ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.def_id(), [self_ty]),
projection_term: ty::AliasTerm::new(
ecx.cx(),
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
[self_ty],
),
term,
}
.upcast(cx),
@@ -863,7 +871,7 @@ fn consider_builtin_coroutine_candidate(
ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new(
ecx.cx(),
goal.predicate.def_id(),
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
[self_ty, coroutine.resume_ty()],
),
term,
@@ -26,7 +26,7 @@ pub(super) fn normalize_opaque_type(
// An impossible opaque type bound is the only way this goal will fail
// e.g. assigning `impl Copy := NotCopy`
self.add_item_bounds_for_hidden_type(
opaque_ty.def_id,
opaque_ty.def_id(),
opaque_ty.args,
goal.param_env,
expected,
@@ -43,7 +43,7 @@ pub(super) fn normalize_opaque_type(
}
| TypingMode::Borrowck { defining_opaque_types } => {
let Some(def_id) = opaque_ty
.def_id
.def_id()
.as_local()
.filter(|&def_id| defining_opaque_types.contains(&def_id))
else {
@@ -110,7 +110,7 @@ pub(super) fn normalize_opaque_type(
}
TypingMode::PostBorrowckAnalysis { defined_opaque_types } => {
let Some(def_id) = opaque_ty
.def_id
.def_id()
.as_local()
.filter(|&def_id| defined_opaque_types.contains(&def_id))
else {
@@ -133,7 +133,7 @@ pub(super) fn normalize_opaque_type(
TypingMode::PostAnalysis => {
// FIXME: Add an assertion that opaque type storage is empty.
let actual =
cx.type_of(opaque_ty.def_id).instantiate(cx, opaque_ty.args).skip_norm_wip();
cx.type_of(opaque_ty.def_id()).instantiate(cx, opaque_ty.args).skip_norm_wip();
self.eq(goal.param_env, expected, actual)?;
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
}
@@ -46,8 +46,11 @@ fn stable<'cx>(
tables: &mut Tables<'cx, BridgeTys>,
cx: &CompilerCtxt<'cx, BridgeTys>,
) -> Self::T {
let ty::AliasTerm { args, def_id, .. } = self;
crate::ty::AliasTerm { def_id: tables.alias_def(*def_id), args: args.stable(tables, cx) }
let ty::AliasTerm { args, kind, .. } = self;
crate::ty::AliasTerm {
def_id: tables.alias_def(kind.def_id()),
args: args.stable(tables, cx),
}
}
}
@@ -245,7 +245,7 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
.map(move |assoc_item| {
super_poly_trait_ref.map_bound(|super_trait_ref| {
let projection_term = ty::AliasTerm::new_from_args(
let projection_term = ty::AliasTerm::new_from_def_id(
tcx,
assoc_item.def_id,
super_trait_ref.args,
@@ -202,7 +202,7 @@ pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
.kind()
.map_bound(|kind| match kind {
ty::ClauseKind::Projection(projection_predicate)
if projection_predicate.projection_term.def_id == item_def_id =>
if projection_predicate.projection_term.def_id() == item_def_id =>
{
projection_predicate.term.as_type()
}
@@ -1468,7 +1468,7 @@ enum Mismatch<'a> {
}
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
ValuePairs::Aliases(ExpectedFound { expected, .. }) => {
(false, Mismatch::Fixed(self.tcx.def_descr(expected.def_id)))
(false, Mismatch::Fixed(self.tcx.def_descr(expected.def_id())))
}
ValuePairs::Regions(_) => (false, Mismatch::Fixed("lifetime")),
ValuePairs::ExistentialTraitRef(_) => {
@@ -579,7 +579,7 @@ pub(super) fn maybe_report_ambiguity(
if let Err(guar) = self
.tcx
.ensure_result()
.coherent_trait(self.tcx.parent(data.projection_term.def_id))
.coherent_trait(self.tcx.parent(data.projection_term.def_id()))
{
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
// other `Foo` impls are incoherent.
@@ -1587,7 +1587,8 @@ pub(super) fn report_projection_error(
};
if let Some(lhs) = lhs.to_alias_term()
&& let ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst = lhs.kind(self.tcx)
&& let ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::ProjectionConst { .. } = lhs.kind(self.tcx)
&& let Some((better_type_err, expected_term)) =
derive_better_type_error(lhs, rhs)
{
@@ -1596,7 +1597,8 @@ pub(super) fn report_projection_error(
better_type_err,
)
} else if let Some(rhs) = rhs.to_alias_term()
&& let ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst = rhs.kind(self.tcx)
&& let ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::ProjectionConst { .. } = rhs.kind(self.tcx)
&& let Some((better_type_err, expected_term)) =
derive_better_type_error(rhs, lhs)
{
@@ -1741,7 +1743,7 @@ fn maybe_detailed_projection_msg(
let self_ty = projection_term.self_ty();
with_forced_trimmed_paths! {
if self.tcx.is_lang_item(projection_term.def_id, LangItem::FnOnceOutput) {
if self.tcx.is_lang_item(projection_term.def_id(), LangItem::FnOnceOutput) {
let (span, closure_span) = if let ty::Closure(def_id, _) = *self_ty.kind() {
let def_span = self.tcx.def_span(def_id);
if let Some(local_def_id) = def_id.as_local()
@@ -1445,7 +1445,7 @@ pub fn extract_callable_info(
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
&& self
.tcx
.is_lang_item(proj.projection_term.def_id, LangItem::FnOnceOutput)
.is_lang_item(proj.projection_term.def_id(), LangItem::FnOnceOutput)
// args tuple will always be args[1]
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
{
@@ -1489,7 +1489,7 @@ pub fn extract_callable_info(
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
&& self
.tcx
.is_lang_item(proj.projection_term.def_id, LangItem::FnOnceOutput)
.is_lang_item(proj.projection_term.def_id(), LangItem::FnOnceOutput)
&& proj.projection_term.self_ty() == found
// args tuple will always be args[1]
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
@@ -5256,7 +5256,7 @@ fn probe_assoc_types_at_expr(
let TypeError::Sorts(expected_found) = diff else {
continue;
};
let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. }) =
let &ty::Alias(ty::AliasTy { kind: kind @ ty::Projection { def_id }, .. }) =
expected_found.expected.kind()
else {
continue;
@@ -5265,7 +5265,7 @@ fn probe_assoc_types_at_expr(
// Make `Self` be equivalent to the type of the call chain
// expression we're looking at now, so that we can tell what
// for example `Iterator::Item` is at this point in the chain.
let args = GenericArgs::for_item(self.tcx, *def_id, |param, _| {
let args = GenericArgs::for_item(self.tcx, def_id, |param, _| {
if param.index == 0 {
debug_assert_matches!(param.kind, ty::GenericParamDefKind::Type { .. });
return prev_ty.into();
@@ -5279,7 +5279,7 @@ fn probe_assoc_types_at_expr(
// This corresponds to `<ExprTy as Iterator>::Item = _`.
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
ty::ClauseKind::Projection(ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(self.tcx, *def_id, args),
projection_term: ty::AliasTerm::new_from_args(self.tcx, kind.into(), args),
term: ty.into(),
}),
));
@@ -5296,7 +5296,7 @@ fn probe_assoc_types_at_expr(
&& let ty = self.resolve_vars_if_possible(ty)
&& !ty.is_ty_var()
{
assocs_in_this_method.push(Some((span, (*def_id, ty))));
assocs_in_this_method.push(Some((span, (def_id, ty))));
} else {
// `<ExprTy as Iterator>` didn't select, so likely we've
// reached the end of the iterator chain, like the originating
@@ -6344,12 +6344,12 @@ fn point_at_assoc_type_restriction<G: EmissionGuarantee>(
return;
};
let Some(name) = tcx
.opt_rpitit_info(proj.projection_term.def_id)
.opt_rpitit_info(proj.projection_term.def_id())
.and_then(|data| match data {
ty::ImplTraitInTraitData::Trait { fn_def_id, .. } => Some(tcx.item_name(fn_def_id)),
ty::ImplTraitInTraitData::Impl { .. } => None,
})
.or_else(|| tcx.opt_item_name(proj.projection_term.def_id))
.or_else(|| tcx.opt_item_name(proj.projection_term.def_id()))
else {
return;
};
@@ -388,8 +388,8 @@ fn detect_error_from_empty_candidates(
self.detect_error_in_self_ty_normalization(goal, pred.self_ty())?;
}
Some(ty::PredicateKind::NormalizesTo(pred))
if let ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst =
pred.alias.kind(tcx) =>
if let ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::ProjectionConst { .. } = pred.alias.kind(tcx) =>
{
self.detect_error_in_self_ty_normalization(goal, pred.alias.self_ty())?;
self.detect_non_well_formed_assoc_item(goal, pred.alias)?;
@@ -450,7 +450,8 @@ fn visit_goal(&mut self, goal: &inspect::InspectGoal<'_, 'tcx>) -> Self::Result
ty::PredicateKind::NormalizesTo(normalizes_to)
if matches!(
normalizes_to.alias.kind(tcx),
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst
ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::ProjectionConst { .. }
) =>
{
ChildMode::Trait(pred.kind().rebind(ty::TraitPredicate {
@@ -753,7 +753,7 @@ fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(tr)) => tr.trait_ref,
ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj))
if matches!(
infcx.tcx.def_kind(proj.projection_term.def_id),
infcx.tcx.def_kind(proj.projection_term.def_id()),
DefKind::AssocTy | DefKind::AssocConst { .. }
) =>
{
@@ -321,7 +321,7 @@ fn normalize_free_alias(&mut self, free: AliasTerm<'tcx>) -> Term<'tcx> {
self.obligations.extend(
infcx
.tcx
.predicates_of(free.def_id)
.predicates_of(free.def_id())
.instantiate_own(infcx.tcx, free.args)
.map(|(pred, span)| (pred.skip_norm_wip(), span))
.map(|(mut predicate, span)| {
@@ -333,7 +333,8 @@ fn normalize_free_alias(&mut self, free: AliasTerm<'tcx>) -> Term<'tcx> {
);
}
let mut cause = self.cause.clone();
cause.map_code(|code| ObligationCauseCode::TypeAlias(code, span, free.def_id));
cause
.map_code(|code| ObligationCauseCode::TypeAlias(code, span, free.def_id()));
Obligation::new(infcx.tcx, cause, self.param_env, predicate)
}),
);
@@ -341,7 +342,7 @@ fn normalize_free_alias(&mut self, free: AliasTerm<'tcx>) -> Term<'tcx> {
let res = if free.kind(infcx.tcx).is_type() {
infcx
.tcx
.type_of(free.def_id)
.type_of(free.def_id())
.instantiate(infcx.tcx, free.args)
.skip_norm_wip()
.fold_with(self)
@@ -349,7 +350,7 @@ fn normalize_free_alias(&mut self, free: AliasTerm<'tcx>) -> Term<'tcx> {
} else {
infcx
.tcx
.const_of_item(free.def_id)
.const_of_item(free.def_id())
.instantiate(infcx.tcx, free.args)
.skip_norm_wip()
.fold_with(self)
@@ -463,14 +463,16 @@ fn normalize_to_error<'a, 'tcx>(
) -> NormalizedTerm<'tcx> {
let trait_ref = ty::Binder::dummy(projection_term.trait_ref(selcx.tcx()));
let new_value = match projection_term.kind(selcx.tcx()) {
ty::AliasTermKind::ProjectionTy
| ty::AliasTermKind::InherentTy
| ty::AliasTermKind::OpaqueTy
| ty::AliasTermKind::FreeTy => selcx.infcx.next_ty_var(cause.span).into(),
ty::AliasTermKind::FreeConst
| ty::AliasTermKind::InherentConst
| ty::AliasTermKind::UnevaluatedConst
| ty::AliasTermKind::ProjectionConst => selcx.infcx.next_const_var(cause.span).into(),
ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::InherentTy { .. }
| ty::AliasTermKind::OpaqueTy { .. }
| ty::AliasTermKind::FreeTy { .. } => selcx.infcx.next_ty_var(cause.span).into(),
ty::AliasTermKind::FreeConst { .. }
| ty::AliasTermKind::InherentConst { .. }
| ty::AliasTermKind::UnevaluatedConst { .. }
| ty::AliasTermKind::ProjectionConst { .. } => {
selcx.infcx.next_const_var(cause.span).into()
}
};
let mut obligations = PredicateObligations::new();
obligations.push(Obligation {
@@ -513,7 +515,7 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
);
// Register the obligations arising from the impl and from the associated type itself.
let predicates = tcx.predicates_of(alias_term.def_id).instantiate(tcx, args);
let predicates = tcx.predicates_of(alias_term.def_id()).instantiate(tcx, args);
for (predicate, span) in predicates {
let predicate = normalize_with_depth_to(
selcx,
@@ -531,7 +533,7 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
// cause code, inherent projections will be printed with identity instantiation in
// diagnostics which is not ideal.
// Consider creating separate cause codes for this specific situation.
ObligationCauseCode::WhereClause(alias_term.def_id, span),
ObligationCauseCode::WhereClause(alias_term.def_id(), span),
);
obligations.push(Obligation::with_depth(
@@ -544,9 +546,9 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
}
let term: Term<'tcx> = if alias_term.kind(tcx).is_type() {
tcx.type_of(alias_term.def_id).instantiate(tcx, args).skip_norm_wip().into()
tcx.type_of(alias_term.def_id()).instantiate(tcx, args).skip_norm_wip().into()
} else {
tcx.const_of_item(alias_term.def_id).instantiate(tcx, args).skip_norm_wip().into()
tcx.const_of_item(alias_term.def_id()).instantiate(tcx, args).skip_norm_wip().into()
};
let mut term = selcx.infcx.resolve_vars_if_possible(term);
@@ -569,7 +571,7 @@ pub fn compute_inherent_assoc_term_args<'a, 'b, 'tcx>(
) -> ty::GenericArgsRef<'tcx> {
let tcx = selcx.tcx();
let impl_def_id = tcx.parent(alias_term.def_id);
let impl_def_id = tcx.parent(alias_term.def_id());
let impl_args = selcx.infcx.fresh_args_for_item(cause.span, impl_def_id);
let mut impl_ty = tcx.type_of(impl_def_id).instantiate(tcx, impl_args).skip_norm_wip();
@@ -747,7 +749,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
let Some(clause) = clause.as_projection_clause() else {
return ControlFlow::Continue(());
};
if clause.item_def_id() != obligation.predicate.def_id {
if clause.item_def_id() != obligation.predicate.def_id() {
return ControlFlow::Continue(());
}
@@ -815,7 +817,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
};
let env_predicates = data
.projection_bounds()
.filter(|bound| bound.item_def_id() == obligation.predicate.def_id)
.filter(|bound| bound.item_def_id() == obligation.predicate.def_id())
.map(|p| p.with_self_ty(tcx, object_ty).upcast(tcx));
assemble_candidates_from_predicates(
@@ -846,7 +848,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let bound_predicate = predicate.kind();
if let ty::ClauseKind::Projection(data) = predicate.kind().skip_binder() {
let data = bound_predicate.rebind(data);
if data.item_def_id() != obligation.predicate.def_id {
if data.item_def_id() != obligation.predicate.def_id() {
continue;
}
@@ -937,7 +939,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
match specialization_graph::assoc_def(
selcx.tcx(),
impl_data.impl_def_id,
obligation.predicate.def_id,
obligation.predicate.def_id(),
) {
Ok(node_item) => {
if node_item.is_final() {
@@ -1143,7 +1145,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
}
_ if tcx.trait_is_auto(trait_ref.def_id) => {
tcx.dcx().span_delayed_bug(
tcx.def_span(obligation.predicate.def_id),
tcx.def_span(obligation.predicate.def_id()),
"associated types not allowed on auto traits",
);
false
@@ -1325,22 +1327,22 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
coroutine_sig,
);
let ty = if tcx.is_lang_item(obligation.predicate.def_id, LangItem::CoroutineReturn) {
let ty = if tcx.is_lang_item(obligation.predicate.def_id(), LangItem::CoroutineReturn) {
return_ty
} else if tcx.is_lang_item(obligation.predicate.def_id, LangItem::CoroutineYield) {
} else if tcx.is_lang_item(obligation.predicate.def_id(), LangItem::CoroutineYield) {
yield_ty
} else {
span_bug!(
tcx.def_span(obligation.predicate.def_id),
tcx.def_span(obligation.predicate.def_id()),
"unexpected associated type: `Coroutine::{}`",
tcx.item_name(obligation.predicate.def_id),
tcx.item_name(obligation.predicate.def_id()),
);
};
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
trait_ref.args,
),
term: ty.into(),
@@ -1383,12 +1385,12 @@ fn confirm_future_candidate<'cx, 'tcx>(
coroutine_sig,
);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name(), sym::Output);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Output);
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
trait_ref.args,
),
term: return_ty.into(),
@@ -1429,12 +1431,12 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
gen_sig,
);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name(), sym::Item);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Item);
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
trait_ref.args,
),
term: yield_ty.into(),
@@ -1475,7 +1477,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
gen_sig,
);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name(), sym::Item);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Item);
let ty::Adt(_poll_adt, args) = *yield_ty.kind() else {
bug!();
@@ -1488,7 +1490,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
trait_ref.args,
),
term: item_ty.into(),
@@ -1506,7 +1508,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
) -> Progress<'tcx> {
let tcx = selcx.tcx();
let self_ty = obligation.predicate.self_ty();
let item_def_id = obligation.predicate.def_id;
let item_def_id = obligation.predicate.def_id();
let trait_def_id = tcx.parent(item_def_id);
let args = tcx.mk_args(&[self_ty.into()]);
let (term, obligations) = if tcx.is_lang_item(trait_def_id, LangItem::DiscriminantKind) {
@@ -1569,7 +1571,11 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
};
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(tcx, item_def_id, args),
projection_term: ty::AliasTerm::new_from_args(
tcx,
ty::AliasTermKind::ProjectionTy { def_id: item_def_id },
args,
),
term,
};
@@ -1702,7 +1708,11 @@ fn confirm_callable_candidate<'cx, 'tcx>(
flag,
)
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(tcx, fn_once_output_def_id, trait_ref.args),
projection_term: ty::AliasTerm::new_from_args(
tcx,
ty::AliasTermKind::ProjectionTy { def_id: fn_once_output_def_id },
trait_ref.args,
),
term: ret_type.into(),
});
@@ -1723,7 +1733,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => obligation.predicate.args.region_at(2),
ty::ClosureKind::FnOnce => tcx.lifetimes.re_static,
};
let item_name = tcx.item_name(obligation.predicate.def_id);
let item_name = tcx.item_name(obligation.predicate.def_id());
let poly_cache_entry = match *self_ty.kind() {
ty::CoroutineClosure(def_id, args) => {
@@ -1787,12 +1797,12 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
let projection_term = match item_name {
sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
[self_ty, sig.tupled_inputs_ty],
),
sym::CallRefFuture => ty::AliasTerm::new(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
[ty::GenericArg::from(self_ty), sig.tupled_inputs_ty.into(), env_region.into()],
),
name => bug!("no such associated type: {name}"),
@@ -1817,12 +1827,12 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
let projection_term = match item_name {
sym::CallOnceFuture | sym::Output => ty::AliasTerm::new(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
[self_ty, Ty::new_tup(tcx, sig.inputs())],
),
sym::CallRefFuture => ty::AliasTerm::new(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
[
ty::GenericArg::from(self_ty),
Ty::new_tup(tcx, sig.inputs()).into(),
@@ -1850,11 +1860,11 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
};
let projection_term = match item_name {
sym::CallOnceFuture | sym::Output => {
ty::AliasTerm::new(tcx, obligation.predicate.def_id, [self_ty, sig.inputs()[0]])
ty::AliasTerm::new(tcx, obligation.predicate.kind, [self_ty, sig.inputs()[0]])
}
sym::CallRefFuture => ty::AliasTerm::new(
tcx,
obligation.predicate.def_id,
obligation.predicate.kind,
[ty::GenericArg::from(self_ty), sig.inputs()[0].into(), env_region.into()],
),
name => bug!("no such associated type: {name}"),
@@ -1890,7 +1900,7 @@ fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
let predicate = ty::ProjectionPredicate {
projection_term: ty::AliasTerm::new_from_args(
selcx.tcx(),
obligation.predicate.def_id,
obligation.predicate.kind,
obligation.predicate.args,
),
term: ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
@@ -1986,7 +1996,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
let ImplSourceUserDefinedData { impl_def_id, args, mut nested } = impl_impl_source;
let assoc_item_id = obligation.predicate.def_id;
let assoc_item_id = obligation.predicate.def_id();
let trait_def_id = tcx.impl_trait_id(impl_def_id);
let param_env = obligation.param_env;
@@ -2074,7 +2084,7 @@ fn assoc_term_own_obligations<'cx, 'tcx>(
) {
let tcx = selcx.tcx();
let predicates = tcx
.predicates_of(obligation.predicate.def_id)
.predicates_of(obligation.predicate.def_id())
.instantiate_own(tcx, obligation.predicate.args);
for (predicate, span) in predicates {
let normalized = normalize_with_depth_to(
@@ -2097,7 +2107,7 @@ fn assoc_term_own_obligations<'cx, 'tcx>(
ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
ObligationCauseCode::WhereClause(obligation.predicate.def_id, span),
ObligationCauseCode::WhereClause(obligation.predicate.def_id(), span),
)
};
nested.push(Obligation::with_depth(
@@ -256,8 +256,8 @@ fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
}
}
ty::Projection { def_id } | ty::Inherent { def_id } | ty::Free { def_id } => self
.try_fold_free_or_assoc(ty::AliasTerm::new(self.cx(), def_id, data.args))?
kind @ (ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }) => self
.try_fold_free_or_assoc(ty::AliasTerm::new(self.cx(), kind.into(), data.args))?
.expect_type(),
};
@@ -285,9 +285,7 @@ fn try_fold_const(
constant,
|constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env),
),
_ => self
.try_fold_free_or_assoc(ty::AliasTerm::new(self.cx(), uv.def, uv.args))?
.expect_const(),
_ => self.try_fold_free_or_assoc(ty::AliasTerm::from(uv))?.expect_const(),
};
debug!(?constant, ?self.param_env);
constant.try_super_fold_with(self)
@@ -329,16 +327,17 @@ fn try_fold_free_or_assoc(
debug!("QueryNormalizer: c_term = {:#?}", c_term);
debug!("QueryNormalizer: orig_values = {:#?}", orig_values);
let result = match term.kind(tcx) {
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst => {
ty::AliasTermKind::ProjectionTy { .. } | ty::AliasTermKind::ProjectionConst { .. } => {
tcx.normalize_canonicalized_projection(c_term)
}
ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst => {
ty::AliasTermKind::FreeTy { .. } | ty::AliasTermKind::FreeConst { .. } => {
tcx.normalize_canonicalized_free_alias(c_term)
}
ty::AliasTermKind::InherentTy | ty::AliasTermKind::InherentConst => {
ty::AliasTermKind::InherentTy { .. } | ty::AliasTermKind::InherentConst { .. } => {
tcx.normalize_canonicalized_inherent_projection(c_term)
}
kind @ (ty::AliasTermKind::OpaqueTy | ty::AliasTermKind::UnevaluatedConst) => {
kind @ (ty::AliasTermKind::OpaqueTy { .. }
| ty::AliasTermKind::UnevaluatedConst { .. }) => {
unreachable!("did not expect {kind:?} due to match arm above")
}
}?;
@@ -382,7 +381,7 @@ fn try_fold_free_or_assoc(
&& (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
|| matches!(
term.kind(tcx),
ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst
ty::AliasTermKind::FreeTy { .. } | ty::AliasTermKind::FreeConst { .. }
))
{
res.try_fold_with(self)
@@ -1761,7 +1761,7 @@ pub(super) fn match_projection_projections(
env_predicate: PolyProjectionPredicate<'tcx>,
potentially_unnormalized_candidates: bool,
) -> ProjectionMatchesProjection {
debug_assert_eq!(obligation.predicate.def_id, env_predicate.item_def_id());
debug_assert_eq!(obligation.predicate.def_id(), env_predicate.item_def_id());
let mut nested_obligations = PredicateObligations::new();
let infer_predicate = self.infcx.instantiate_binder_with_fresh_vars(
@@ -1797,7 +1797,7 @@ pub(super) fn match_projection_projections(
});
if is_match {
let generics = self.tcx().generics_of(obligation.predicate.def_id);
let generics = self.tcx().generics_of(obligation.predicate.def_id());
// FIXME(generic_associated_types): Addresses aggressive inference in #92917.
// If this type is a GAT, and of the GAT args resolve to something new,
// that means that we must have newly inferred something about the GAT.
@@ -478,7 +478,7 @@ fn add_wf_preds_for_alias_term(&mut self, data: ty::AliasTerm<'tcx>) {
// `i32: Clone`
// `i32: Copy`
// ]
let obligations = self.nominal_obligations(data.def_id, data.args);
let obligations = self.nominal_obligations(data.def_id(), data.args);
self.out.extend(obligations);
self.add_wf_preds_for_projection_args(data.args);
@@ -507,7 +507,7 @@ fn add_wf_preds_for_inherent_projection(&mut self, data: ty::AliasTerm<'tcx>) {
self.recursion_depth,
&mut self.out,
);
let obligations = self.nominal_obligations(data.def_id, args);
let obligations = self.nominal_obligations(data.def_id(), args);
self.out.extend(obligations);
}
@@ -1001,7 +1001,7 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
.map_bound(|p| {
p.term.as_const().map(|ct| {
let assoc_const_ty = tcx
.type_of(p.projection_term.def_id)
.type_of(p.projection_term.def_id())
.instantiate(tcx, p.projection_term.args)
.skip_norm_wip();
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(
@@ -75,7 +75,7 @@ fn normalize_canonicalized_free_alias<'tcx>(
tcx.infer_ctxt().enter_canonical_trait_query(
&goal,
|ocx, ParamEnvAnd { param_env, value: goal }| {
let obligations = tcx.predicates_of(goal.def_id).instantiate_own(tcx, goal.args).map(
let obligations = tcx.predicates_of(goal.def_id()).instantiate_own(tcx, goal.args).map(
|(predicate, span)| {
traits::Obligation::new(
tcx,
@@ -87,9 +87,9 @@ fn normalize_canonicalized_free_alias<'tcx>(
);
ocx.register_obligations(obligations);
let normalized_term = if goal.kind(tcx).is_type() {
tcx.type_of(goal.def_id).instantiate(tcx, goal.args).skip_norm_wip().into()
tcx.type_of(goal.def_id()).instantiate(tcx, goal.args).skip_norm_wip().into()
} else {
tcx.const_of_item(goal.def_id).instantiate(tcx, goal.args).skip_norm_wip().into()
tcx.const_of_item(goal.def_id()).instantiate(tcx, goal.args).skip_norm_wip().into()
};
Ok(NormalizationResult { normalized_term })
},
+4 -3
View File
@@ -197,10 +197,10 @@ fn canonical_param_env_cache_get_or_insert<R>(
type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>;
fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf;
// FIXME: remove `def_id` param after `AliasTermKind` contains `def_id` within
// TODO: remove `def_id` param after `AliasTermKind` contains `def_id` within
fn opt_alias_variances(
self,
kind: impl Into<ty::AliasTermKind>,
kind: impl Into<ty::AliasTermKind<Self>>,
def_id: Self::DefId,
) -> Option<Self::VariancesOf>;
@@ -215,7 +215,8 @@ fn type_of_opaque_hir_typeck(self, def_id: Self::LocalDefId)
fn alias_ty_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTyKind<Self>;
fn alias_term_kind(self, alias: ty::AliasTerm<Self>) -> ty::AliasTermKind;
// FIXME: remove in favor of explicit construction
fn alias_term_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTermKind<Self>;
fn trait_ref_and_own_args_for_alias(
self,
+98 -61
View File
@@ -3,9 +3,7 @@
use derive_where::derive_where;
#[cfg(feature = "nightly")]
use rustc_macros::{
Decodable, Decodable_NoContext, Encodable, Encodable_NoContext, HashStable_NoContext,
};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_type_ir_macros::{
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
};
@@ -532,7 +530,7 @@ pub fn with_self_ty(&self, interner: I, self_ty: I::Ty) -> ProjectionPredicate<I
ProjectionPredicate {
projection_term: AliasTerm::new(
interner,
self.def_id,
interner.alias_term_kind_from_def_id(self.def_id),
[self_ty.into()].iter().chain(self.args.iter()),
),
term: self.term,
@@ -544,7 +542,7 @@ pub fn erase_self_ty(interner: I, projection_predicate: ProjectionPredicate<I>)
projection_predicate.projection_term.args.type_at(0);
Self {
def_id: projection_predicate.projection_term.def_id,
def_id: projection_predicate.projection_term.def_id(),
args: interner.mk_args(&projection_predicate.projection_term.args.as_slice()[1..]),
term: projection_predicate.term,
use_existential_projection_new_instead: (),
@@ -563,6 +561,7 @@ pub fn item_def_id(&self) -> I::DefId {
}
#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)]
#[derive(Lift_Generic)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
@@ -610,42 +609,55 @@ pub enum AliasTermKind<I: Interner> {
InherentConst { def_id: I::DefId },
}
impl AliasTermKind {
impl<I: Interner> AliasTermKind<I> {
pub fn descr(self) -> &'static str {
match self {
AliasTermKind::ProjectionTy => "associated type",
AliasTermKind::ProjectionConst => "associated const",
AliasTermKind::InherentTy => "inherent associated type",
AliasTermKind::InherentConst => "inherent associated const",
AliasTermKind::OpaqueTy => "opaque type",
AliasTermKind::FreeTy => "type alias",
AliasTermKind::FreeConst => "unevaluated constant",
AliasTermKind::UnevaluatedConst => "unevaluated constant",
AliasTermKind::ProjectionTy { .. } => "associated type",
AliasTermKind::ProjectionConst { .. } => "associated const",
AliasTermKind::InherentTy { .. } => "inherent associated type",
AliasTermKind::InherentConst { .. } => "inherent associated const",
AliasTermKind::OpaqueTy { .. } => "opaque type",
AliasTermKind::FreeTy { .. } => "type alias",
AliasTermKind::FreeConst { .. } => "unevaluated constant",
AliasTermKind::UnevaluatedConst { .. } => "unevaluated constant",
}
}
pub fn is_type(self) -> bool {
match self {
AliasTermKind::ProjectionTy
| AliasTermKind::InherentTy
| AliasTermKind::OpaqueTy
| AliasTermKind::FreeTy => true,
AliasTermKind::ProjectionTy { .. }
| AliasTermKind::InherentTy { .. }
| AliasTermKind::OpaqueTy { .. }
| AliasTermKind::FreeTy { .. } => true,
AliasTermKind::UnevaluatedConst
| AliasTermKind::ProjectionConst
| AliasTermKind::InherentConst
| AliasTermKind::FreeConst => false,
AliasTermKind::UnevaluatedConst { .. }
| AliasTermKind::ProjectionConst { .. }
| AliasTermKind::InherentConst { .. }
| AliasTermKind::FreeConst { .. } => false,
}
}
// FIXME: replace with explicit matches
pub fn def_id(self) -> I::DefId {
let (AliasTermKind::ProjectionTy { def_id }
| AliasTermKind::InherentTy { def_id }
| AliasTermKind::OpaqueTy { def_id }
| AliasTermKind::FreeTy { def_id }
| AliasTermKind::UnevaluatedConst { def_id }
| AliasTermKind::ProjectionConst { def_id }
| AliasTermKind::FreeConst { def_id }
| AliasTermKind::InherentConst { def_id }) = self;
def_id
}
}
impl<I: Interner> From<ty::AliasTyKind<I>> for AliasTermKind {
impl<I: Interner> From<ty::AliasTyKind<I>> for AliasTermKind<I> {
fn from(value: ty::AliasTyKind<I>) -> Self {
match value {
ty::Projection { .. } => AliasTermKind::ProjectionTy,
ty::Opaque { .. } => AliasTermKind::OpaqueTy,
ty::Free { .. } => AliasTermKind::FreeTy,
ty::Inherent { .. } => AliasTermKind::InherentTy,
ty::Projection { def_id } => AliasTermKind::ProjectionTy { def_id },
ty::Opaque { def_id } => AliasTermKind::OpaqueTy { def_id },
ty::Free { def_id } => AliasTermKind::FreeTy { def_id },
ty::Inherent { def_id } => AliasTermKind::InherentTy { def_id },
}
}
}
@@ -674,6 +686,8 @@ pub struct AliasTerm<I: Interner> {
/// while for TAIT it is used for the generic parameters of the alias.
pub args: I::GenericArgs,
#[type_foldable(identity)]
#[type_visitable(ignore)]
pub kind: AliasTermKind<I>,
/// This field exists to prevent the creation of `AliasTerm` without using [`AliasTerm::new_from_args`].
@@ -684,57 +698,72 @@ pub struct AliasTerm<I: Interner> {
impl<I: Interner> Eq for AliasTerm<I> {}
impl<I: Interner> AliasTerm<I> {
pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTerm<I> {
interner.debug_assert_args_compatible(def_id, args);
AliasTerm { def_id, args, _use_alias_term_new_instead: () }
pub fn new_from_args(
interner: I,
kind: AliasTermKind<I>,
args: I::GenericArgs,
) -> AliasTerm<I> {
interner.debug_assert_args_compatible(kind.def_id(), args);
AliasTerm { kind, args, _use_alias_term_new_instead: () }
}
pub fn new(
interner: I,
def_id: I::DefId,
kind: AliasTermKind<I>,
args: impl IntoIterator<Item: Into<I::GenericArg>>,
) -> AliasTerm<I> {
let args = interner.mk_args_from_iter(args.into_iter().map(Into::into));
Self::new_from_args(interner, def_id, args)
Self::new_from_args(interner, kind, args)
}
pub fn new_from_def_id(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTerm<I> {
let kind = interner.alias_term_kind_from_def_id(def_id);
Self::new_from_args(interner, kind, args)
}
pub fn expect_ty(self, interner: I) -> ty::AliasTy<I> {
let kind = match self.kind(interner) {
AliasTermKind::ProjectionTy => AliasTyKind::Projection { def_id: self.def_id },
AliasTermKind::InherentTy => AliasTyKind::Inherent { def_id: self.def_id },
AliasTermKind::OpaqueTy => AliasTyKind::Opaque { def_id: self.def_id },
AliasTermKind::FreeTy => AliasTyKind::Free { def_id: self.def_id },
AliasTermKind::InherentConst
| AliasTermKind::FreeConst
| AliasTermKind::UnevaluatedConst
| AliasTermKind::ProjectionConst => {
AliasTermKind::ProjectionTy { def_id } => AliasTyKind::Projection { def_id },
AliasTermKind::InherentTy { def_id } => AliasTyKind::Inherent { def_id },
AliasTermKind::OpaqueTy { def_id } => AliasTyKind::Opaque { def_id },
AliasTermKind::FreeTy { def_id } => AliasTyKind::Free { def_id },
AliasTermKind::InherentConst { .. }
| AliasTermKind::FreeConst { .. }
| AliasTermKind::UnevaluatedConst { .. }
| AliasTermKind::ProjectionConst { .. } => {
panic!("Cannot turn `UnevaluatedConst` into `AliasTy`")
}
};
ty::AliasTy { kind, args: self.args, _use_alias_ty_new_instead: () }
}
pub fn kind(self, interner: I) -> AliasTermKind {
interner.alias_term_kind(self)
// FIXME: remove this function (access the field instead)
pub fn kind(self, _interner: I) -> AliasTermKind<I> {
self.kind
}
// FIXME: replace with explicit matches
pub fn def_id(self) -> I::DefId {
self.kind.def_id()
}
pub fn to_term(self, interner: I) -> I::Term {
let alias_ty_kind = match self.kind(interner) {
AliasTermKind::FreeConst
| AliasTermKind::InherentConst
| AliasTermKind::UnevaluatedConst
| AliasTermKind::ProjectionConst => {
AliasTermKind::FreeConst { def_id }
| AliasTermKind::InherentConst { def_id }
| AliasTermKind::UnevaluatedConst { def_id }
| AliasTermKind::ProjectionConst { def_id } => {
return I::Const::new_unevaluated(
interner,
ty::UnevaluatedConst::new(self.def_id.try_into().unwrap(), self.args),
ty::UnevaluatedConst::new(def_id.try_into().unwrap(), self.args),
)
.into();
}
AliasTermKind::ProjectionTy => ty::Projection { def_id: self.def_id },
AliasTermKind::InherentTy => ty::Inherent { def_id: self.def_id },
AliasTermKind::OpaqueTy => ty::Opaque { def_id: self.def_id },
AliasTermKind::FreeTy => ty::Free { def_id: self.def_id },
AliasTermKind::ProjectionTy { def_id } => ty::Projection { def_id },
AliasTermKind::InherentTy { def_id } => ty::Inherent { def_id },
AliasTermKind::OpaqueTy { def_id } => ty::Opaque { def_id },
AliasTermKind::FreeTy { def_id } => ty::Free { def_id },
};
Ty::new_alias(interner, ty::AliasTy::new_from_args(interner, alias_ty_kind, self.args))
@@ -751,7 +780,7 @@ pub fn self_ty(self) -> I::Ty {
pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self {
AliasTerm::new(
interner,
self.def_id,
self.kind,
[self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
)
}
@@ -760,11 +789,11 @@ pub fn trait_def_id(self, interner: I) -> I::TraitId {
assert!(
matches!(
self.kind(interner),
AliasTermKind::ProjectionTy | AliasTermKind::ProjectionConst
AliasTermKind::ProjectionTy { .. } | AliasTermKind::ProjectionConst { .. }
),
"expected a projection"
);
interner.parent(self.def_id).try_into().unwrap()
interner.parent(self.def_id()).try_into().unwrap()
}
/// Extracts the underlying trait reference and own args from this projection.
@@ -772,7 +801,7 @@ pub fn trait_def_id(self, interner: I) -> I::TraitId {
/// then this function would return a `T: StreamingIterator` trait reference and
/// `['a]` as the own args.
pub fn trait_ref_and_own_args(self, interner: I) -> (TraitRef<I>, I::GenericArgsSlice) {
interner.trait_ref_and_own_args_for_alias(self.def_id, self.args)
interner.trait_ref_and_own_args_for_alias(self.def_id(), self.args)
}
/// Extracts the underlying trait reference from this projection.
@@ -813,7 +842,7 @@ pub fn rebase_inherent_args_onto_impl(
) -> I::GenericArgs {
debug_assert!(matches!(
self.kind(interner),
AliasTermKind::InherentTy | AliasTermKind::InherentConst
AliasTermKind::InherentTy { .. } | AliasTermKind::InherentConst { .. }
));
interner.mk_args_from_iter(impl_args.iter().chain(self.args.iter().skip(1)))
}
@@ -821,13 +850,21 @@ pub fn rebase_inherent_args_onto_impl(
impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> {
fn from(ty: ty::AliasTy<I>) -> Self {
AliasTerm { args: ty.args, def_id: ty.kind.def_id(), _use_alias_term_new_instead: () }
AliasTerm {
args: ty.args,
kind: AliasTermKind::from(ty.kind),
_use_alias_term_new_instead: (),
}
}
}
impl<I: Interner> From<ty::UnevaluatedConst<I>> for AliasTerm<I> {
fn from(ct: ty::UnevaluatedConst<I>) -> Self {
AliasTerm { args: ct.args, def_id: ct.def.into(), _use_alias_term_new_instead: () }
AliasTerm {
args: ct.args,
kind: AliasTermKind::UnevaluatedConst { def_id: ct.def.into() },
_use_alias_term_new_instead: (),
}
}
}
@@ -873,7 +910,7 @@ pub fn trait_def_id(self, interner: I) -> I::TraitId {
}
pub fn def_id(self) -> I::DefId {
self.projection_term.def_id
self.projection_term.def_id()
}
}
@@ -894,7 +931,7 @@ pub fn term(&self) -> ty::Binder<I, I::Term> {
/// associated type, which is in `tcx.associated_item(projection_def_id()).container`.
pub fn item_def_id(&self) -> I::DefId {
// Ok to skip binder since trait `DefId` does not care about regions.
self.skip_binder().projection_term.def_id
self.skip_binder().projection_term.def_id()
}
}
@@ -933,7 +970,7 @@ pub fn trait_def_id(self, interner: I) -> I::TraitId {
}
pub fn def_id(self) -> I::DefId {
self.alias.def_id
self.alias.def_id()
}
}
+12 -12
View File
@@ -236,27 +236,27 @@ fn relate<R: TypeRelation<I>>(
a: ty::AliasTerm<I>,
b: ty::AliasTerm<I>,
) -> RelateResult<I, ty::AliasTerm<I>> {
if a.def_id != b.def_id {
Err(TypeError::ProjectionMismatched(ExpectedFound::new(a.def_id, b.def_id)))
if a.def_id() != b.def_id() {
Err(TypeError::ProjectionMismatched(ExpectedFound::new(a.def_id(), b.def_id())))
} else {
let args = match a.kind(relation.cx()) {
ty::AliasTermKind::OpaqueTy => relate_args_with_variances(
ty::AliasTermKind::OpaqueTy { .. } => relate_args_with_variances(
relation,
relation.cx().variances_of(a.def_id),
relation.cx().variances_of(a.def_id()),
a.args,
b.args,
)?,
ty::AliasTermKind::ProjectionTy
| ty::AliasTermKind::FreeConst
| ty::AliasTermKind::FreeTy
| ty::AliasTermKind::InherentTy
| ty::AliasTermKind::InherentConst
| ty::AliasTermKind::UnevaluatedConst
| ty::AliasTermKind::ProjectionConst => {
ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::FreeConst { .. }
| ty::AliasTermKind::FreeTy { .. }
| ty::AliasTermKind::InherentTy { .. }
| ty::AliasTermKind::InherentConst { .. }
| ty::AliasTermKind::UnevaluatedConst { .. }
| ty::AliasTermKind::ProjectionConst { .. } => {
relate_args_invariantly(relation, a.args, b.args)?
}
};
Ok(ty::AliasTerm::new_from_args(relation.cx(), a.def_id, args))
Ok(ty::AliasTerm::new_from_args(relation.cx(), a.kind, args))
}
}
}