Skip to content

Remove weak alias terminology #140249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
| ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

ty::Alias(ty::Weak, _) => bug!("type_name: unexpected weak projection"),
ty::Alias(ty::Free, _) => bug!("type_name: unexpected free alias"),
ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"),
ty::CoroutineWitness(..) => bug!("type_name: unexpected `CoroutineWitness`"),
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ fn check_variances_for_type_defn<'tcx>(
ItemKind::TyAlias(..) => {
assert!(
tcx.type_alias_is_lazy(item.owner_id),
"should not be computing variance of non-weak type alias"
"should not be computing variance of non-free type alias"
);
}
kind => span_bug!(item.span, "cannot compute the variances of {kind:?}"),
Expand Down Expand Up @@ -2223,7 +2223,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsProbablyCyclical<'tcx> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<(), ()> {
let def_id = match ty.kind() {
ty::Adt(adt_def, _) => Some(adt_def.did()),
ty::Alias(ty::Weak, alias_ty) => Some(alias_ty.def_id),
ty::Alias(ty::Free, alias_ty) => Some(alias_ty.def_id),
_ => None,
};
if let Some(def_id) = def_id {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<'tcx> InherentCollect<'tcx> {
let id = id.owner_id.def_id;
let item_span = self.tcx.def_span(id);
let self_ty = self.tcx.type_of(id).instantiate_identity();
let mut self_ty = self.tcx.peel_off_weak_alias_tys(self_ty);
let mut self_ty = self.tcx.peel_off_free_alias_tys(self_ty);
// We allow impls on pattern types exactly when we allow impls on the base type.
// FIXME(pattern_types): Figure out the exact coherence rules we want here.
while let ty::Pat(base, _) = *self_ty.kind() {
Expand Down Expand Up @@ -188,7 +188,7 @@ impl<'tcx> InherentCollect<'tcx> {
| ty::CoroutineClosure(..)
| ty::Coroutine(..)
| ty::CoroutineWitness(..)
| ty::Alias(ty::Weak, _)
| ty::Alias(ty::Free, _)
| ty::Bound(..)
| ty::Placeholder(_)
| ty::Infer(_) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub(crate) fn orphan_check_impl(
ty::Projection => "associated type",
// type Foo = (impl Sized, bool)
// impl AutoTrait for Foo {}
ty::Weak => "type alias",
ty::Free => "type alias",
// type Opaque = impl Trait;
// impl AutoTrait for Opaque {}
ty::Opaque => "opaque type",
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/constrained_generic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) fn parameters_for<'tcx>(
include_nonconstraining: bool,
) -> Vec<Parameter> {
let mut collector = ParameterCollector { parameters: vec![], include_nonconstraining };
let value = if !include_nonconstraining { tcx.expand_weak_alias_tys(value) } else { value };
let value = if !include_nonconstraining { tcx.expand_free_alias_tys(value) } else { value };
value.visit_with(&mut collector);
collector.parameters
}
Expand All @@ -68,9 +68,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
{
return;
}
// All weak alias types should've been expanded beforehand.
ty::Alias(ty::Weak, _) if !self.include_nonconstraining => {
bug!("unexpected weak alias type")
// All free alias types should've been expanded beforehand.
ty::Alias(ty::Free, _) if !self.include_nonconstraining => {
bug!("unexpected free alias type")
}
ty::Param(param) => self.parameters.push(Parameter::from(param)),
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
// then actually instantiate the where bounds of.
let alias_ty = ty::AliasTy::new_from_args(tcx, did, args);
Ty::new_alias(tcx, ty::Weak, alias_ty)
Ty::new_alias(tcx, ty::Free, alias_ty)
} else {
tcx.at(span).type_of(did).instantiate(tcx, args)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ fn insert_required_predicates_to_be_wf<'tcx>(
);
}

ty::Alias(ty::Weak, alias) => {
ty::Alias(ty::Free, alias) => {
// This corresponds to a type like `Type<'a, T>`.
// We check inferred and explicit predicates.
debug!("Weak");
debug!("Free");
check_inferred_predicates(
tcx,
alias.def_id,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
let current_item = &CurrentItem { inferred_start };
let ty = tcx.type_of(def_id).instantiate_identity();

// The type as returned by `type_of` is the underlying type and generally not a weak projection.
// The type as returned by `type_of` is the underlying type and generally not a free alias.
// Therefore we need to check the `DefKind` first.
if let DefKind::TyAlias = tcx.def_kind(def_id)
&& tcx.type_alias_is_lazy(def_id)
Expand Down Expand Up @@ -282,7 +282,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_invariant_args(current, data.args, variance);
}

ty::Alias(ty::Weak, ref data) => {
ty::Alias(ty::Free, ref data) => {
self.add_constraints_from_args(current, data.def_id, data.args, variance);
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
match ty.kind() {
ty::Adt(adt_def, _) => Some(*adt_def),
// FIXME(#104767): Should we handle bound regions here?
ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _)
ty::Alias(ty::Projection | ty::Inherent | ty::Free, _)
if !ty.has_escaping_bound_vars() =>
{
if self.next_trait_solver() {
Expand All @@ -357,7 +357,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
// WF obligations that are registered elsewhere, but they have a
// better cause code assigned to them in `add_required_obligations_for_hir`.
// This means that they should shadow obligations with worse spans.
if let ty::Alias(ty::Projection | ty::Weak, ty::AliasTy { args, def_id, .. }) =
if let ty::Alias(ty::Projection | ty::Free, ty::AliasTy { args, def_id, .. }) =
ty.kind()
{
self.add_required_obligations_for_hir(span, *def_id, args, hir_id);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'tcx> InferCtxt<'tcx> {
}]);
}
// The old solver only accepts projection predicates for associated types.
ty::Alias(ty::Inherent | ty::Weak | ty::Opaque, _) => {
ty::Alias(ty::Inherent | ty::Free | ty::Opaque, _) => {
return Err(TypeError::CyclicTy(source_ty));
}
_ => bug!("generalized `{source_ty:?} to infer, not an alias"),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),

ty::Param(..)
| ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ..)
| ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..)
| ty::Infer(..)
| ty::Bound(..)
| ty::Error(_)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ rustc_queries! {

/// Returns whether the type alias given by `DefId` is lazy.
///
/// I.e., if the type alias expands / ought to expand to a [weak] [alias type]
/// I.e., if the type alias expands / ought to expand to a [free] [alias type]
/// instead of the underyling aliased type.
///
/// Relevant for features `lazy_type_alias` and `type_alias_impl_trait`.
Expand All @@ -298,7 +298,7 @@ rustc_queries! {
///
/// This query *may* panic if the given definition is not a type alias.
///
/// [weak]: rustc_middle::ty::Weak
/// [free]: rustc_middle::ty::Free
/// [alias type]: rustc_middle::ty::AliasTy
query type_alias_is_lazy(key: DefId) -> bool {
desc { |tcx|
Expand Down Expand Up @@ -2280,7 +2280,7 @@ rustc_queries! {
/// Do not call this query directly: Invoke `normalize` instead.
///
/// </div>
query normalize_canonicalized_weak_ty(
query normalize_canonicalized_free_alias(
goal: CanonicalAliasGoal<'tcx>
) -> Result<
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ pub enum ObligationCauseCode<'tcx> {
/// Requirement for a `const N: Ty` to implement `Ty: ConstParamTy`
ConstParam(Ty<'tcx>),

/// Obligations emitted during the normalization of a weak type alias.
/// Obligations emitted during the normalization of a free type alias.
TypeAlias(ObligationCauseCodeHandle<'tcx>, Span, DefId),
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub struct MethodAutoderefBadTy<'tcx> {
pub ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
}

/// Result of the `normalize_canonicalized_{{,inherent_}projection,weak}_ty` queries.
/// Result of the `normalize_canonicalized_{{,inherent_}projection,free}_ty` queries.
#[derive(Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
pub struct NormalizationResult<'tcx> {
/// Result of the normalization.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
}
}
DefKind::OpaqueTy => ty::Opaque,
DefKind::TyAlias => ty::Weak,
DefKind::TyAlias => ty::Free,
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
}
}
Expand All @@ -242,7 +242,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
}
}
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
DefKind::TyAlias => ty::AliasTermKind::WeakTy,
DefKind::TyAlias => ty::AliasTermKind::FreeTy,
DefKind::AssocConst => ty::AliasTermKind::ProjectionConst,
DefKind::AnonConst | DefKind::Const | DefKind::Ctor(_, CtorKind::Const) => {
ty::AliasTermKind::UnevaluatedConst
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'tcx> Ty<'tcx> {
ty::Placeholder(..) => "higher-ranked type".into(),
ty::Bound(..) => "bound type variable".into(),
ty::Alias(ty::Projection | ty::Inherent, _) => "associated type".into(),
ty::Alias(ty::Weak, _) => "type alias".into(),
ty::Alias(ty::Free, _) => "type alias".into(),
ty::Param(_) => "type parameter".into(),
ty::Alias(ty::Opaque, ..) => "opaque type".into(),
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/inhabitedness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'tcx> Ty<'tcx> {
InhabitedPredicate::True
}
Never => InhabitedPredicate::False,
Param(_) | Alias(ty::Projection | ty::Weak, _) => InhabitedPredicate::GenericType(self),
Param(_) | Alias(ty::Projection | ty::Free, _) => InhabitedPredicate::GenericType(self),
Alias(ty::Opaque, alias_ty) => {
match alias_ty.def_id.as_local() {
// Foreign opaque is considered inhabited.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::Foreign(def_id) => {
p!(print_def_path(def_id, &[]));
}
ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ref data) => {
ty::Alias(ty::Projection | ty::Inherent | ty::Free, ref data) => {
p!(print(data))
}
ty::Placeholder(placeholder) => match placeholder.bound.kind {
Expand Down Expand Up @@ -3205,7 +3205,7 @@ define_print! {
p!(print_def_path(self.def_id, self.args));
}
}
| ty::AliasTermKind::WeakTy
| ty::AliasTermKind::FreeTy
| ty::AliasTermKind::OpaqueTy
| ty::AliasTermKind::UnevaluatedConst
| ty::AliasTermKind::ProjectionConst => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ impl<'tcx> Ty<'tcx> {
(kind, tcx.def_kind(alias_ty.def_id)),
(ty::Opaque, DefKind::OpaqueTy)
| (ty::Projection | ty::Inherent, DefKind::AssocTy)
| (ty::Weak, DefKind::TyAlias)
| (ty::Free, DefKind::TyAlias)
);
Ty::new(tcx, Alias(kind, alias_ty))
}
Expand Down
42 changes: 21 additions & 21 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ impl<'tcx> TyCtxt<'tcx> {
|| self.extern_crate(key).is_some_and(|e| e.is_direct())
}

/// Expand any [weak alias types][weak] contained within the given `value`.
/// Expand any [free alias types][free] contained within the given `value`.
///
/// This should be used over other normalization routines in situations where
/// it's important not to normalize other alias types and where the predicates
Expand All @@ -926,19 +926,19 @@ impl<'tcx> TyCtxt<'tcx> {
/// <div class="warning">
/// This delays a bug on overflow! Therefore you need to be certain that the
/// contained types get fully normalized at a later stage. Note that even on
/// overflow all well-behaved weak alias types get expanded correctly, so the
/// overflow all well-behaved free alias types get expanded correctly, so the
/// result is still useful.
/// </div>
///
/// [weak]: ty::Weak
pub fn expand_weak_alias_tys<T: TypeFoldable<TyCtxt<'tcx>>>(self, value: T) -> T {
value.fold_with(&mut WeakAliasTypeExpander { tcx: self, depth: 0 })
/// [free]: ty::Free
pub fn expand_free_alias_tys<T: TypeFoldable<TyCtxt<'tcx>>>(self, value: T) -> T {
value.fold_with(&mut FreeAliasTypeExpander { tcx: self, depth: 0 })
}

/// Peel off all [weak alias types] in this type until there are none left.
/// Peel off all [free alias types] in this type until there are none left.
///
/// This only expands weak alias types in “head” / outermost positions. It can
/// be used over [expand_weak_alias_tys] as an optimization in situations where
/// This only expands free alias types in “head” / outermost positions. It can
/// be used over [expand_free_alias_tys] as an optimization in situations where
/// one only really cares about the *kind* of the final aliased type but not
/// the types the other constituent types alias.
///
Expand All @@ -947,17 +947,17 @@ impl<'tcx> TyCtxt<'tcx> {
/// type gets fully normalized at a later stage.
/// </div>
///
/// [weak]: ty::Weak
/// [expand_weak_alias_tys]: Self::expand_weak_alias_tys
pub fn peel_off_weak_alias_tys(self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
let ty::Alias(ty::Weak, _) = ty.kind() else { return ty };
/// [free]: ty::Free
/// [expand_free_alias_tys]: Self::expand_free_alias_tys
pub fn peel_off_free_alias_tys(self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
let ty::Alias(ty::Free, _) = ty.kind() else { return ty };

let limit = self.recursion_limit();
let mut depth = 0;

while let ty::Alias(ty::Weak, alias) = ty.kind() {
while let ty::Alias(ty::Free, alias) = ty.kind() {
if !limit.value_within_limit(depth) {
let guar = self.dcx().delayed_bug("overflow expanding weak alias type");
let guar = self.dcx().delayed_bug("overflow expanding free alias type");
return Ty::new_error(self, guar);
}

Expand Down Expand Up @@ -985,7 +985,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
ty::AliasTermKind::OpaqueTy => Some(self.variances_of(def_id)),
ty::AliasTermKind::InherentTy
| ty::AliasTermKind::WeakTy
| ty::AliasTermKind::FreeTy
| ty::AliasTermKind::UnevaluatedConst
| ty::AliasTermKind::ProjectionConst => None,
}
Expand Down Expand Up @@ -1078,25 +1078,25 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
}
}

struct WeakAliasTypeExpander<'tcx> {
struct FreeAliasTypeExpander<'tcx> {
tcx: TyCtxt<'tcx>,
depth: usize,
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for WeakAliasTypeExpander<'tcx> {
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_WEAK) {
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_FREE_ALIAS) {
return ty;
}
let ty::Alias(ty::Weak, alias) = ty.kind() else {
let ty::Alias(ty::Free, alias) = ty.kind() else {
return ty.super_fold_with(self);
};
if !self.tcx.recursion_limit().value_within_limit(self.depth) {
let guar = self.tcx.dcx().delayed_bug("overflow expanding weak alias type");
let guar = self.tcx.dcx().delayed_bug("overflow expanding free alias type");
return Ty::new_error(self.tcx, guar);
}

Expand All @@ -1107,7 +1107,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for WeakAliasTypeExpander<'tcx> {
}

fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
if !ct.has_type_flags(ty::TypeFlags::HAS_TY_WEAK) {
if !ct.has_type_flags(ty::TypeFlags::HAS_TY_FREE_ALIAS) {
return ct;
}
ct.super_fold_with(self)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'tcx> TyCtxt<'tcx> {
{
let mut collector = LateBoundRegionsCollector::new(just_constrained);
let value = value.skip_binder();
let value = if just_constrained { self.expand_weak_alias_tys(value) } else { value };
let value = if just_constrained { self.expand_free_alias_tys(value) } else { value };
value.visit_with(&mut collector);
collector.regions
}
Expand Down Expand Up @@ -182,8 +182,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector {
ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) => {
return;
}
// All weak alias types should've been expanded beforehand.
ty::Alias(ty::Weak, _) => bug!("unexpected weak alias type"),
// All free alias types should've been expanded beforehand.
ty::Alias(ty::Free, _) => bug!("unexpected free alias type"),
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ where
}

ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty),
ty::Alias(ty::Inherent | ty::Weak, _) => {
ty::Alias(ty::Inherent | ty::Free, _) => {
self.cx().delay_bug(format!("could not normalize {self_ty:?}, it is not WF"));
return;
}
Expand Down
Loading
Loading