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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectMemberConstraintsVisitor<'_, '_,
| 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
}

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)| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2720,7 +2720,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,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
.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);
ty::ClauseKind::ConstArgHasType(ct, assoc_const_ty)
})
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
);
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)
})
};

Expand All @@ -543,7 +543,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
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)
tcx.type_of(alias.def_id()).instantiate(tcx, alias.args)
});
let ty = check_assoc_const_binding_type(
self,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&item_segment,
trait_ref.args,
);
ty::AliasTerm::new_from_args(
ty::AliasTerm::new_from_def_id(
tcx,
assoc_item.def_id,
alias_args,
Expand All @@ -1367,7 +1367,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// 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).instantiate(tcx, alias.args)
tcx.type_of(alias.def_id()).instantiate(tcx, alias.args)
});
let ty = bounds::check_assoc_const_binding_type(
self,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,11 +1082,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 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,
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/for_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ where
} 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) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ where
&& (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;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'tcx> InferCtxt<'tcx> {
) -> 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 {
Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ impl<'tcx> InferCtxt<'tcx> {

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
Expand All @@ -199,14 +200,14 @@ impl<'tcx> InferCtxt<'tcx> {
}]);
}
// 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()));
}
}
Expand Down Expand Up @@ -755,7 +756,8 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
// 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;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {

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,
Expand All @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// 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)
{
let assoc_pred = assoc_pred.fold_with(proj_replacer);
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {

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>> {
Expand Down Expand Up @@ -202,29 +201,27 @@ impl<'tcx> Interner for TyCtxt<'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:?}"),
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ pub use self::list::{List, ListWithCachedTypeInfo};
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,
Expand Down Expand Up @@ -603,14 +603,14 @@ impl<'tcx> Term<'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,
},
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::ty::{

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>>;
Expand Down Expand Up @@ -652,7 +653,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
}
24 changes: 12 additions & 12 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
&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(
Expand Down Expand Up @@ -3152,22 +3152,22 @@ define_print! {

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)?;
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,24 +935,23 @@ impl<'tcx> TyCtxt<'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,
}
}
}
Expand Down
Loading
Loading