mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Auto merge of #155392 - WaffleLapkin:alias-termmm, r=BoxyUwU
`AliasTerm` refactor follow up to https://github.com/rust-lang/rust/pull/154758 tracking issue: https://github.com/rust-lang/rust/issues/154941
This commit is contained in:
@@ -177,7 +177,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) {
|
||||
| ty::Coroutine(def_id, args) => self.visit_closure_args(def_id, args),
|
||||
|
||||
ty::Alias(ty::AliasTy { kind, args, .. })
|
||||
if let Some(variances) = self.cx().opt_alias_variances(kind, kind.def_id()) =>
|
||||
if let Some(variances) = self.cx().opt_alias_variances(kind) =>
|
||||
{
|
||||
// Skip lifetime parameters that are not captured, since they do
|
||||
// not need member constraints registered for them; we'll erase
|
||||
|
||||
@@ -501,7 +501,7 @@ fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, RegionVid> {
|
||||
}
|
||||
|
||||
ty::Alias(ty::AliasTy { kind, args, .. })
|
||||
if let Some(variances) = tcx.opt_alias_variances(kind, kind.def_id()) =>
|
||||
if let Some(variances) = tcx.opt_alias_variances(kind) =>
|
||||
{
|
||||
let args = tcx.mk_args_from_iter(std::iter::zip(variances, args.iter()).map(
|
||||
|(&v, s)| {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) {
|
||||
} else {
|
||||
// Skip lifetime parameters that are not captured, since they do
|
||||
// not need to be live.
|
||||
let variances = tcx.opt_alias_variances(kind, kind.def_id());
|
||||
let variances = tcx.opt_alias_variances(kind);
|
||||
|
||||
for (idx, s) in args.iter().enumerate() {
|
||||
if variances.map(|variances| variances[idx]) != Some(ty::Bivariant) {
|
||||
|
||||
@@ -485,7 +485,7 @@ fn alias_ty_must_outlive(
|
||||
&& (alias_ty.has_infer_regions() || matches!(kind, ty::Opaque { .. }))
|
||||
{
|
||||
debug!("no declared bounds");
|
||||
let opt_variances = self.tcx.opt_alias_variances(kind, kind.def_id());
|
||||
let opt_variances = self.tcx.opt_alias_variances(kind);
|
||||
self.args_must_outlive(alias_ty.args, origin, region, opt_variances);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -184,11 +184,12 @@ fn instantiate_var<R: PredicateEmittingRelation<Self>>(
|
||||
|
||||
relation.register_predicates([ty::PredicateKind::AliasRelate(lhs, rhs, direction)]);
|
||||
} else {
|
||||
let Some(source_alias) = source_term.to_alias_term() else {
|
||||
let Some(source_alias) = source_term.to_alias_term(self.tcx) else {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@@ -755,7 +756,8 @@ fn consts(
|
||||
// path), as doing this new No path breaks some GCE things. I expect GCE to be
|
||||
// ripped out soon so this shouldn't matter soon.
|
||||
StructurallyRelateAliases::No if !self.cx().features().generic_const_exprs() => {
|
||||
self.generalize_alias_term(uv.into()).map(|v| v.expect_const())
|
||||
self.generalize_alias_term(ty::AliasTerm::from_unevaluated_const(self.cx(), uv))
|
||||
.map(|v| v.expect_const())
|
||||
}
|
||||
_ => {
|
||||
let ty::UnevaluatedConst { def, args } = uv;
|
||||
|
||||
@@ -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,10 +166,9 @@ fn variances_of(self, def_id: DefId) -> Self::VariancesOf {
|
||||
|
||||
fn opt_alias_variances(
|
||||
self,
|
||||
kind: impl Into<ty::AliasTermKind>,
|
||||
def_id: DefId,
|
||||
kind: impl Into<ty::AliasTermKind<'tcx>>,
|
||||
) -> Option<&'tcx [ty::Variance]> {
|
||||
self.opt_alias_variances(kind, def_id)
|
||||
self.opt_alias_variances(kind)
|
||||
}
|
||||
|
||||
fn type_of(self, def_id: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
|
||||
@@ -205,29 +204,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:?}"),
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
@@ -607,14 +607,14 @@ pub fn into_arg(self) -> GenericArg<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
|
||||
pub fn to_alias_term(self, tcx: TyCtxt<'tcx>) -> Option<AliasTerm<'tcx>> {
|
||||
match self.kind() {
|
||||
TermKind::Ty(ty) => match *ty.kind() {
|
||||
ty::Alias(alias_ty) => Some(alias_ty.into()),
|
||||
_ => None,
|
||||
},
|
||||
TermKind::Const(ct) => match ct.kind() {
|
||||
ConstKind::Unevaluated(uv) => Some(uv.into()),
|
||||
ConstKind::Unevaluated(uv) => Some(AliasTerm::from_unevaluated_const(tcx, uv)),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,6 +9,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>>;
|
||||
@@ -642,7 +643,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
|
||||
}
|
||||
|
||||
@@ -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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,24 +939,23 @@ 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>>,
|
||||
) -> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ pub(super) fn compute_alias_relate_goal(
|
||||
// `{type error}` if the alias still contains infer vars, so we also
|
||||
// accept alias-relate goals where one of the terms is an error.
|
||||
debug_assert!(
|
||||
lhs.to_alias_term().is_some()
|
||||
|| rhs.to_alias_term().is_some()
|
||||
lhs.to_alias_term(self.cx()).is_some()
|
||||
|| rhs.to_alias_term(self.cx()).is_some()
|
||||
|| lhs.is_error()
|
||||
|| rhs.is_error()
|
||||
);
|
||||
|
||||
// Structurally normalize the lhs.
|
||||
let lhs = if let Some(alias) = lhs.to_alias_term() {
|
||||
let lhs = if let Some(alias) = lhs.to_alias_term(self.cx()) {
|
||||
let term = self.next_term_infer_of_kind(lhs);
|
||||
self.add_goal(
|
||||
GoalSource::TypeRelating,
|
||||
@@ -60,7 +60,7 @@ pub(super) fn compute_alias_relate_goal(
|
||||
};
|
||||
|
||||
// Structurally normalize the rhs.
|
||||
let rhs = if let Some(alias) = rhs.to_alias_term() {
|
||||
let rhs = if let Some(alias) = rhs.to_alias_term(self.cx()) {
|
||||
let term = self.next_term_infer_of_kind(rhs);
|
||||
self.add_goal(
|
||||
GoalSource::TypeRelating,
|
||||
@@ -87,7 +87,7 @@ pub(super) fn compute_alias_relate_goal(
|
||||
ty::AliasRelationDirection::Equate => ty::Invariant,
|
||||
ty::AliasRelationDirection::Subtype => ty::Covariant,
|
||||
};
|
||||
match (lhs.to_alias_term(), rhs.to_alias_term()) {
|
||||
match (lhs.to_alias_term(self.cx()), rhs.to_alias_term(self.cx())) {
|
||||
(None, None) => {
|
||||
self.relate(param_env, lhs, variance, rhs)?;
|
||||
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
|
||||
|
||||
@@ -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 = alias.with_args(cx, identity_args);
|
||||
let ctor_term = rigid_ctor.to_term(cx);
|
||||
let obligations = self.delegate.eq_structurally_relating_aliases(
|
||||
param_env,
|
||||
|
||||
@@ -344,7 +344,7 @@ fn structurally_normalize_term(
|
||||
param_env: I::ParamEnv,
|
||||
term: I::Term,
|
||||
) -> Result<I::Term, NoSolution> {
|
||||
if let Some(_) = term.to_alias_term() {
|
||||
if let Some(_) = term.to_alias_term(self.cx()) {
|
||||
let normalized_term = self.next_term_infer_of_kind(term);
|
||||
let alias_relate_goal = Goal::new(
|
||||
self.cx(),
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1536,8 +1536,11 @@ pub(super) fn report_projection_error(
|
||||
let unnormalized_term = data.projection_term.to_term(self.tcx);
|
||||
// FIXME(-Znext-solver): For diagnostic purposes, it would be nice
|
||||
// to deeply normalize this type.
|
||||
let normalized_term =
|
||||
ocx.normalize(&obligation.cause, obligation.param_env, Unnormalized::new_wip(unnormalized_term));
|
||||
let normalized_term = ocx.normalize(
|
||||
&obligation.cause,
|
||||
obligation.param_env,
|
||||
Unnormalized::new_wip(unnormalized_term),
|
||||
);
|
||||
|
||||
// constrain inference variables a bit more to nested obligations from normalize so
|
||||
// we can have more helpful errors.
|
||||
@@ -1586,8 +1589,9 @@ 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)
|
||||
if let Some(lhs) = lhs.to_alias_term(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)
|
||||
{
|
||||
@@ -1595,8 +1599,9 @@ pub(super) fn report_projection_error(
|
||||
Some((lhs, self.resolve_vars_if_possible(expected_term), rhs)),
|
||||
better_type_err,
|
||||
)
|
||||
} else if let Some(rhs) = rhs.to_alias_term()
|
||||
&& let ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst = rhs.kind(self.tcx)
|
||||
} else if let Some(rhs) = rhs.to_alias_term(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 +1746,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()
|
||||
|
||||
@@ -1493,7 +1493,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()
|
||||
{
|
||||
@@ -1537,7 +1537,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()
|
||||
@@ -5304,7 +5304,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;
|
||||
@@ -5313,7 +5313,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();
|
||||
@@ -5327,7 +5327,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(),
|
||||
}),
|
||||
));
|
||||
@@ -5344,7 +5344,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
|
||||
@@ -6392,12 +6392,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 {
|
||||
|
||||
@@ -107,7 +107,7 @@ fn normalize_alias_term(
|
||||
let tcx = infcx.tcx;
|
||||
let recursion_limit = tcx.recursion_limit();
|
||||
if !recursion_limit.value_within_limit(self.depth) {
|
||||
let term = alias_term.to_alias_term().unwrap();
|
||||
let term = alias_term.to_alias_term(tcx).unwrap();
|
||||
|
||||
self.at.infcx.err_ctxt().report_overflow_error(
|
||||
OverflowCause::DeeplyNormalize(term),
|
||||
|
||||
@@ -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 { .. }
|
||||
) =>
|
||||
{
|
||||
|
||||
@@ -699,8 +699,8 @@ fn process_obligation(
|
||||
// `generic_const_exprs`
|
||||
.eq(
|
||||
DefineOpaqueTypes::Yes,
|
||||
ty::AliasTerm::from(a),
|
||||
ty::AliasTerm::from(b),
|
||||
ty::AliasTerm::from_unevaluated_const(tcx, a),
|
||||
ty::AliasTerm::from_unevaluated_const(tcx, b),
|
||||
)
|
||||
{
|
||||
return ProcessResult::Changed(mk_pending(
|
||||
|
||||
@@ -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)
|
||||
@@ -468,16 +469,20 @@ fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
|
||||
// feature gate causes a parse error.
|
||||
let ct = match tcx.def_kind(uv.def) {
|
||||
DefKind::AssocConst { .. } => match tcx.def_kind(tcx.parent(uv.def)) {
|
||||
DefKind::Trait => self.normalize_trait_projection(uv.into()).expect_const(),
|
||||
DefKind::Impl { of_trait: false } => {
|
||||
self.normalize_inherent_projection(uv.into()).expect_const()
|
||||
}
|
||||
DefKind::Trait => self
|
||||
.normalize_trait_projection(ty::AliasTerm::from_unevaluated_const(tcx, uv))
|
||||
.expect_const(),
|
||||
DefKind::Impl { of_trait: false } => self
|
||||
.normalize_inherent_projection(ty::AliasTerm::from_unevaluated_const(tcx, uv))
|
||||
.expect_const(),
|
||||
kind => unreachable!(
|
||||
"unexpected `DefKind` for const alias' resolution's parent def: {:?}",
|
||||
kind
|
||||
),
|
||||
},
|
||||
DefKind::Const { .. } => self.normalize_free_alias(uv.into()).expect_const(),
|
||||
DefKind::Const { .. } => self
|
||||
.normalize_free_alias(ty::AliasTerm::from_unevaluated_const(tcx, uv))
|
||||
.expect_const(),
|
||||
DefKind::AnonConst => {
|
||||
let ct = ct.super_fold_with(self);
|
||||
super::with_replaced_escaping_bound_vars(
|
||||
|
||||
@@ -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,24 +1327,20 @@ 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,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: ty.into(),
|
||||
};
|
||||
|
||||
@@ -1383,14 +1381,10 @@ 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,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: return_ty.into(),
|
||||
};
|
||||
|
||||
@@ -1429,14 +1423,10 @@ 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,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: yield_ty.into(),
|
||||
};
|
||||
|
||||
@@ -1475,7 +1465,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!();
|
||||
@@ -1486,11 +1476,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
|
||||
let item_ty = args.type_at(0);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
tcx,
|
||||
obligation.predicate.def_id,
|
||||
trait_ref.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
|
||||
term: item_ty.into(),
|
||||
};
|
||||
|
||||
@@ -1506,7 +1492,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 +1555,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 +1692,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 +1717,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 +1781,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 +1811,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 +1844,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}"),
|
||||
@@ -1888,11 +1882,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.args,
|
||||
),
|
||||
projection_term: obligation.predicate.with_args(selcx.tcx(), obligation.predicate.args),
|
||||
term: ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
|
||||
selcx.tcx(),
|
||||
goal_kind_ty.expect_ty().to_opt_closure_kind().unwrap(),
|
||||
@@ -1986,7 +1976,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 +2064,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 +2087,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(),
|
||||
};
|
||||
|
||||
@@ -286,7 +286,7 @@ fn try_fold_const(
|
||||
|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))?
|
||||
.try_fold_free_or_assoc(ty::AliasTerm::from_unevaluated_const(self.cx(), uv))?
|
||||
.expect_const(),
|
||||
};
|
||||
debug!(?constant, ?self.param_env);
|
||||
@@ -329,16 +329,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 +383,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)
|
||||
|
||||
@@ -891,8 +891,8 @@ fn evaluate_predicate_recursively<'o>(
|
||||
// `generic_const_exprs`
|
||||
.eq(
|
||||
DefineOpaqueTypes::Yes,
|
||||
ty::AliasTerm::from(a),
|
||||
ty::AliasTerm::from(b),
|
||||
ty::AliasTerm::from_unevaluated_const(tcx, a),
|
||||
ty::AliasTerm::from_unevaluated_const(tcx, b),
|
||||
)
|
||||
{
|
||||
return self.evaluate_predicates_recursively(
|
||||
@@ -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.
|
||||
|
||||
@@ -41,7 +41,7 @@ fn structurally_normalize_term<E: 'tcx>(
|
||||
|
||||
if self.infcx.next_trait_solver() {
|
||||
let term = term.skip_normalization();
|
||||
if let None = term.to_alias_term() {
|
||||
if let None = term.to_alias_term(self.infcx.tcx) {
|
||||
return Ok(term);
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
@@ -1077,7 +1077,9 @@ fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
|
||||
if matches!(tcx.def_kind(uv.def), DefKind::AssocConst { .. })
|
||||
&& tcx.def_kind(tcx.parent(uv.def)) == (DefKind::Impl { of_trait: false })
|
||||
{
|
||||
self.add_wf_preds_for_inherent_projection(uv.into());
|
||||
self.add_wf_preds_for_inherent_projection(
|
||||
ty::AliasTerm::from_unevaluated_const(tcx, uv),
|
||||
);
|
||||
return; // Subtree is handled by above function
|
||||
} else {
|
||||
let obligations = self.nominal_obligations(uv.def, uv.args);
|
||||
|
||||
@@ -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 })
|
||||
},
|
||||
|
||||
@@ -432,14 +432,16 @@ fn is_error(self) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_alias_term(self) -> Option<ty::AliasTerm<I>> {
|
||||
fn to_alias_term(self, interner: I) -> Option<ty::AliasTerm<I>> {
|
||||
match self.kind() {
|
||||
ty::TermKind::Ty(ty) => match ty.kind() {
|
||||
ty::Alias(alias_ty) => Some(alias_ty.into()),
|
||||
_ => None,
|
||||
},
|
||||
ty::TermKind::Const(ct) => match ct.kind() {
|
||||
ty::ConstKind::Unevaluated(uv) => Some(uv.into()),
|
||||
ty::ConstKind::Unevaluated(uv) => {
|
||||
Some(ty::AliasTerm::from_unevaluated_const(interner, uv))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -197,11 +197,9 @@ 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
|
||||
fn opt_alias_variances(
|
||||
self,
|
||||
kind: impl Into<ty::AliasTermKind>,
|
||||
def_id: Self::DefId,
|
||||
kind: impl Into<ty::AliasTermKind<Self>>,
|
||||
) -> Option<Self::VariancesOf>;
|
||||
|
||||
fn type_of(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Ty>;
|
||||
@@ -215,7 +213,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,
|
||||
|
||||
@@ -226,7 +226,7 @@ pub fn compute_alias_components_recursive<I: Interner>(
|
||||
alias_ty: ty::AliasTy<I>,
|
||||
out: &mut SmallVec<[Component<I>; 4]>,
|
||||
) {
|
||||
let opt_variances = cx.opt_alias_variances(alias_ty.kind, alias_ty.kind.def_id());
|
||||
let opt_variances = cx.opt_alias_variances(alias_ty.kind);
|
||||
|
||||
let mut visitor = OutlivesCollector { cx, out, visited: Default::default() };
|
||||
|
||||
|
||||
@@ -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: (),
|
||||
@@ -562,71 +560,104 @@ pub fn item_def_id(&self) -> I::DefId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
|
||||
pub enum AliasTermKind {
|
||||
#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)]
|
||||
#[derive(Lift_Generic)]
|
||||
#[cfg_attr(
|
||||
feature = "nightly",
|
||||
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
|
||||
)]
|
||||
pub enum AliasTermKind<I: Interner> {
|
||||
/// A projection `<Type as Trait>::AssocType`.
|
||||
///
|
||||
/// Can get normalized away if monomorphic enough.
|
||||
ProjectionTy,
|
||||
///
|
||||
/// The `def_id` is the `DefId` of the `TraitItem` for the associated type.
|
||||
///
|
||||
/// Note that the `def_id` is not the `DefId` of the `TraitRef` containing this
|
||||
/// associated type, which is in `interner.associated_item(def_id).container`,
|
||||
/// aka. `interner.parent(def_id)`.
|
||||
ProjectionTy { def_id: I::DefId },
|
||||
|
||||
/// An associated type in an inherent `impl`
|
||||
InherentTy,
|
||||
///
|
||||
/// The `def_id` is the `DefId` of the `ImplItem` for the associated type.
|
||||
InherentTy { def_id: I::DefId },
|
||||
|
||||
/// An opaque type (usually from `impl Trait` in type aliases or function return types)
|
||||
///
|
||||
/// Can only be normalized away in PostAnalysis mode or its defining scope.
|
||||
OpaqueTy,
|
||||
/// A free type alias that actually checks its trait bounds.
|
||||
/// `def_id` is the `DefId` of the `OpaqueType` item.
|
||||
///
|
||||
/// Can only be normalized away in `PostAnalysis` mode or its defining scope.
|
||||
///
|
||||
/// During codegen, `interner.type_of(def_id)` can be used to get the type of the
|
||||
/// underlying type if the type is an opaque.
|
||||
OpaqueTy { def_id: I::DefId },
|
||||
|
||||
/// A type alias that actually checks its trait bounds.
|
||||
///
|
||||
/// Currently only used if the type alias references opaque types.
|
||||
/// Can always be normalized away.
|
||||
FreeTy,
|
||||
FreeTy { def_id: I::DefId },
|
||||
|
||||
/// An unevaluated anonymous constants.
|
||||
UnevaluatedConst,
|
||||
UnevaluatedConst { def_id: I::DefId },
|
||||
/// An unevaluated const coming from an associated const.
|
||||
ProjectionConst,
|
||||
ProjectionConst { def_id: I::DefId },
|
||||
/// A top level const item not part of a trait or impl.
|
||||
FreeConst,
|
||||
FreeConst { def_id: I::DefId },
|
||||
/// An associated const in an inherent `impl`
|
||||
InherentConst,
|
||||
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 },
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -655,17 +686,9 @@ pub struct AliasTerm<I: Interner> {
|
||||
/// while for TAIT it is used for the generic parameters of the alias.
|
||||
pub args: I::GenericArgs,
|
||||
|
||||
/// The `DefId` of the `TraitItem` or `ImplItem` for the associated type `N` depending on whether
|
||||
/// this is a projection or an inherent projection or the `DefId` of the `OpaqueType` item if
|
||||
/// this is an opaque.
|
||||
///
|
||||
/// During codegen, `interner.type_of(def_id)` can be used to get the type of the
|
||||
/// underlying type if the type is an opaque.
|
||||
///
|
||||
/// Note that if this is an associated type, this is not the `DefId` of the
|
||||
/// `TraitRef` containing this associated type, which is in `interner.associated_item(def_id).container`,
|
||||
/// aka. `interner.parent(def_id)`.
|
||||
pub def_id: I::DefId,
|
||||
#[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`].
|
||||
#[derive_where(skip(Debug))]
|
||||
@@ -675,62 +698,86 @@ 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 from_unevaluated_const(interner: I, ct: ty::UnevaluatedConst<I>) -> Self {
|
||||
let kind = interner.alias_term_kind_from_def_id(ct.def.into());
|
||||
AliasTerm::new_from_args(interner, kind, ct.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))
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn with_args(self, interner: I, args: I::GenericArgs) -> Self {
|
||||
Self::new_from_args(interner, self.kind, args)
|
||||
}
|
||||
}
|
||||
|
||||
/// The following methods work only with (trait) associated term projections.
|
||||
@@ -742,7 +789,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)),
|
||||
)
|
||||
}
|
||||
@@ -751,11 +798,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.
|
||||
@@ -763,7 +810,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.
|
||||
@@ -804,7 +851,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)))
|
||||
}
|
||||
@@ -812,13 +859,11 @@ 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: () }
|
||||
}
|
||||
}
|
||||
|
||||
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: ty.args,
|
||||
kind: AliasTermKind::from(ty.kind),
|
||||
_use_alias_term_new_instead: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -864,7 +909,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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,7 +930,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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -924,7 +969,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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ fn relate<R: TypeRelation<I>>(
|
||||
)))
|
||||
} else {
|
||||
let cx = relation.cx();
|
||||
let args = if let Some(variances) = cx.opt_alias_variances(a.kind, a.kind.def_id()) {
|
||||
let args = if let Some(variances) = cx.opt_alias_variances(a.kind) {
|
||||
relate_args_with_variances(relation, variances, a.args, b.args)?
|
||||
} else {
|
||||
relate_args_invariantly(relation, a.args, b.args)?
|
||||
@@ -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(a.with_args(relation.cx(), args))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ fn projection_to_path_segment<'tcx>(
|
||||
proj: ty::Binder<'tcx, ty::AliasTerm<'tcx>>,
|
||||
cx: &mut DocContext<'tcx>,
|
||||
) -> PathSegment {
|
||||
let def_id = proj.skip_binder().def_id;
|
||||
let def_id = proj.skip_binder().def_id();
|
||||
let generics = cx.tcx.generics_of(def_id);
|
||||
PathSegment {
|
||||
name: cx.tcx.item_name(def_id),
|
||||
|
||||
@@ -696,7 +696,7 @@ fn sig_from_bounds<'tcx>(
|
||||
inputs = Some(i);
|
||||
},
|
||||
ty::ClauseKind::Projection(p)
|
||||
if Some(p.projection_term.def_id) == lang_items.fn_once_output()
|
||||
if Some(p.projection_term.def_id()) == lang_items.fn_once_output()
|
||||
&& p.projection_term.self_ty() == ty =>
|
||||
{
|
||||
if output.is_some() {
|
||||
@@ -737,7 +737,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
|
||||
}
|
||||
inputs = Some(i);
|
||||
},
|
||||
ty::ClauseKind::Projection(p) if Some(p.projection_term.def_id) == lang_items.fn_once_output() => {
|
||||
ty::ClauseKind::Projection(p) if Some(p.projection_term.def_id()) == lang_items.fn_once_output() => {
|
||||
if output.is_some() {
|
||||
// Multiple different fn trait impls. Is this even allowed?
|
||||
return None;
|
||||
|
||||
@@ -33,7 +33,7 @@ error: rustc_dump_item_bounds
|
||||
LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: Binder { value: ProjectionPredicate(AliasTerm { args: [Alias(AliasTy { args: [Self/#0, T/#1, P/#2], kind: Projection { def_id: DefId(..) }, .. })], def_id: DefId(..), .. }, Term::Ty(())), bound_vars: [] }
|
||||
= note: Binder { value: ProjectionPredicate(AliasTerm { args: [Alias(AliasTy { args: [Self/#0, T/#1, P/#2], kind: Projection { def_id: DefId(..) }, .. })], kind: ProjectionTy { def_id: DefId(..) }, .. }, Term::Ty(())), bound_vars: [] }
|
||||
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] }
|
||||
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], kind: ProjectionTy { def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }, .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], kind: ProjectionTy { def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }, .. }
|
||||
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
|
||||
--> $DIR/associated-type.rs:32:1
|
||||
|
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], kind: ProjectionTy { def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }, .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], kind: ProjectionTy { def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }, .. }
|
||||
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
|
||||
--> $DIR/associated-type.rs:32:1
|
||||
|
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [?1t, '^0.Named(DefId(0:15 ~ structually_relate_aliases[de75]::{impl#1}::'a))], def_id: DefId(0:5 ~ structually_relate_aliases[de75]::ToUnit::Unit), .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [?1t, '^0.Named(DefId(0:15 ~ structually_relate_aliases[de75]::{impl#1}::'a))], kind: ProjectionTy { def_id: DefId(0:5 ~ structually_relate_aliases[de75]::ToUnit::Unit) }, .. }
|
||||
error[E0277]: the trait bound `for<'a> T: ToUnit<'a>` is not satisfied
|
||||
--> $DIR/structually-relate-aliases.rs:13:36
|
||||
|
|
||||
|
||||
@@ -16,7 +16,7 @@ help: this trait has no implementations, consider adding one
|
||||
LL | trait ToUnit<'a> {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a)), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc), .. }
|
||||
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a)), ?1t], kind: FreeTy { def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) }, .. }
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0425.
|
||||
|
||||
Reference in New Issue
Block a user