authorbors <bors@rust-lang.org> 2026-06-27 11:04:54 UTC
committerbors <bors@rust-lang.org> 2026-06-27 11:04:54 UTC
logcb41b6d3daa0c1ad088a8802a6d8700c61290865
tree658da1cea11084c57bc938a766d014c1d2592eaa
parent267c4057bad01b0cf9733081d170c1358b4b3674
parentc502825eefefcf21c152991de428948f6be609da

Auto merge of #158115 - Shourya742:2026-06-19-rename-unevaluatedConst-to-aliasconst, r=BoxyUwU,khyperia

Rename UnevaluatedConst to AliasConst refer: https://github.com/rust-lang/project-const-generics/issues/115 r? @khyperia I only renamed the type system version to `AliasConst`/`AliasConstKind`. I did not rename MIR’s `UnevaluatedConst`, it currently holds direct def_id instead of kind variant we have in type-system. I also left `rustc_public`’s `UnevaluatedConst` unchanged.

75 files changed, 465 insertions(+), 517 deletions(-)

compiler/rustc_borrowck/src/type_check/mod.rs+9-7
......@@ -1759,13 +1759,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
17591759 let tcx = self.tcx();
17601760 let maybe_uneval = match constant.const_ {
17611761 Const::Ty(_, ct) => match ct.kind() {
1762 ty::ConstKind::Unevaluated(_, uv) => match uv.kind {
1763 ty::UnevaluatedConstKind::Projection { def_id }
1764 | ty::UnevaluatedConstKind::Inherent { def_id }
1765 | ty::UnevaluatedConstKind::Free { def_id }
1766 | ty::UnevaluatedConstKind::Anon { def_id } => {
1767 Some(UnevaluatedConst { def: def_id, args: uv.args, promoted: None })
1768 }
1762 ty::ConstKind::Alias(_, alias_const) => match alias_const.kind {
1763 ty::AliasConstKind::Projection { def_id }
1764 | ty::AliasConstKind::Inherent { def_id }
1765 | ty::AliasConstKind::Free { def_id }
1766 | ty::AliasConstKind::Anon { def_id } => Some(UnevaluatedConst {
1767 def: def_id,
1768 args: alias_const.args,
1769 promoted: None,
1770 }),
17691771 },
17701772 _ => None,
17711773 },
compiler/rustc_const_eval/src/check_consts/qualifs.rs+3-3
......@@ -344,13 +344,13 @@ where
344344 let uneval = match constant.const_ {
345345 Const::Ty(_, ct) => match ct.kind() {
346346 ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
347 // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`).
348 ty::ConstKind::Unevaluated(_, _) => None,
347 // Alias consts in MIR bodies don't have associated MIR (e.g. `type const`).
348 ty::ConstKind::Alias(_, _) => None,
349349 // FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
350350 // strict, and if instead we should be doing some kind of value-based analysis.
351351 ty::ConstKind::Value(_) => None,
352352 _ => bug!(
353 "expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}",
353 "expected ConstKind::Param, ConstKind::Value, ConstKind::Alias, or ConstKind::Error here, found {:?}",
354354 ct
355355 ),
356356 },
compiler/rustc_hir_analysis/src/check/check.rs+2-2
......@@ -778,8 +778,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
778778 if has_default {
779779 // need to store default and type of default
780780 let ct = tcx.const_param_default(param.def_id).skip_binder();
781 if let ty::ConstKind::Unevaluated(_, uv) = ct.kind()
782 && let Some(def_id) = uv.kind.opt_def_id()
781 if let ty::ConstKind::Alias(_, alias_const) = ct.kind()
782 && let Some(def_id) = alias_const.kind.opt_def_id()
783783 {
784784 tcx.ensure_ok().type_of(def_id);
785785 }
compiler/rustc_hir_analysis/src/check/wfcheck.rs+4-2
......@@ -1488,7 +1488,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
14881488 // be sure if it will error or not as user might always specify the other.
14891489 // FIXME(generic_const_exprs): This is incorrect when dealing with unused const params.
14901490 // E.g: `struct Foo<const N: usize, const M: usize = { 1 - 2 }>;`. Here, we should
1491 // eagerly error but we don't as we have `ConstKind::Unevaluated(.., [N, M])`.
1491 // eagerly error but we don't as we have `ConstKind::Alias(.., [N, M])`.
14921492 if !default.has_param() {
14931493 wfcx.register_wf_obligation(
14941494 tcx.def_span(param.def_id),
......@@ -1509,7 +1509,9 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
15091509 | ty::ConstKind::Bound(_, _) => unreachable!(),
15101510 ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => continue,
15111511 ty::ConstKind::Value(cv) => cv.ty,
1512 ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(),
1512 ty::ConstKind::Alias(_, alias_const) => {
1513 alias_const.type_of(infcx.tcx).skip_norm_wip()
1514 }
15131515 ty::ConstKind::Param(param_ct) => {
15141516 param_ct.find_const_ty_from_env(wfcx.param_env)
15151517 }
compiler/rustc_hir_analysis/src/collect/generics_of.rs+2-2
......@@ -124,11 +124,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
124124 // ^ parent_def_id
125125 //
126126 // then we only want to return generics for params to the left of `N`. If we don't do that we
127 // end up with that const looking like: `ty::ConstKind::Unevaluated(def_id, args: [N#0])`.
127 // end up with that const looking like: `ty::ConstKind::Alias(def_id, args: [N#0])`.
128128 //
129129 // This causes ICEs (#86580) when building the args for Foo in `fn foo() -> Foo { .. }` as
130130 // we instantiate the defaults with the partially built args when we build the args. Instantiating
131 // the `N#0` on the unevaluated const indexes into the empty args we're in the process of building.
131 // the `N#0` on the alias const indexes into the empty args we're in the process of building.
132132 //
133133 // We fix this by having this function return the parent's generics ourselves and truncating the
134134 // generics to only include non-forward declared params (with the exception of the `Self` ty)
compiler/rustc_hir_analysis/src/collect/predicates_of.rs+6-6
......@@ -415,8 +415,8 @@ fn const_evaluatable_predicates_of<'tcx>(
415415 preds: FxIndexSet<(ty::Clause<'tcx>, Span)>,
416416 }
417417
418 fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::UnevaluatedConstKind<'_>) -> bool {
419 let ty::UnevaluatedConstKind::Anon { def_id } = kind else { return false };
418 fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::AliasConstKind<'_>) -> bool {
419 let ty::AliasConstKind::Anon { def_id } = kind else { return false };
420420 let Some(local) = def_id.as_local() else { return false };
421421
422422 let hir_id = tcx.local_def_id_to_hir_id(local);
......@@ -433,8 +433,8 @@ fn const_evaluatable_predicates_of<'tcx>(
433433
434434 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> {
435435 fn visit_const(&mut self, c: ty::Const<'tcx>) {
436 if let ty::ConstKind::Unevaluated(_, uv) = c.kind() {
437 if is_const_param_default(self.tcx, uv.kind) {
436 if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
437 if is_const_param_default(self.tcx, alias_const.kind) {
438438 // Do not look into const param defaults,
439439 // these get checked when they are actually instantiated.
440440 //
......@@ -446,11 +446,11 @@ fn const_evaluatable_predicates_of<'tcx>(
446446 }
447447
448448 // Skip type consts as mGCA doesn't support evaluatable clauses.
449 if uv.kind.is_type_const(self.tcx) {
449 if alias_const.kind.is_type_const(self.tcx) {
450450 return;
451451 }
452452
453 let span = uv.kind.def_span(self.tcx);
453 let span = alias_const.kind.def_span(self.tcx);
454454 self.preds.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span));
455455 }
456456 }
compiler/rustc_hir_analysis/src/constrained_generic_params.rs+1-1
......@@ -93,7 +93,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
9393
9494 fn visit_const(&mut self, c: ty::Const<'tcx>) {
9595 match c.kind() {
96 ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => {
96 ty::ConstKind::Alias(..) if !self.include_nonconstraining => {
9797 // Constant expressions are not injective in general.
9898 return;
9999 }
compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs+10-14
......@@ -1402,7 +1402,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
14021402 if let Some(def_id) = alias_ct.kind.opt_def_id() {
14031403 self.require_type_const_attribute(def_id, span)?;
14041404 }
1405 let ct = Const::new_unevaluated(tcx, ty::IsRigid::No, alias_ct);
1405 let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct);
14061406 let ct = self.check_param_uses_if_mcg(ct, span, false);
14071407 Ok(ct)
14081408 }
......@@ -1865,12 +1865,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
18651865 ty::AssocTag::Const,
18661866 )?;
18671867 self.require_type_const_attribute(item_def_id, span)?;
1868 let uv = ty::UnevaluatedConst::new(
1868 let alias_const = ty::AliasConst::new(
18691869 tcx,
1870 ty::UnevaluatedConstKind::new_from_def_id(tcx, item_def_id),
1870 ty::AliasConstKind::new_from_def_id(tcx, item_def_id),
18711871 item_args,
18721872 );
1873 Ok(Const::new_unevaluated(tcx, ty::IsRigid::No, uv))
1873 Ok(Const::new_alias(tcx, ty::IsRigid::No, alias_const))
18741874 }
18751875
18761876 /// Lower a [resolved][hir::QPath::Resolved] (type-level) associated item path.
......@@ -2772,14 +2772,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27722772 let _ = self
27732773 .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
27742774 let args = self.lower_generic_args_of_path_segment(span, did, segment);
2775 ty::Const::new_unevaluated(
2775 ty::Const::new_alias(
27762776 tcx,
27772777 ty::IsRigid::No,
2778 ty::UnevaluatedConst::new(
2779 tcx,
2780 ty::UnevaluatedConstKind::new_from_def_id(tcx, did),
2781 args,
2782 ),
2778 ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, did), args),
27832779 )
27842780 }
27852781 Res::Def(kind @ DefKind::Ctor(ctor_of, CtorKind::Const), did) => {
......@@ -2915,7 +2911,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
29152911 self.check_param_uses_if_mcg(ct, span, false)
29162912 }
29172913
2918 /// Literals are eagerly converted to a constant, everything else becomes `Unevaluated`.
2914 /// Literals are eagerly converted to a constant, everything else becomes `ConstKind::Alias`.
29192915 #[instrument(skip(self), level = "debug")]
29202916 fn lower_const_arg_anon(&self, anon: &AnonConst) -> Const<'tcx> {
29212917 let tcx = self.tcx();
......@@ -2930,12 +2926,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
29302926
29312927 match self.try_lower_anon_const_lit(ty, expr) {
29322928 Some(v) => v,
2933 None => ty::Const::new_unevaluated(
2929 None => ty::Const::new_alias(
29342930 tcx,
29352931 ty::IsRigid::No,
2936 ty::UnevaluatedConst::new(
2932 ty::AliasConst::new(
29372933 tcx,
2938 ty::UnevaluatedConstKind::Anon { def_id: anon.def_id.to_def_id() },
2934 ty::AliasConstKind::Anon { def_id: anon.def_id.to_def_id() },
29392935 ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()),
29402936 ),
29412937 ),
compiler/rustc_hir_analysis/src/variance/constraints.rs+2-2
......@@ -408,8 +408,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
408408 debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance);
409409
410410 match &c.kind() {
411 ty::ConstKind::Unevaluated(_, uv) => {
412 self.add_constraints_from_invariant_args(current, uv.args, variance);
411 ty::ConstKind::Alias(_, alias_const) => {
412 self.add_constraints_from_invariant_args(current, alias_const.args, variance);
413413 }
414414 _ => {}
415415 }
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs+1-1
......@@ -1488,7 +1488,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14881488 let ct = self.resolve_vars_with_obligations(ct);
14891489
14901490 if self.next_trait_solver()
1491 && let ty::ConstKind::Unevaluated(..) = ct.kind()
1491 && let ty::ConstKind::Alias(..) = ct.kind()
14921492 {
14931493 // We need to use a separate variable here as otherwise the temporary for
14941494 // `self.fulfillment_cx.borrow_mut()` is alive in the `Err` branch, resulting
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs+1-1
......@@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174174 ty::ConstKind::Param(_)
175175 | ty::ConstKind::Expr(_)
176176 | ty::ConstKind::Placeholder(_)
177 | ty::ConstKind::Unevaluated(_, _) => enforce_copy_bound(element, element_ty),
177 | ty::ConstKind::Alias(_, _) => enforce_copy_bound(element, element_ty),
178178
179179 ty::ConstKind::Bound(_, _) | ty::ConstKind::Infer(_) | ty::ConstKind::Error(_) => {
180180 unreachable!()
compiler/rustc_infer/src/infer/freshen.rs+1-1
......@@ -158,7 +158,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
158158
159159 ty::ConstKind::Param(_)
160160 | ty::ConstKind::Value(_)
161 | ty::ConstKind::Unevaluated(..)
161 | ty::ConstKind::Alias(..)
162162 | ty::ConstKind::Expr(..)
163163 | ty::ConstKind::Error(_) => ct.super_fold_with(self),
164164 }
compiler/rustc_infer/src/infer/mod.rs+1-1
......@@ -1266,7 +1266,7 @@ impl<'tcx> InferCtxt<'tcx> {
12661266 ty::ConstKind::Param(_)
12671267 | ty::ConstKind::Bound(_, _)
12681268 | ty::ConstKind::Placeholder(_)
1269 | ty::ConstKind::Unevaluated(_, _)
1269 | ty::ConstKind::Alias(_, _)
12701270 | ty::ConstKind::Value(_)
12711271 | ty::ConstKind::Error(_)
12721272 | ty::ConstKind::Expr(_) => ct,
compiler/rustc_infer/src/infer/relate/generalize.rs+10-10
......@@ -77,7 +77,7 @@ impl<'tcx> InferCtxt<'tcx> {
7777 /// would result in an infinite type as we continuously replace an inference variable
7878 /// in `ct` with `ct` itself.
7979 ///
80 /// This is especially important as unevaluated consts use their parents generics.
80 /// This is especially important as alias consts use their parents generics.
8181 /// They therefore often contain unused args, making these errors far more likely.
8282 ///
8383 /// A good example of this is the following:
......@@ -95,7 +95,7 @@ impl<'tcx> InferCtxt<'tcx> {
9595 /// }
9696 /// ```
9797 ///
98 /// Here `3 + 4` ends up as `ConstKind::Unevaluated` which uses the generics
98 /// Here `3 + 4` ends up as `ConstKind::Alias` which uses the generics
9999 /// of `fn bind` (meaning that its args contain `N`).
100100 ///
101101 /// `bind(arr)` now infers that the type of `arr` must be `[u8; N]`.
......@@ -112,8 +112,8 @@ impl<'tcx> InferCtxt<'tcx> {
112112 target_vid: ty::ConstVid,
113113 source_ct: ty::Const<'tcx>,
114114 ) -> RelateResult<'tcx, ()> {
115 // FIXME(generic_const_exprs): Occurs check failures for unevaluated
116 // constants and generic expressions are not yet handled correctly.
115 // FIXME(generic_const_exprs): Occurs check failures for alias consts
116 // and generic expressions are not yet handled correctly.
117117 debug_assert!(
118118 self.inner.borrow_mut().const_unification_table().probe_value(target_vid).is_unknown()
119119 );
......@@ -752,7 +752,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
752752 }
753753 }
754754 }
755 // FIXME: Unevaluated constants are also not rigid, so the current
755 // FIXME: Alias consts are also not rigid, so the current
756756 // approach of always relating them structurally is incomplete.
757757 //
758758 // FIXME: replace the StructurallyRelateAliases::Yes branch with
......@@ -760,26 +760,26 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
760760 //
761761 // We only need to be careful with potentially normalizeable
762762 // aliases here. See `generalize_alias_term` for more information.
763 ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => {
763 ty::ConstKind::Alias(ty::IsRigid::No, alias_const) => {
764764 match self.structurally_relate_aliases {
765765 // Hack: Fall back to old behavior if GCE is enabled (it used to just be the Yes
766766 // path), as doing this new No path breaks some GCE things. I expect GCE to be
767767 // ripped out soon so this shouldn't matter soon.
768768 StructurallyRelateAliases::No if !tcx.features().generic_const_exprs() => {
769 self.generalize_alias_term(uv.into()).map(|v| v.expect_const())
769 self.generalize_alias_term(alias_const.into()).map(|v| v.expect_const())
770770 }
771771 _ => {
772 let ty::UnevaluatedConst { kind, args, .. } = uv;
772 let ty::AliasConst { kind, args, .. } = alias_const;
773773 let args = self.relate_with_variance(
774774 ty::Invariant,
775775 ty::VarianceDiagInfo::default(),
776776 args,
777777 args,
778778 )?;
779 Ok(ty::Const::new_unevaluated(
779 Ok(ty::Const::new_alias(
780780 tcx,
781781 ty::IsRigid::No,
782 ty::UnevaluatedConst::new(tcx, kind, args),
782 ty::AliasConst::new(tcx, kind, args),
783783 ))
784784 }
785785 }
compiler/rustc_middle/src/mir/consts.rs+3-7
......@@ -221,7 +221,7 @@ pub enum Const<'tcx> {
221221
222222 /// An unevaluated mir constant which is not part of the type system.
223223 ///
224 /// Note that `Ty(ty::ConstKind::Unevaluated)` and this variant are *not* identical! `Ty` will
224 /// Note that `Ty(ty::ConstKind::Alias)` and this variant are *not* identical! `Ty` will
225225 /// always flow through a valtree, so all data not captured in the valtree is lost. This variant
226226 /// directly uses the evaluated result of the given constant, including e.g. data stored in
227227 /// padding.
......@@ -472,13 +472,9 @@ pub struct UnevaluatedConst<'tcx> {
472472
473473impl<'tcx> UnevaluatedConst<'tcx> {
474474 #[inline]
475 pub fn shrink(self, tcx: TyCtxt<'tcx>) -> ty::UnevaluatedConst<'tcx> {
475 pub fn shrink(self, tcx: TyCtxt<'tcx>) -> ty::AliasConst<'tcx> {
476476 assert_eq!(self.promoted, None);
477 ty::UnevaluatedConst::new(
478 tcx,
479 ty::UnevaluatedConstKind::new_from_def_id(tcx, self.def),
480 self.args,
481 )
477 ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, self.def), self.args)
482478 }
483479}
484480
compiler/rustc_middle/src/mir/interpret/queries.rs+5-5
......@@ -90,7 +90,7 @@ impl<'tcx> TyCtxt<'tcx> {
9090 pub fn const_eval_resolve_for_typeck(
9191 self,
9292 typing_env: ty::TypingEnv<'tcx>,
93 ct: ty::UnevaluatedConst<'tcx>,
93 ct: ty::AliasConst<'tcx>,
9494 span: Span,
9595 ) -> ConstToValTreeResult<'tcx> {
9696 // Cannot resolve `Unevaluated` constants that contain inference
......@@ -104,10 +104,10 @@ impl<'tcx> TyCtxt<'tcx> {
104104 }
105105
106106 let def_id = match ct.kind {
107 ty::UnevaluatedConstKind::Projection { def_id }
108 | ty::UnevaluatedConstKind::Inherent { def_id }
109 | ty::UnevaluatedConstKind::Free { def_id }
110 | ty::UnevaluatedConstKind::Anon { def_id } => def_id,
107 ty::AliasConstKind::Projection { def_id }
108 | ty::AliasConstKind::Inherent { def_id }
109 | ty::AliasConstKind::Free { def_id }
110 | ty::AliasConstKind::Anon { def_id } => def_id,
111111 };
112112
113113 let cid = match ty::Instance::try_resolve(self, typing_env, def_id, ct.args) {
compiler/rustc_middle/src/mir/pretty.rs+7-9
......@@ -1491,16 +1491,14 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
14911491 let val = match const_ {
14921492 Const::Ty(_, ct) => match ct.kind() {
14931493 ty::ConstKind::Param(p) => format!("ty::Param({p})"),
1494 ty::ConstKind::Unevaluated(_, uv) => {
1495 let kind = match uv.kind {
1496 ty::UnevaluatedConstKind::Projection { def_id }
1497 | ty::UnevaluatedConstKind::Inherent { def_id }
1498 | ty::UnevaluatedConstKind::Free { def_id }
1499 | ty::UnevaluatedConstKind::Anon { def_id } => {
1500 self.tcx.def_path_str(def_id)
1501 }
1494 ty::ConstKind::Alias(_, alias_const) => {
1495 let kind = match alias_const.kind {
1496 ty::AliasConstKind::Projection { def_id }
1497 | ty::AliasConstKind::Inherent { def_id }
1498 | ty::AliasConstKind::Free { def_id }
1499 | ty::AliasConstKind::Anon { def_id } => self.tcx.def_path_str(def_id),
15021500 };
1503 format!("ty::Unevaluated({}, {:?})", kind, uv.args)
1501 format!("ty::AliasConst({}, {:?})", kind, alias_const.args)
15041502 }
15051503 ty::ConstKind::Value(cv) => {
15061504 format!("ty::Valtree({})", fmt_valtree(&cv))
compiler/rustc_middle/src/ty/abstract_const.rs+3-3
......@@ -52,13 +52,13 @@ impl<'tcx> TyCtxt<'tcx> {
5252 }
5353 fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
5454 let ct = match c.kind() {
55 ty::ConstKind::Unevaluated(_, uv)
56 if let Some(def_id) = uv.kind.opt_def_id() =>
55 ty::ConstKind::Alias(_, alias_const)
56 if let Some(def_id) = alias_const.kind.opt_def_id() =>
5757 {
5858 match self.tcx.thir_abstract_const(def_id) {
5959 Err(e) => ty::Const::new_error(self.tcx, e),
6060 Ok(Some(bac)) => {
61 let args = self.tcx.erase_and_anonymize_regions(uv.args);
61 let args = self.tcx.erase_and_anonymize_regions(alias_const.args);
6262 let bac = bac.instantiate(self.tcx, args).skip_norm_wip();
6363 return bac.fold_with(self);
6464 }
compiler/rustc_middle/src/ty/consts.rs+9-9
......@@ -21,8 +21,8 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed};
2121pub use valtree::*;
2222
2323pub type ConstKind<'tcx> = ir::ConstKind<TyCtxt<'tcx>>;
24pub type UnevaluatedConst<'tcx> = ir::UnevaluatedConst<TyCtxt<'tcx>>;
25pub type UnevaluatedConstKind<'tcx> = ir::UnevaluatedConstKind<TyCtxt<'tcx>>;
24pub type AliasConst<'tcx> = ir::AliasConst<TyCtxt<'tcx>>;
25pub type AliasConstKind<'tcx> = ir::AliasConstKind<TyCtxt<'tcx>>;
2626
2727#[cfg(target_pointer_width = "64")]
2828rustc_data_structures::static_assert_size!(ConstKind<'_>, 32);
......@@ -107,12 +107,12 @@ impl<'tcx> Const<'tcx> {
107107 }
108108
109109 #[inline]
110 pub fn new_unevaluated(
110 pub fn new_alias(
111111 tcx: TyCtxt<'tcx>,
112112 is_rigid: ty::IsRigid,
113 uv: ty::UnevaluatedConst<'tcx>,
113 alias_const: ty::AliasConst<'tcx>,
114114 ) -> Const<'tcx> {
115 Const::new(tcx, ty::ConstKind::Unevaluated(is_rigid, uv))
115 Const::new(tcx, ty::ConstKind::Alias(is_rigid, alias_const))
116116 }
117117
118118 #[inline]
......@@ -157,7 +157,7 @@ impl<'tcx> Const<'tcx> {
157157 true
158158 }
159159 ty::ConstKind::Infer(_)
160 | ty::ConstKind::Unevaluated(..)
160 | ty::ConstKind::Alias(..)
161161 | ty::ConstKind::Value(_)
162162 | ty::ConstKind::Error(_)
163163 | ty::ConstKind::Expr(_) => false,
......@@ -194,12 +194,12 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
194194 Const::new_placeholder(tcx, placeholder)
195195 }
196196
197 fn new_unevaluated(
197 fn new_alias(
198198 interner: TyCtxt<'tcx>,
199199 is_rigid: ty::IsRigid,
200 uv: ty::UnevaluatedConst<'tcx>,
200 alias_const: ty::AliasConst<'tcx>,
201201 ) -> Self {
202 Const::new_unevaluated(interner, is_rigid, uv)
202 Const::new_alias(interner, is_rigid, alias_const)
203203 }
204204
205205 fn new_expr(interner: TyCtxt<'tcx>, expr: ty::Expr<'tcx>) -> Self {
compiler/rustc_middle/src/ty/context/impl_interner.rs+7-10
......@@ -41,7 +41,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
4141 type CoroutineId = DefId;
4242 type AdtId = DefId;
4343 type ImplId = DefId;
44 type UnevaluatedConstId = DefId;
44 type AnonConstId = DefId;
4545 type TraitAssocTyId = DefId;
4646 type TraitAssocConstId = DefId;
4747 type TraitAssocTermId = DefId;
......@@ -208,23 +208,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
208208 self.adt_def(adt_def_id)
209209 }
210210
211 fn unevaluated_const_kind_from_def_id(
212 self,
213 def_id: Self::DefId,
214 ) -> ty::UnevaluatedConstKind<'tcx> {
211 fn alias_const_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasConstKind<'tcx> {
215212 match self.def_kind(def_id) {
216213 DefKind::AssocConst { .. } => {
217214 if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) {
218 ty::UnevaluatedConstKind::Inherent { def_id }
215 ty::AliasConstKind::Inherent { def_id }
219216 } else {
220 ty::UnevaluatedConstKind::Projection { def_id }
217 ty::AliasConstKind::Projection { def_id }
221218 }
222219 }
223 DefKind::Const { .. } => ty::UnevaluatedConstKind::Free { def_id },
220 DefKind::Const { .. } => ty::AliasConstKind::Free { def_id },
224221 DefKind::AnonConst | DefKind::InlineConst | DefKind::Ctor(_, CtorKind::Const) => {
225 ty::UnevaluatedConstKind::Anon { def_id }
222 ty::AliasConstKind::Anon { def_id }
226223 }
227 kind => bug!("unexpected DefKind in UnevaluatedConst: {kind:?}"),
224 kind => bug!("unexpected DefKind in AliasConst: {kind:?}"),
228225 }
229226 }
230227
compiler/rustc_middle/src/ty/mod.rs+5-5
......@@ -76,9 +76,9 @@ pub use self::closure::{
7676 place_to_string_for_capture,
7777};
7878pub use self::consts::{
79 AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult, Expr, ExprKind,
80 LitToConstInput, ScalarInt, SimdAlign, UnevaluatedConst, UnevaluatedConstKind, ValTree,
81 ValTreeKindExt, Value, const_lit_matches_ty,
79 AliasConst, AliasConstKind, AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult,
80 Expr, ExprKind, LitToConstInput, ScalarInt, SimdAlign, ValTree, ValTreeKindExt, Value,
81 const_lit_matches_ty,
8282};
8383pub use self::context::{
8484 CtxtInterners, CurrentGcx, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
......@@ -693,7 +693,7 @@ impl<'tcx> Term<'tcx> {
693693 _ => None,
694694 },
695695 TermKind::Const(ct) => match ct.kind() {
696 ConstKind::Unevaluated(_, uv) => Some(uv.into()),
696 ConstKind::Alias(_, alias_const) => Some(alias_const.into()),
697697 _ => None,
698698 },
699699 }
......@@ -706,7 +706,7 @@ impl<'tcx> Term<'tcx> {
706706 _ => false,
707707 },
708708 ty::TermKind::Const(ct) => match ct.kind() {
709 ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => true,
709 ty::ConstKind::Alias(ty::IsRigid::No, _) => true,
710710 _ => false,
711711 },
712712 }
compiler/rustc_middle/src/ty/print/pretty.rs+5-5
......@@ -1579,14 +1579,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15791579 }
15801580
15811581 match ct.kind() {
1582 ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => {
1582 ty::ConstKind::Alias(_, ty::AliasConst { kind, args, .. }) => {
15831583 match kind {
1584 ty::UnevaluatedConstKind::Projection { def_id }
1585 | ty::UnevaluatedConstKind::Inherent { def_id }
1586 | ty::UnevaluatedConstKind::Free { def_id } => {
1584 ty::AliasConstKind::Projection { def_id }
1585 | ty::AliasConstKind::Inherent { def_id }
1586 | ty::AliasConstKind::Free { def_id } => {
15871587 self.pretty_print_value_path(def_id, args)?;
15881588 }
1589 ty::UnevaluatedConstKind::Anon { def_id } => {
1589 ty::AliasConstKind::Anon { def_id } => {
15901590 if def_id.is_local()
15911591 && let span = self.tcx().def_span(def_id)
15921592 && let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span)
compiler/rustc_middle/src/ty/structural_impls.rs+5-5
......@@ -634,8 +634,8 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
634634 folder: &mut F,
635635 ) -> Result<Self, F::Error> {
636636 let kind = match self.kind() {
637 ConstKind::Unevaluated(is_rigid, uv) => {
638 ConstKind::Unevaluated(is_rigid, uv.try_fold_with(folder)?)
637 ConstKind::Alias(is_rigid, alias_const) => {
638 ConstKind::Alias(is_rigid, alias_const.try_fold_with(folder)?)
639639 }
640640 ConstKind::Value(v) => ConstKind::Value(v.try_fold_with(folder)?),
641641 ConstKind::Expr(e) => ConstKind::Expr(e.try_fold_with(folder)?),
......@@ -651,8 +651,8 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
651651
652652 fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
653653 let kind = match self.kind() {
654 ConstKind::Unevaluated(is_rigid, uv) => {
655 ConstKind::Unevaluated(is_rigid, uv.fold_with(folder))
654 ConstKind::Alias(is_rigid, alias_const) => {
655 ConstKind::Alias(is_rigid, alias_const.fold_with(folder))
656656 }
657657 ConstKind::Value(v) => ConstKind::Value(v.fold_with(folder)),
658658 ConstKind::Expr(e) => ConstKind::Expr(e.fold_with(folder)),
......@@ -670,7 +670,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
670670impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
671671 fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
672672 match self.kind() {
673 ConstKind::Unevaluated(_, uv) => uv.visit_with(visitor),
673 ConstKind::Alias(_, alias_const) => alias_const.visit_with(visitor),
674674 ConstKind::Value(v) => v.visit_with(visitor),
675675 ConstKind::Expr(e) => e.visit_with(visitor),
676676 ConstKind::Error(e) => e.visit_with(visitor),
compiler/rustc_middle/src/ty/visit.rs+2-2
......@@ -200,10 +200,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector<'tcx> {
200200
201201 fn visit_const(&mut self, c: ty::Const<'tcx>) {
202202 // if we are only looking for "constrained" region, we have to
203 // ignore the inputs of an unevaluated const, as they may not appear
203 // ignore the inputs of an alias const, as they may not appear
204204 // in the normalized form
205205 if self.just_constrained {
206 if let ty::ConstKind::Unevaluated(..) = c.kind() {
206 if let ty::ConstKind::Alias(..) = c.kind() {
207207 return;
208208 }
209209 }
compiler/rustc_mir_build/src/builder/expr/as_constant.rs+3-3
......@@ -72,12 +72,12 @@ pub(crate) fn as_constant_inner<'tcx>(
7272 ExprKind::NamedConst { def_id, args, ref user_ty } => {
7373 let user_ty = user_ty.as_ref().and_then(push_cuta);
7474 if tcx.is_type_const(def_id) {
75 let uneval = ty::UnevaluatedConst::new(
75 let uneval = ty::AliasConst::new(
7676 tcx,
77 ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id),
77 ty::AliasConstKind::new_from_def_id(tcx, def_id),
7878 args,
7979 );
80 let ct = ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval);
80 let ct = ty::Const::new_alias(tcx, ty::IsRigid::No, uneval);
8181
8282 let const_ = Const::Ty(ty, ct);
8383 return ConstOperand { span, user_ty, const_ };
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs+69-72
......@@ -49,7 +49,7 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> {
4949 let mut convert = ConstToPat::new(self, id, span, c);
5050
5151 match c.kind() {
52 ty::ConstKind::Unevaluated(_, uv) => convert.unevaluated_to_pat(uv, ty),
52 ty::ConstKind::Alias(_, alias_const) => convert.alias_to_pat(alias_const, ty),
5353 ty::ConstKind::Value(value) => convert.valtree_to_pat(value),
5454 _ => span_bug!(span, "Invalid `ConstKind` for `const_to_pat`: {:?}", c),
5555 }
......@@ -77,17 +77,17 @@ impl<'tcx> ConstToPat<'tcx> {
7777
7878 /// We errored. Signal that in the pattern, so that follow up errors can be silenced.
7979 fn mk_err(&self, mut err: Diag<'_>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> {
80 if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind() {
81 if let ty::UnevaluatedConstKind::Projection { def_id }
82 | ty::UnevaluatedConstKind::Inherent { def_id } = uv.kind
80 if let ty::ConstKind::Alias(_, alias_const) = self.c.kind() {
81 if let ty::AliasConstKind::Projection { def_id }
82 | ty::AliasConstKind::Inherent { def_id } = alias_const.kind
8383 && let Some(def_id) = def_id.as_local()
8484 {
8585 // Include the container item in the output.
8686 err.span_label(self.tcx.def_span(self.tcx.local_parent(def_id)), "");
8787 }
88 if let ty::UnevaluatedConstKind::Projection { def_id }
89 | ty::UnevaluatedConstKind::Inherent { def_id }
90 | ty::UnevaluatedConstKind::Free { def_id } = uv.kind
88 if let ty::AliasConstKind::Projection { def_id }
89 | ty::AliasConstKind::Inherent { def_id }
90 | ty::AliasConstKind::Free { def_id } = alias_const.kind
9191 {
9292 err.span_label(self.tcx.def_span(def_id), msg!("constant defined here"));
9393 }
......@@ -95,11 +95,7 @@ impl<'tcx> ConstToPat<'tcx> {
9595 Box::new(Pat { span: self.span, ty, kind: PatKind::Error(err.emit()), extra: None })
9696 }
9797
98 fn unevaluated_to_pat(
99 &mut self,
100 uv: ty::UnevaluatedConst<'tcx>,
101 ty: Ty<'tcx>,
102 ) -> Box<Pat<'tcx>> {
98 fn alias_to_pat(&mut self, alias_const: ty::AliasConst<'tcx>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> {
10399 // It's not *technically* correct to be revealing opaque types here as borrowcheck has
104100 // not run yet. However, CTFE itself uses `TypingMode::PostAnalysis` unconditionally even
105101 // during typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821).
......@@ -109,13 +105,13 @@ impl<'tcx> ConstToPat<'tcx> {
109105 // instead of having this logic here
110106 let typing_env =
111107 self.tcx.erase_and_anonymize_regions(self.typing_env).with_codegen_normalized(self.tcx);
112 let uv = self.tcx.erase_and_anonymize_regions(uv);
108 let alias_const = self.tcx.erase_and_anonymize_regions(alias_const);
113109
114110 // FIXME(gca): This will become insufficient once associated constants can be
115111 // implemented as `type` consts (project-const-generics#76). At that point it'll
116112 // become necessary to just use type system normalization for all const patterns
117113 // but that's not yet possible.
118 let mut thir_pat = if uv.kind.is_type_const(self.tcx) {
114 let mut thir_pat = if alias_const.kind.is_type_const(self.tcx) {
119115 let Ok(normalize) = self
120116 .tcx
121117 .try_normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(self.c))
......@@ -132,67 +128,68 @@ impl<'tcx> ConstToPat<'tcx> {
132128 } else {
133129 // try to resolve e.g. associated constants to their definition on an impl, and then
134130 // evaluate the const.
135 let valtree = match self.tcx.const_eval_resolve_for_typeck(typing_env, uv, self.span) {
136 Ok(Ok(c)) => c,
137 Err(ErrorHandled::Reported(_, _)) => {
138 // Let's tell the use where this failing const occurs.
139 let mut err =
140 self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
141 // We've emitted an error on the original const, it would be redundant to complain
142 // on its use as well.
143 if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind()
144 && let ty::UnevaluatedConstKind::Projection { .. }
145 | ty::UnevaluatedConstKind::Inherent { .. }
146 | ty::UnevaluatedConstKind::Free { .. } = uv.kind
147 {
148 err.downgrade_to_delayed_bug();
149 }
150 return self.mk_err(err, ty);
151 }
152 Err(ErrorHandled::TooGeneric(_)) => {
153 let mut e = self
154 .tcx
155 .dcx()
156 .create_err(ConstPatternDependsOnGenericParameter { span: self.span });
157 for arg in uv.args {
158 if let ty::GenericArgKind::Type(ty) = arg.kind()
159 && let ty::Param(param_ty) = ty.kind()
131 let valtree =
132 match self.tcx.const_eval_resolve_for_typeck(typing_env, alias_const, self.span) {
133 Ok(Ok(c)) => c,
134 Err(ErrorHandled::Reported(_, _)) => {
135 // Let's tell the use where this failing const occurs.
136 let mut err =
137 self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
138 // We've emitted an error on the original const, it would be redundant to complain
139 // on its use as well.
140 if let ty::ConstKind::Alias(_, alias_const) = self.c.kind()
141 && let ty::AliasConstKind::Projection { .. }
142 | ty::AliasConstKind::Inherent { .. }
143 | ty::AliasConstKind::Free { .. } = alias_const.kind
160144 {
161 let def_id = self.tcx.hir_enclosing_body_owner(self.id);
162 let generics = self.tcx.generics_of(def_id);
163 let param = generics.type_param(*param_ty, self.tcx);
164 let span = self.tcx.def_span(param.def_id);
165 e.span_label(span, "constant depends on this generic parameter");
166 if let Some(ident) = self.tcx.def_ident_span(def_id)
167 && self.tcx.sess.source_map().is_multiline(ident.between(span))
145 err.downgrade_to_delayed_bug();
146 }
147 return self.mk_err(err, ty);
148 }
149 Err(ErrorHandled::TooGeneric(_)) => {
150 let mut err = self
151 .tcx
152 .dcx()
153 .create_err(ConstPatternDependsOnGenericParameter { span: self.span });
154 for arg in alias_const.args {
155 if let ty::GenericArgKind::Type(ty) = arg.kind()
156 && let ty::Param(param_ty) = ty.kind()
168157 {
169 // Display the `fn` name as well in the diagnostic, as the generic isn't
170 // in the same line and it could be confusing otherwise.
171 e.span_label(ident, "");
158 let def_id = self.tcx.hir_enclosing_body_owner(self.id);
159 let generics = self.tcx.generics_of(def_id);
160 let param = generics.type_param(*param_ty, self.tcx);
161 let span = self.tcx.def_span(param.def_id);
162 err.span_label(span, "constant depends on this generic parameter");
163 if let Some(ident) = self.tcx.def_ident_span(def_id)
164 && self.tcx.sess.source_map().is_multiline(ident.between(span))
165 {
166 // Display the `fn` name as well in the diagnostic, as the generic isn't
167 // in the same line and it could be confusing otherwise.
168 err.span_label(ident, "");
169 }
172170 }
173171 }
172 return self.mk_err(err, ty);
174173 }
175 return self.mk_err(e, ty);
176 }
177 Ok(Err(bad_ty)) => {
178 // The pattern cannot be turned into a valtree.
179 let e = match bad_ty.kind() {
180 ty::Adt(def, ..) => {
181 assert!(def.is_union());
182 self.tcx.dcx().create_err(UnionPattern { span: self.span })
183 }
184 ty::FnPtr(..) | ty::RawPtr(..) => {
185 self.tcx.dcx().create_err(PointerPattern { span: self.span })
186 }
187 _ => self.tcx.dcx().create_err(InvalidPattern {
188 span: self.span,
189 non_sm_ty: bad_ty,
190 prefix: bad_ty.prefix_string(self.tcx).to_string(),
191 }),
192 };
193 return self.mk_err(e, ty);
194 }
195 };
174 Ok(Err(bad_ty)) => {
175 // The pattern cannot be turned into a valtree.
176 let e = match bad_ty.kind() {
177 ty::Adt(def, ..) => {
178 assert!(def.is_union());
179 self.tcx.dcx().create_err(UnionPattern { span: self.span })
180 }
181 ty::FnPtr(..) | ty::RawPtr(..) => {
182 self.tcx.dcx().create_err(PointerPattern { span: self.span })
183 }
184 _ => self.tcx.dcx().create_err(InvalidPattern {
185 span: self.span,
186 non_sm_ty: bad_ty,
187 prefix: bad_ty.prefix_string(self.tcx).to_string(),
188 }),
189 };
190 return self.mk_err(e, ty);
191 }
192 };
196193
197194 // Lower the valtree to a THIR pattern.
198195 self.valtree_to_pat(ty::Value { ty, valtree })
......@@ -209,7 +206,7 @@ impl<'tcx> ConstToPat<'tcx> {
209206
210207 // Mark the pattern to indicate that it is the result of lowering a named
211208 // constant. This is used for diagnostics.
212 thir_pat.extra.get_or_insert_default().expanded_const = uv.kind.opt_def_id();
209 thir_pat.extra.get_or_insert_default().expanded_const = alias_const.kind.opt_def_id();
213210 thir_pat
214211 }
215212
......@@ -253,7 +250,7 @@ impl<'tcx> ConstToPat<'tcx> {
253250 // then error about that instead, because `TypeNotStructural` gives advice that is
254251 // relevant only when the problem is that `ty` does not derive `PartialEq`.
255252 //
256 // Note that this is a duplicate of a check in `unevaluated_to_pat()`,
253 // Note that this is a duplicate of a check in `alias_to_pat()`,
257254 // which we would run later if we weren’t emitting an error now.
258255 if possibly_inapplicable_derived_partial_eq && !has_impl {
259256 let mut err =
compiler/rustc_mir_build/src/thir/pattern/mod.rs+3-3
......@@ -657,12 +657,12 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> {
657657 let args = self.typeck_results.node_args(id);
658658 // FIXME(mgca): we will need to special case IACs here to have type system compatible
659659 // generic args, instead of how we represent them in body expressions.
660 let c = ty::Const::new_unevaluated(
660 let c = ty::Const::new_alias(
661661 self.tcx,
662662 ty::IsRigid::No,
663 ty::UnevaluatedConst::new(
663 ty::AliasConst::new(
664664 self.tcx,
665 ty::UnevaluatedConstKind::new_from_def_id(self.tcx, def_id),
665 ty::AliasConstKind::new_from_def_id(self.tcx, def_id),
666666 args,
667667 ),
668668 );
compiler/rustc_mir_transform/src/impossible_predicates.rs+1-1
......@@ -44,7 +44,7 @@ pub(crate) fn has_impossible_predicates(tcx: TyCtxt<'_>, def_id: DefId) -> bool
4444 !p.has_type_flags(
4545 // Only consider global clauses to simplify.
4646 TypeFlags::HAS_FREE_LOCAL_NAMES
47 // Clauses that refer to unevaluated constants as they cause cycles.
47 // Clauses that refer to alias constants as they cause cycles.
4848 | TypeFlags::HAS_CT_PROJECTION,
4949 )
5050 });
compiler/rustc_mir_transform/src/inline.rs+1-1
......@@ -1026,7 +1026,7 @@ fn inline_call<'tcx, I: Inliner<'tcx>>(
10261026 });
10271027
10281028 // Copy required constants from the callee_body into the caller_body. Although we are only
1029 // pushing unevaluated consts to `required_consts`, here they may have been evaluated
1029 // pushing constants that still need evaluation to `required_consts`, here they may have been evaluated
10301030 // because we are calling `instantiate_and_normalize_erasing_regions` -- so we filter again.
10311031 caller_body.required_consts.as_mut().unwrap().extend(
10321032 callee_body.required_consts().into_iter().filter(|ct| ct.const_.is_required_const()),
compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs+1-1
......@@ -565,7 +565,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
565565 },
566566 // FIXME: See comment above -- we could fold the region separately or something.
567567 ty::ConstKind::Bound(_, _)
568 | ty::ConstKind::Unevaluated(_, _)
568 | ty::ConstKind::Alias(_, _)
569569 | ty::ConstKind::Value(_)
570570 | ty::ConstKind::Error(_)
571571 | ty::ConstKind::Expr(_) => return c.super_fold_with(self),
compiler/rustc_next_trait_solver/src/delegate.rs+1-1
......@@ -37,7 +37,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
3737 fn evaluate_const(
3838 &self,
3939 param_env: <Self::Interner as Interner>::ParamEnv,
40 uv: ty::UnevaluatedConst<Self::Interner>,
40 alias_const: ty::AliasConst<Self::Interner>,
4141 ) -> Option<<Self::Interner as Interner>::Const>;
4242
4343 // FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`!
compiler/rustc_next_trait_solver/src/normalize.rs+5-5
......@@ -231,7 +231,7 @@ where
231231 // With eager normalization, we should normalize the args of alias before
232232 // normalizing the alias itself.
233233 let ct = ct.try_super_fold_with(self)?;
234 let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return Ok(ct) };
234 let ty::ConstKind::Alias(orig_is_rigid, alias_const) = ct.kind() else { return Ok(ct) };
235235 // We support ambiguous aliases inside rigid alias. So we still recognize
236236 // the rigidness of the outer alias.
237237 if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes {
......@@ -239,10 +239,10 @@ where
239239 }
240240
241241 let normalized = if ct.has_escaping_bound_vars() {
242 let (uv, mapped_regions, mapped_types, mapped_consts) =
243 BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uv);
242 let (alias_const, mapped_regions, mapped_types, mapped_consts) =
243 BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, alias_const);
244244 let Some(result) = ensure_sufficient_stack(|| {
245 self.normalize_alias_term(uv.into(), HasEscapingBoundVars::Yes)
245 self.normalize_alias_term(alias_const.into(), HasEscapingBoundVars::Yes)
246246 })?
247247 else {
248248 return Ok(ct);
......@@ -257,7 +257,7 @@ where
257257 )
258258 } else {
259259 ensure_sufficient_stack(|| {
260 self.normalize_alias_term(uv.into(), HasEscapingBoundVars::No)
260 self.normalize_alias_term(alias_const.into(), HasEscapingBoundVars::No)
261261 })?
262262 .map(|term| term.expect_const())
263263 .unwrap_or(ct)
compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs+7-7
......@@ -1439,13 +1439,13 @@ where
14391439 pub(super) fn evaluate_const(
14401440 &mut self,
14411441 param_env: I::ParamEnv,
1442 uv: ty::UnevaluatedConst<I>,
1442 alias_const: ty::AliasConst<I>,
14431443 ) -> Result<Option<I::Const>, RerunNonErased> {
14441444 if self.typing_mode().is_erased_not_coherence() {
14451445 match self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)? {}
14461446 }
14471447
1448 Ok(self.delegate.evaluate_const(param_env, uv))
1448 Ok(self.delegate.evaluate_const(param_env, alias_const))
14491449 }
14501450
14511451 pub(super) fn evaluate_const_and_instantiate_projection_term(
......@@ -1453,9 +1453,9 @@ where
14531453 param_env: I::ParamEnv,
14541454 projection_term: ty::AliasTerm<I>,
14551455 expected_term: I::Term,
1456 uv: ty::UnevaluatedConst<I>,
1456 alias_const: ty::AliasConst<I>,
14571457 ) -> QueryResultOrRerunNonErased<I> {
1458 match self.evaluate_const(param_env, uv)? {
1458 match self.evaluate_const(param_env, alias_const)? {
14591459 Some(evaluated) => {
14601460 self.eq(param_env, expected_term, evaluated.into())?;
14611461 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
......@@ -1468,11 +1468,11 @@ where
14681468 // Perhaps we could split EvaluateConstErr::HasGenericsOrInfers into HasGenerics and
14691469 // HasInfers or something, make evaluate_const return that, and make this branch be
14701470 // based on that, rather than checking `has_non_region_infer`.
1471 if self.resolve_vars_if_possible(uv).has_non_region_infer() {
1471 if self.resolve_vars_if_possible(alias_const).has_non_region_infer() {
14721472 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
14731473 } else {
1474 // We do not instantiate to the `uv` passed in, but rather
1475 // `goal.predicate.alias`. The `uv` passed in might correspond to the `impl`
1474 // We do not instantiate to the `alias_const` passed in, but rather
1475 // `goal.predicate.alias`. The `alias_const` passed in might correspond to the `impl`
14761476 // form of a constant (with generic arguments corresponding to the impl block),
14771477 // however, we want to structurally instantiate to the original, non-rebased,
14781478 // trait `Self` form of the constant (with generic arguments being the trait
compiler/rustc_next_trait_solver/src/solve/mod.rs+6-6
......@@ -196,7 +196,7 @@ where
196196 Goal { param_env, predicate: ct }: Goal<I, I::Const>,
197197 ) -> QueryResultOrRerunNonErased<I> {
198198 match ct.kind() {
199 ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _)
199 ty::ConstKind::Alias(ty::IsRigid::Yes, _)
200200 | ty::ConstKind::Placeholder(_)
201201 | ty::ConstKind::Value(_)
202202 | ty::ConstKind::Error(_) => {
......@@ -207,7 +207,7 @@ where
207207 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
208208 }
209209
210 ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => {
210 ty::ConstKind::Alias(ty::IsRigid::No, alias_const) => {
211211 // We never return `NoSolution` here as `evaluate_const` emits an
212212 // error itself when failing to evaluate, so emitting an additional fulfillment
213213 // error in that case is unnecessary noise. This may change in the future once
......@@ -216,7 +216,7 @@ where
216216
217217 // FIXME(generic_const_exprs): Implement handling for generic
218218 // const expressions here.
219 if let Some(_normalized) = self.evaluate_const(param_env, uv)? {
219 if let Some(_normalized) = self.evaluate_const(param_env, alias_const)? {
220220 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
221221 } else {
222222 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
......@@ -252,10 +252,10 @@ where
252252 .evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
253253 .map_err(Into::into);
254254 }
255 ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => {
256 uv.type_of(self.cx()).skip_norm_wip()
255 ty::ConstKind::Alias(ty::IsRigid::Yes, alias_const) => {
256 alias_const.type_of(self.cx()).skip_norm_wip()
257257 }
258 ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => unimplemented!(
258 ty::ConstKind::Alias(ty::IsRigid::No, _) => unimplemented!(
259259 "non-rigid unevaluated constant for compute_const_arg_has_type_goal: {ct:?}"
260260 ),
261261 ty::ConstKind::Expr(_) => unimplemented!(
compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs+3-3
......@@ -445,9 +445,9 @@ where
445445 c.into()
446446 }
447447 ty::AliasTermKind::ProjectionConst { .. } => {
448 let uv = ty::UnevaluatedConst::new(
448 let alias_const = ty::AliasConst::new(
449449 cx,
450 ty::UnevaluatedConstKind::Projection {
450 ty::AliasConstKind::Projection {
451451 def_id: target_item_def_id.into().try_into().unwrap(),
452452 },
453453 target_args,
......@@ -456,7 +456,7 @@ where
456456 goal.param_env,
457457 goal.predicate.alias,
458458 goal.predicate.term,
459 uv,
459 alias_const,
460460 );
461461 }
462462 kind => panic!("expected projection, found {kind:?}"),
compiler/rustc_next_trait_solver/src/solve/project_goals/anon_const.rs+2-2
......@@ -15,12 +15,12 @@ where
1515 &mut self,
1616 goal: Goal<I, ty::ProjectionPredicate<I>>,
1717 ) -> QueryResultOrRerunNonErased<I> {
18 let uv = goal.predicate.projection_term.expect_ct();
18 let alias_const = goal.predicate.projection_term.expect_ct();
1919 self.evaluate_const_and_instantiate_projection_term(
2020 goal.param_env,
2121 goal.predicate.projection_term,
2222 goal.predicate.term,
23 uv,
23 alias_const,
2424 )
2525 }
2626}
compiler/rustc_public/src/unstable/convert/stable/ty.rs+5-7
......@@ -552,16 +552,14 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
552552 }
553553 }
554554 ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)),
555 ty::ConstKind::Unevaluated(_, uv) => {
556 let Some(def_id) = uv.kind.opt_def_id() else {
557 // FIXME: implement (both AliasTy and UnevaluatedConst will be needing this soon)
558 panic!(
559 "non-defid unevaluated constants are not supported by rustc_public at the moment"
560 )
555 ty::ConstKind::Alias(_, alias_const) => {
556 let Some(def_id) = alias_const.kind.opt_def_id() else {
557 // FIXME: implement (both AliasTy and AliasConst will be needing this soon)
558 panic!("non-defid alias consts are not supported by rustc_public at the moment")
561559 };
562560 crate::ty::TyConstKind::Unevaluated(
563561 tables.const_def(def_id),
564 uv.args.stable(tables, cx),
562 alias_const.args.stable(tables, cx),
565563 )
566564 }
567565 ty::ConstKind::Error(_) => unreachable!(),
compiler/rustc_symbol_mangling/src/v0.rs+6-6
......@@ -696,13 +696,13 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
696696 return Ok(());
697697 }
698698
699 // We may still encounter unevaluated consts due to the printing
699 // We may still encounter alias consts due to the printing
700700 // logic sometimes passing identity-substituted impl headers.
701 ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => match kind {
702 ty::UnevaluatedConstKind::Projection { def_id }
703 | ty::UnevaluatedConstKind::Inherent { def_id }
704 | ty::UnevaluatedConstKind::Free { def_id }
705 | ty::UnevaluatedConstKind::Anon { def_id } => {
701 ty::ConstKind::Alias(_, ty::AliasConst { kind, args, .. }) => match kind {
702 ty::AliasConstKind::Projection { def_id }
703 | ty::AliasConstKind::Inherent { def_id }
704 | ty::AliasConstKind::Free { def_id }
705 | ty::AliasConstKind::Anon { def_id } => {
706706 return self.print_def_path(def_id, args);
707707 }
708708 },
compiler/rustc_trait_selection/src/diagnostics.rs+2-2
......@@ -21,11 +21,11 @@ use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlig
2121pub(crate) mod note_and_explain;
2222
2323#[derive(Diagnostic)]
24#[diag("unable to construct a constant value for the unevaluated constant {$unevaluated}")]
24#[diag("unable to construct a constant value for the alias const {$alias_const}")]
2525pub(crate) struct UnableToConstructConstantValue<'a> {
2626 #[primary_span]
2727 pub span: Span,
28 pub unevaluated: ty::UnevaluatedConst<'a>,
28 pub alias_const: ty::AliasConst<'a>,
2929}
3030
3131pub(crate) struct NegativePositiveConflict<'tcx> {
compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs+2-2
......@@ -1079,9 +1079,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
10791079 }
10801080 }
10811081 GenericArgKind::Const(ct) => {
1082 if matches!(ct.kind(), ty::ConstKind::Unevaluated(..)) {
1082 if matches!(ct.kind(), ty::ConstKind::Alias(..)) {
10831083 // You can't write the generic arguments for
1084 // unevaluated constants.
1084 // alias constants.
10851085 walker.skip_current_subtree();
10861086 }
10871087 }
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs+4-4
......@@ -3769,12 +3769,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
37693769
37703770 match obligation.predicate.kind().skip_binder() {
37713771 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => match ct.kind() {
3772 ty::ConstKind::Unevaluated(_, uv) => {
3772 ty::ConstKind::Alias(_, alias_const) => {
37733773 let mut err =
37743774 self.dcx().struct_span_err(span, "unconstrained generic constant");
3775 let const_span = uv.kind.def_span(self.tcx);
3775 let const_span = alias_const.kind.def_span(self.tcx);
37763776
3777 let const_ty = uv.type_of(self.tcx).skip_norm_wip();
3777 let const_ty = alias_const.type_of(self.tcx).skip_norm_wip();
37783778 let cast = if const_ty != self.tcx.types.usize { " as usize" } else { "" };
37793779 let msg = "try adding a `where` bound";
37803780 if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(const_span) {
......@@ -3812,7 +3812,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
38123812 Ok(err)
38133813 }
38143814 _ => {
3815 bug!("const evaluatable failed for non-unevaluated const `{ct:?}`");
3815 bug!("const evaluatable failed for non-alias const `{ct:?}`");
38163816 }
38173817 },
38183818 _ => {
compiler/rustc_trait_selection/src/solve/delegate.rs+2-2
......@@ -218,9 +218,9 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
218218 fn evaluate_const(
219219 &self,
220220 param_env: ty::ParamEnv<'tcx>,
221 uv: ty::UnevaluatedConst<'tcx>,
221 alias_const: ty::AliasConst<'tcx>,
222222 ) -> Option<ty::Const<'tcx>> {
223 let ct = ty::Const::new_unevaluated(self.tcx, ty::IsRigid::No, uv);
223 let ct = ty::Const::new_alias(self.tcx, ty::IsRigid::No, alias_const);
224224
225225 match crate::traits::try_evaluate_const(&self.0, ct, param_env) {
226226 Ok(ct) => Some(ct),
compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs+3-1
......@@ -34,7 +34,9 @@ pub(super) fn fulfillment_error_for_no_solution<'tcx>(
3434 }
3535 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => {
3636 let ct_ty = match ct.kind() {
37 ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(),
37 ty::ConstKind::Alias(_, alias_const) => {
38 alias_const.type_of(infcx.tcx).skip_norm_wip()
39 }
3840 ty::ConstKind::Param(param_ct) => {
3941 param_ct.find_const_ty_from_env(obligation.param_env)
4042 }
compiler/rustc_trait_selection/src/solve/normalize.rs+7-4
......@@ -146,18 +146,21 @@ impl<'me, 'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'me, 'tcx> {
146146 }
147147
148148 let ct = ct.super_fold_with(self);
149 let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return ct };
149 let ty::ConstKind::Alias(orig_is_rigid, alias_const) = ct.kind() else { return ct };
150150 if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes {
151151 return ct;
152152 }
153153
154154 if ct.has_escaping_bound_vars() {
155 let (replaced, ..) =
156 BoundVarReplacer::replace_bound_vars(self.at.infcx, &mut self.universes, uv);
155 let (replaced, ..) = BoundVarReplacer::replace_bound_vars(
156 self.at.infcx,
157 &mut self.universes,
158 alias_const,
159 );
157160 let _ = self.term_to_infer(replaced.into());
158161 ct
159162 } else {
160 self.term_to_infer(uv.into()).expect_const()
163 self.term_to_infer(alias_const.into()).expect_const()
161164 }
162165 }
163166}
compiler/rustc_trait_selection/src/traits/auto_trait.rs+3-3
......@@ -774,15 +774,15 @@ impl<'tcx> AutoTraitFinder<'tcx> {
774774 }
775775 ty::PredicateKind::ConstEquate(c1, c2) => {
776776 let evaluate = |c: ty::Const<'tcx>| {
777 if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() {
777 if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
778778 let ct =
779779 super::try_evaluate_const(selcx.infcx, c, obligation.param_env);
780780
781781 if let Err(EvaluateConstErr::InvalidConstParamTy(_)) = ct {
782 let span = unevaluated.kind.def_span(self.tcx);
782 let span = alias_const.kind.def_span(self.tcx);
783783 self.tcx
784784 .dcx()
785 .emit_err(UnableToConstructConstantValue { span, unevaluated });
785 .emit_err(UnableToConstructConstantValue { span, alias_const });
786786 }
787787
788788 ct
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs+8-11
......@@ -30,7 +30,7 @@ pub fn is_const_evaluatable<'tcx>(
3030) -> Result<(), NotConstEvaluatable> {
3131 let tcx = infcx.tcx;
3232 match tcx.expand_abstract_consts(unexpanded_ct).kind() {
33 ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Expr(_) => (),
33 ty::ConstKind::Alias(_, _) | ty::ConstKind::Expr(_) => (),
3434 ty::ConstKind::Param(_)
3535 | ty::ConstKind::Bound(_, _)
3636 | ty::ConstKind::Placeholder(_)
......@@ -44,10 +44,7 @@ pub fn is_const_evaluatable<'tcx>(
4444
4545 let is_anon_ct = matches!(
4646 ct.kind(),
47 ty::ConstKind::Unevaluated(
48 _,
49 ty::UnevaluatedConst { kind: ty::UnevaluatedConstKind::Anon { .. }, .. }
50 )
47 ty::ConstKind::Alias(_, ty::AliasConst { kind: ty::AliasConstKind::Anon { .. }, .. })
5148 );
5249
5350 if !is_anon_ct {
......@@ -69,7 +66,7 @@ pub fn is_const_evaluatable<'tcx>(
6966 // here.
7067 tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported");
7168 }
72 ty::ConstKind::Unevaluated(_, _) => {
69 ty::ConstKind::Alias(_, _) => {
7370 match crate::traits::try_evaluate_const(infcx, unexpanded_ct, param_env) {
7471 Err(EvaluateConstErr::HasGenericsOrInfers) => {
7572 Err(NotConstEvaluatable::Error(infcx.dcx().span_delayed_bug(
......@@ -93,8 +90,8 @@ pub fn is_const_evaluatable<'tcx>(
9390 crate::traits::evaluate_const(infcx, unexpanded_ct, param_env);
9491 Ok(())
9592 } else {
96 let uv = match unexpanded_ct.kind() {
97 ty::ConstKind::Unevaluated(_, uv) => uv,
93 let alias_const = match unexpanded_ct.kind() {
94 ty::ConstKind::Alias(_, alias_const) => alias_const,
9895 ty::ConstKind::Expr(_) => {
9996 bug!("`ConstKind::Expr` without `feature(generic_const_exprs)` enabled")
10097 }
......@@ -117,7 +114,7 @@ pub fn is_const_evaluatable<'tcx>(
117114 tcx.dcx()
118115 .struct_span_fatal(
119116 // Slightly better span than just using `span` alone
120 if span == DUMMY_SP { uv.kind.def_span(tcx) } else { span },
117 if span == DUMMY_SP { alias_const.kind.def_span(tcx) } else { span },
121118 "failed to evaluate generic const expression",
122119 )
123120 .with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`")
......@@ -131,9 +128,9 @@ pub fn is_const_evaluatable<'tcx>(
131128 }
132129
133130 Err(EvaluateConstErr::HasGenericsOrInfers) => {
134 let err = if uv.has_non_region_infer() {
131 let err = if alias_const.has_non_region_infer() {
135132 NotConstEvaluatable::MentionsInfer
136 } else if uv.has_non_region_param() {
133 } else if alias_const.has_non_region_param() {
137134 NotConstEvaluatable::MentionsParam
138135 } else {
139136 let guar = infcx.dcx().span_delayed_bug(
compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs+2-6
......@@ -886,13 +886,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
886886 let ct = self.tcx.expand_abstract_consts(ct);
887887
888888 match ct.kind() {
889 ty::ConstKind::Unevaluated(
889 ty::ConstKind::Alias(
890890 _,
891 ty::UnevaluatedConst {
892 kind: ty::UnevaluatedConstKind::Projection { def_id },
893 args,
894 ..
895 },
891 ty::AliasConst { kind: ty::AliasConstKind::Projection { def_id }, args, .. },
896892 ) if self.tcx.features().min_generic_const_args() => {
897893 match self.allow_self_projections {
898894 AllowSelfProjections::Yes => {
compiler/rustc_trait_selection/src/traits/fulfill.rs+18-17
......@@ -559,7 +559,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
559559 return ProcessResult::Changed(PendingPredicateObligations::new());
560560 }
561561 ty::ConstKind::Value(cv) => cv.ty,
562 ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(),
562 ty::ConstKind::Alias(_, alias_const) => {
563 alias_const.type_of(infcx.tcx).skip_norm_wip()
564 }
563565 // FIXME(generic_const_exprs): we should construct an alias like
564566 // `<lhs_ty as Add<rhs_ty>>::Output` when this is an `Expr` representing
565567 // `lhs + rhs`.
......@@ -677,10 +679,10 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
677679 }
678680 }
679681
680 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
682 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
681683 match const_evaluatable::is_const_evaluatable(
682684 self.selcx.infcx,
683 uv,
685 alias_const,
684686 obligation.param_env,
685687 obligation.cause.span,
686688 ) {
......@@ -688,7 +690,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
688690 Err(NotConstEvaluatable::MentionsInfer) => {
689691 pending_obligation.stalled_on.clear();
690692 pending_obligation.stalled_on.extend(
691 uv.walk().filter_map(TyOrConstInferVar::maybe_from_generic_arg),
693 alias_const
694 .walk()
695 .filter_map(TyOrConstInferVar::maybe_from_generic_arg),
692696 );
693697 ProcessResult::Unchanged
694698 }
......@@ -717,15 +721,13 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
717721 debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2);
718722
719723 match (c1.kind(), c2.kind()) {
720 (
721 ty::ConstKind::Unevaluated(_, a),
722 ty::ConstKind::Unevaluated(_, b),
723 ) if a.kind == b.kind
724 && matches!(
725 a.kind,
726 ty::UnevaluatedConstKind::Projection { .. }
727 | ty::UnevaluatedConstKind::Inherent { .. }
728 ) =>
724 (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b))
725 if a.kind == b.kind
726 && matches!(
727 a.kind,
728 ty::AliasConstKind::Projection { .. }
729 | ty::AliasConstKind::Inherent { .. }
730 ) =>
729731 {
730732 if let Ok(new_obligations) = infcx
731733 .at(&obligation.cause, obligation.param_env)
......@@ -743,8 +745,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
743745 ));
744746 }
745747 }
746 (_, ty::ConstKind::Unevaluated(_, _))
747 | (ty::ConstKind::Unevaluated(_, _), _) => (),
748 (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (),
748749 (_, _) => {
749750 if let Ok(new_obligations) = infcx
750751 .at(&obligation.cause, obligation.param_env)
......@@ -764,7 +765,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
764765 let stalled_on = &mut pending_obligation.stalled_on;
765766
766767 let mut evaluate = |c: Const<'tcx>| {
767 if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() {
768 if let ty::ConstKind::Alias(_, alias_const) = c.kind() {
768769 match super::try_evaluate_const(
769770 self.selcx.infcx,
770771 c,
......@@ -773,7 +774,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
773774 Ok(val) => Ok(val),
774775 e @ Err(EvaluateConstErr::HasGenericsOrInfers) => {
775776 stalled_on.extend(
776 unevaluated
777 alias_const
777778 .args
778779 .iter()
779780 .filter_map(TyOrConstInferVar::maybe_from_generic_arg),
compiler/rustc_trait_selection/src/traits/mod.rs+30-28
......@@ -369,8 +369,8 @@ pub fn normalize_param_env_or_error<'tcx>(
369369 // should actually be okay since without `feature(generic_const_exprs)` the only
370370 // const arguments that have a non-empty param env are array repeat counts. These
371371 // do not appear in the type system though.
372 if let ty::ConstKind::Unevaluated(_, uv) = c.kind()
373 && matches!(uv.kind, ty::UnevaluatedConstKind::Anon { .. })
372 if let ty::ConstKind::Alias(_, alias_const) = c.kind()
373 && matches!(alias_const.kind, ty::AliasConstKind::Anon { .. })
374374 {
375375 let infcx = self.0.infer_ctxt().build(TypingMode::non_body_analysis());
376376 let c = evaluate_const(&infcx, c, ty::ParamEnv::empty());
......@@ -401,10 +401,10 @@ pub fn normalize_param_env_or_error<'tcx>(
401401 // we cannot prove `T: Trait<u8>`.
402402 //
403403 // The same thing is true for const generics- attempting to prove
404 // `T: Trait<ConstKind::Unevaluated(...)>` with the same thing as a where clauses
404 // `T: Trait<ConstKind::Alias(...)>` with the same thing as a where clauses
405405 // will fail. After normalization we may be attempting to prove `T: Trait<4>` with
406 // the unnormalized where clause `T: Trait<ConstKind::Unevaluated(...)>`. In order
407 // for the obligation to hold `4` must be equal to `ConstKind::Unevaluated(...)`
406 // the unnormalized where clause `T: Trait<ConstKind::Alias(...)>`. In order
407 // for the obligation to hold `4` must be equal to `ConstKind::Alias(...)`
408408 // but as we do not have lazy norm implemented, equating the two consts fails outright.
409409 //
410410 // Ideally we would not normalize consts here at all but it is required for backwards
......@@ -547,7 +547,7 @@ pub fn deeply_normalize_param_env_ignoring_regions<'tcx>(
547547#[derive(Debug)]
548548pub enum EvaluateConstErr {
549549 /// The constant being evaluated was either a generic parameter or inference variable, *or*,
550 /// some unevaluated constant with either generic parameters or inference variables in its
550 /// some alias const with either generic parameters or inference variables in its
551551 /// generic arguments.
552552 HasGenericsOrInfers,
553553 /// The type this constant evaluated to is not valid for use in const generics. This should
......@@ -560,7 +560,7 @@ pub enum EvaluateConstErr {
560560}
561561
562562// FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine
563// FIXME(generic_const_exprs): Consider accepting a `ty::UnevaluatedConst` when we are not rolling our own
563// FIXME(generic_const_exprs): Consider accepting a `ty::AliasConst` when we are not rolling our own
564564// normalization scheme
565565/// Evaluates a type system constant returning a `ConstKind::Error` in cases where CTFE failed and
566566/// returning the passed in constant if it was not fully concrete (i.e. depended on generic parameters
......@@ -583,7 +583,7 @@ pub fn evaluate_const<'tcx>(
583583}
584584
585585// FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine
586// FIXME(generic_const_exprs): Consider accepting a `ty::UnevaluatedConst` when we are not rolling our own
586// FIXME(generic_const_exprs): Consider accepting a `ty::AliasConst` when we are not rolling our own
587587// normalization scheme
588588/// Evaluates a type system constant making sure to not allow constants that depend on generic parameters
589589/// or inference variables to succeed in evaluating.
......@@ -608,11 +608,9 @@ pub fn try_evaluate_const<'tcx>(
608608 | ty::ConstKind::Bound(_, _)
609609 | ty::ConstKind::Placeholder(_)
610610 | ty::ConstKind::Expr(_) => Err(EvaluateConstErr::HasGenericsOrInfers),
611 ty::ConstKind::Unevaluated(_, uv) => {
612 let opt_anon_const_kind = match uv.kind {
613 ty::UnevaluatedConstKind::Anon { def_id } => {
614 Some((def_id, tcx.anon_const_kind(def_id)))
615 }
611 ty::ConstKind::Alias(_, alias_const) => {
612 let opt_anon_const_kind = match alias_const.kind {
613 ty::AliasConstKind::Anon { def_id } => Some((def_id, tcx.anon_const_kind(def_id))),
616614 _ => None,
617615 };
618616
......@@ -632,14 +630,14 @@ pub fn try_evaluate_const<'tcx>(
632630 // completely fall apart under `generic_const_exprs` and makes this whole function Really hard to reason
633631 // about if you have to consider gce whatsoever.
634632 Some((def_id, ty::AnonConstKind::GCE)) => {
635 if uv.has_non_region_infer() || uv.has_non_region_param() {
633 if alias_const.has_non_region_infer() || alias_const.has_non_region_param() {
636634 // `feature(generic_const_exprs)` causes anon consts to inherit all parent generics. This can cause
637635 // inference variables and generic parameters to show up in `ty::Const` even though the anon const
638636 // does not actually make use of them. We handle this case specially and attempt to evaluate anyway.
639637 match tcx.thir_abstract_const(def_id) {
640638 Ok(Some(ct)) => {
641639 let ct = tcx.expand_abstract_consts(
642 ct.instantiate(tcx, uv.args).skip_norm_wip(),
640 ct.instantiate(tcx, alias_const.args).skip_norm_wip(),
643641 );
644642 if let Err(e) = ct.error_reported() {
645643 return Err(EvaluateConstErr::EvaluationFailure(e));
......@@ -648,8 +646,10 @@ pub fn try_evaluate_const<'tcx>(
648646 // the generic arguments provided for it, then we should *not* attempt to evaluate it.
649647 return Err(EvaluateConstErr::HasGenericsOrInfers);
650648 } else {
651 let args =
652 replace_param_and_infer_args_with_placeholder(tcx, uv.args);
649 let args = replace_param_and_infer_args_with_placeholder(
650 tcx,
651 alias_const.args,
652 );
653653 let typing_env = infcx
654654 .typing_env(tcx.erase_and_anonymize_regions(param_env))
655655 .with_post_analysis_normalized(tcx);
......@@ -666,11 +666,11 @@ pub fn try_evaluate_const<'tcx>(
666666 let typing_env = infcx
667667 .typing_env(tcx.erase_and_anonymize_regions(param_env))
668668 .with_post_analysis_normalized(tcx);
669 (uv.args, typing_env)
669 (alias_const.args, typing_env)
670670 }
671671 }
672672 Some((def_id, ty::AnonConstKind::RepeatExprCount)) => {
673 if uv.has_non_region_infer() {
673 if alias_const.has_non_region_infer() {
674674 // Diagnostics will sometimes replace the identity args of anon consts in
675675 // array repeat expr counts with inference variables so we have to handle this
676676 // even though it is not something we should ever actually encounter.
......@@ -706,9 +706,9 @@ pub fn try_evaluate_const<'tcx>(
706706 // logic does not go through type system normalization. If it did this would
707707 // be a backwards compatibility problem as we do not enforce "syntactic" non-
708708 // usage of generic parameters like we do here.
709 if uv.args.has_non_region_param()
710 || uv.args.has_non_region_infer()
711 || uv.args.has_non_region_placeholders()
709 if alias_const.args.has_non_region_param()
710 || alias_const.args.has_non_region_infer()
711 || alias_const.args.has_non_region_placeholders()
712712 {
713713 return Err(EvaluateConstErr::HasGenericsOrInfers);
714714 }
......@@ -717,19 +717,21 @@ pub fn try_evaluate_const<'tcx>(
717717 // to prevent query cycle.
718718 let typing_env = ty::TypingEnv::fully_monomorphized();
719719
720 (uv.args, typing_env)
720 (alias_const.args, typing_env)
721721 }
722722 };
723723
724 let uv = ty::UnevaluatedConst::new(tcx, uv.kind, args);
725 let erased_uv = tcx.erase_and_anonymize_regions(uv);
724 let alias_const = ty::AliasConst::new(tcx, alias_const.kind, args);
725 let erased_alias_const = tcx.erase_and_anonymize_regions(alias_const);
726726
727727 use rustc_middle::mir::interpret::ErrorHandled;
728728 // FIXME: `def_span` will point at the definition of this const; ideally, we'd point at
729729 // where it gets used as a const generic.
730 let span = uv.kind.def_span(tcx);
731 match tcx.const_eval_resolve_for_typeck(typing_env, erased_uv, span) {
732 Ok(Ok(val)) => Ok(ty::Const::new_value(tcx, val, uv.type_of(tcx).skip_norm_wip())),
730 let span = alias_const.kind.def_span(tcx);
731 match tcx.const_eval_resolve_for_typeck(typing_env, erased_alias_const, span) {
732 Ok(Ok(val)) => {
733 Ok(ty::Const::new_value(tcx, val, alias_const.type_of(tcx).skip_norm_wip()))
734 }
733735 Ok(Err(_)) => {
734736 let e = tcx.dcx().delayed_bug(
735737 "Type system constant with non valtree'able type evaluated but no error emitted",
compiler/rustc_trait_selection/src/traits/normalize.rs+12-12
......@@ -469,14 +469,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
469469
470470 if tcx.features().generic_const_exprs()
471471 // Normalize type_const items even with feature `generic_const_exprs`.
472 && !matches!(ct.kind(), ty::ConstKind::Unevaluated(_, uv) if uv.kind.is_type_const(tcx))
472 && !matches!(ct.kind(), ty::ConstKind::Alias(_, alias_const) if alias_const.kind.is_type_const(tcx))
473473 || !needs_normalization(self.selcx.infcx, &ct)
474474 {
475475 return ct;
476476 }
477477
478 let uv = match ct.kind() {
479 ty::ConstKind::Unevaluated(_, uv) => uv,
478 let alias_const = match ct.kind() {
479 ty::ConstKind::Alias(_, alias_const) => alias_const,
480480 _ => return ct.super_fold_with(self),
481481 };
482482
......@@ -484,20 +484,20 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
484484 // unless a `min_generic_const_args` feature gate error has already
485485 // been emitted earlier in compilation.
486486 //
487 // That's because we can only end up with an Unevaluated ty::Const for a const item
487 // That's because we can only end up with an Alias ty::Const for a const item
488488 // if it was marked with `type const`. Using this attribute without the mgca
489489 // feature gate causes a parse error.
490 let ct = match uv.kind {
491 ty::UnevaluatedConstKind::Projection { .. } => {
492 self.normalize_trait_projection(uv.into()).expect_const()
490 let ct = match alias_const.kind {
491 ty::AliasConstKind::Projection { .. } => {
492 self.normalize_trait_projection(alias_const.into()).expect_const()
493493 }
494 ty::UnevaluatedConstKind::Inherent { .. } => {
495 self.normalize_inherent_projection(uv.into()).expect_const()
494 ty::AliasConstKind::Inherent { .. } => {
495 self.normalize_inherent_projection(alias_const.into()).expect_const()
496496 }
497 ty::UnevaluatedConstKind::Free { .. } => {
498 self.normalize_free_alias(uv.into()).expect_const()
497 ty::AliasConstKind::Free { .. } => {
498 self.normalize_free_alias(alias_const.into()).expect_const()
499499 }
500 ty::UnevaluatedConstKind::Anon { .. } => {
500 ty::AliasConstKind::Anon { .. } => {
501501 let ct = ct.super_fold_with(self);
502502 super::with_replaced_escaping_bound_vars(
503503 self.selcx.infcx,
compiler/rustc_trait_selection/src/traits/query/normalize.rs+12-14
......@@ -272,21 +272,19 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
272272 return Ok(constant);
273273 }
274274
275 let uv = match constant.kind() {
276 ty::ConstKind::Unevaluated(_, uv) => uv,
275 let alias_const = match constant.kind() {
276 ty::ConstKind::Alias(_, alias_const) => alias_const,
277277 _ => return constant.try_super_fold_with(self),
278278 };
279279
280 let constant = match uv.kind {
281 ty::UnevaluatedConstKind::Anon { .. } => {
282 crate::traits::with_replaced_escaping_bound_vars(
283 self.infcx,
284 &mut self.universes,
285 constant,
286 |constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env),
287 )
288 }
289 _ => self.try_fold_free_or_assoc(uv.into())?.expect_const(),
280 let constant = match alias_const.kind {
281 ty::AliasConstKind::Anon { .. } => crate::traits::with_replaced_escaping_bound_vars(
282 self.infcx,
283 &mut self.universes,
284 constant,
285 |constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env),
286 ),
287 _ => self.try_fold_free_or_assoc(alias_const.into())?.expect_const(),
290288 };
291289 debug!(?constant, ?self.param_env);
292290 constant.try_super_fold_with(self)
......@@ -373,10 +371,10 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> {
373371 result.normalized_term
374372 };
375373 // `tcx.normalize_canonicalized_projection` may normalize to a type that
376 // still has unevaluated consts, so keep normalizing here if that's the case.
374 // still has alias consts, so keep normalizing here if that's the case.
377375 // Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer
378376 // of type/const and we need to continue folding it to reveal the TAIT behind it
379 // or further normalize nested unevaluated consts.
377 // or further normalize nested alias consts.
380378 if res != term.to_term(tcx, ty::IsRigid::No)
381379 && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
382380 || matches!(
compiler/rustc_trait_selection/src/traits/select/mod.rs+14-15
......@@ -852,10 +852,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
852852 }
853853 }
854854
855 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
855 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
856856 match const_evaluatable::is_const_evaluatable(
857857 self.infcx,
858 uv,
858 alias_const,
859859 obligation.param_env,
860860 obligation.cause.span,
861861 ) {
......@@ -882,15 +882,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
882882 );
883883
884884 match (c1.kind(), c2.kind()) {
885 (
886 ty::ConstKind::Unevaluated(_, a),
887 ty::ConstKind::Unevaluated(_, b),
888 ) if a.kind == b.kind
889 && matches!(
890 a.kind,
891 ty::UnevaluatedConstKind::Projection { .. }
892 | ty::UnevaluatedConstKind::Inherent { .. }
893 ) =>
885 (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b))
886 if a.kind == b.kind
887 && matches!(
888 a.kind,
889 ty::AliasConstKind::Projection { .. }
890 | ty::AliasConstKind::Inherent { .. }
891 ) =>
894892 {
895893 if let Ok(InferOk { obligations, value: () }) = self
896894 .infcx
......@@ -909,8 +907,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
909907 );
910908 }
911909 }
912 (_, ty::ConstKind::Unevaluated(_, _))
913 | (ty::ConstKind::Unevaluated(_, _), _) => (),
910 (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (),
914911 (_, _) => {
915912 if let Ok(InferOk { obligations, value: () }) = self
916913 .infcx
......@@ -929,7 +926,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
929926 }
930927
931928 let evaluate = |c: ty::Const<'tcx>| {
932 if let ty::ConstKind::Unevaluated(_, _) = c.kind() {
929 if let ty::ConstKind::Alias(_, _) = c.kind() {
933930 match crate::traits::try_evaluate_const(
934931 self.infcx,
935932 c,
......@@ -989,7 +986,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
989986 }
990987 ty::ConstKind::Error(_) => return Ok(EvaluatedToOk),
991988 ty::ConstKind::Value(cv) => cv.ty,
992 ty::ConstKind::Unevaluated(_, uv) => uv.type_of(self.tcx()).skip_norm_wip(),
989 ty::ConstKind::Alias(_, alias_const) => {
990 alias_const.type_of(self.tcx()).skip_norm_wip()
991 }
993992 // FIXME(generic_const_exprs): See comment in `fulfill.rs`
994993 ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk),
995994 ty::ConstKind::Placeholder(_) => {
compiler/rustc_trait_selection/src/traits/wf.rs+11-10
......@@ -1064,10 +1064,11 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
10641064 let tcx = self.tcx();
10651065
10661066 match c.kind() {
1067 ty::ConstKind::Unevaluated(_, uv) => {
1067 ty::ConstKind::Alias(_, alias_const) => {
10681068 if !c.has_escaping_bound_vars() {
10691069 // Skip type consts as mGCA doesn't support evaluatable clauses
1070 if !uv.kind.is_type_const(tcx) && !tcx.features().generic_const_args() {
1070 if !alias_const.kind.is_type_const(tcx) && !tcx.features().generic_const_args()
1071 {
10711072 let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
10721073 ty::ClauseKind::ConstEvaluatable(c),
10731074 ));
......@@ -1081,15 +1082,15 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
10811082 ));
10821083 }
10831084
1084 match uv.kind {
1085 ty::UnevaluatedConstKind::Inherent { .. } => {
1086 self.add_wf_preds_for_inherent_projection(uv.into());
1085 match alias_const.kind {
1086 ty::AliasConstKind::Inherent { .. } => {
1087 self.add_wf_preds_for_inherent_projection(alias_const.into());
10871088 return; // Subtree is handled by above function
10881089 }
1089 ty::UnevaluatedConstKind::Projection { def_id }
1090 | ty::UnevaluatedConstKind::Free { def_id }
1091 | ty::UnevaluatedConstKind::Anon { def_id } => {
1092 let obligations = self.nominal_obligations(def_id, uv.args);
1090 ty::AliasConstKind::Projection { def_id }
1091 | ty::AliasConstKind::Free { def_id }
1092 | ty::AliasConstKind::Anon { def_id } => {
1093 let obligations = self.nominal_obligations(def_id, alias_const.args);
10931094 self.out.extend(obligations);
10941095 }
10951096 }
......@@ -1111,7 +1112,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
11111112 ty::ConstKind::Expr(_) => {
11121113 // FIXME(generic_const_exprs): this doesn't verify that given `Expr(N + 1)` the
11131114 // trait bound `typeof(N): Add<typeof(1)>` holds. This is currently unnecessary
1114 // as `ConstKind::Expr` is only produced via normalization of `ConstKind::Unevaluated`
1115 // as `ConstKind::Expr` is only produced via normalization of `ConstKind::Alias`
11151116 // which means that the `DefId` would have been typeck'd elsewhere. However in
11161117 // the future we may allow directly lowering to `ConstKind::Expr` in which case
11171118 // we would not be proving bounds we should.
compiler/rustc_ty_utils/src/consts.rs+3-6
......@@ -70,12 +70,9 @@ fn recurse_build<'tcx>(
7070 }
7171 &ExprKind::ZstLiteral { user_ty: _ } => ty::Const::zero_sized(tcx, node.ty),
7272 &ExprKind::NamedConst { def_id, args, user_ty: _ } => {
73 let uneval = ty::UnevaluatedConst::new(
74 tcx,
75 ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id),
76 args,
77 );
78 ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval)
73 let uneval =
74 ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, def_id), args);
75 ty::Const::new_alias(tcx, ty::IsRigid::No, uneval)
7976 }
8077 ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param),
8178
compiler/rustc_ty_utils/src/layout.rs+1-1
......@@ -177,7 +177,7 @@ fn extract_const_value<'tcx>(
177177 }
178178 Err(error(cx, LayoutError::TooGeneric(ty)))
179179 }
180 ty::ConstKind::Unevaluated(_, _) => {
180 ty::ConstKind::Alias(_, _) => {
181181 let err = if ct.has_param() {
182182 LayoutError::TooGeneric(ty)
183183 } else {
compiler/rustc_type_ir/src/const_kind.rs+35-37
......@@ -9,7 +9,7 @@ use rustc_type_ir_macros::{
99 GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
1010};
1111
12use crate::{self as ty, BoundVarIndexKind, Interner, UnevaluatedConst};
12use crate::{self as ty, AliasConst, BoundVarIndexKind, Interner};
1313
1414/// Represents a constant in Rust.
1515#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
......@@ -34,7 +34,7 @@ pub enum ConstKind<I: Interner> {
3434 /// An unnormalized const item such as an anon const or assoc const or free const item.
3535 /// Right now anything other than anon consts does not actually work properly but this
3636 /// should
37 Unevaluated(ty::IsRigid, ty::UnevaluatedConst<I>),
37 Alias(ty::IsRigid, ty::AliasConst<I>),
3838
3939 /// Used to hold computed value.
4040 Value(I::ValueConst),
......@@ -43,7 +43,7 @@ pub enum ConstKind<I: Interner> {
4343 /// propagated to avoid useless error messages.
4444 Error(I::ErrorGuaranteed),
4545
46 /// Unevaluated non-const-item, used by `feature(generic_const_exprs)` to represent
46 /// A non-const-item expression awaiting evaluation, used by `feature(generic_const_exprs)` to represent
4747 /// const arguments such as `N + 1` or `foo(N)`
4848 Expr(I::ExprConst),
4949}
......@@ -59,7 +59,9 @@ impl<I: Interner> fmt::Debug for ConstKind<I> {
5959 Infer(var) => write!(f, "{var:?}"),
6060 Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var),
6161 Placeholder(placeholder) => write!(f, "{placeholder:?}"),
62 Unevaluated(is_rigid, uv) => write!(f, "Unevaluated({is_rigid:?}, {uv:?})"),
62 Alias(is_rigid, alias_const) => {
63 write!(f, "AliasConst({is_rigid:?}, {alias_const:?})")
64 }
6365 Value(val) => write!(f, "{val:?}"),
6466 Error(_) => write!(f, "{{const error}}"),
6567 Expr(expr) => write!(f, "{expr:?}"),
......@@ -67,46 +69,42 @@ impl<I: Interner> fmt::Debug for ConstKind<I> {
6769 }
6870}
6971
70impl<I: Interner> UnevaluatedConst<I> {
72impl<I: Interner> AliasConst<I> {
7173 #[inline]
72 pub fn new(
73 interner: I,
74 kind: UnevaluatedConstKind<I>,
75 args: I::GenericArgs,
76 ) -> UnevaluatedConst<I> {
74 pub fn new(interner: I, kind: AliasConstKind<I>, args: I::GenericArgs) -> AliasConst<I> {
7775 if cfg!(debug_assertions) {
7876 let def_id = match kind {
79 ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(),
80 ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(),
81 ty::UnevaluatedConstKind::Free { def_id } => def_id.into(),
82 ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(),
77 ty::AliasConstKind::Projection { def_id } => def_id.into(),
78 ty::AliasConstKind::Inherent { def_id } => def_id.into(),
79 ty::AliasConstKind::Free { def_id } => def_id.into(),
80 ty::AliasConstKind::Anon { def_id } => def_id.into(),
8381 };
8482 interner.debug_assert_args_compatible(def_id, args);
8583 }
86 UnevaluatedConst { kind, args, _use_alias_new_instead: () }
84 AliasConst { kind, args, _use_alias_new_instead: () }
8785 }
8886
8987 pub fn type_of(self, interner: I) -> ty::Unnormalized<I, I::Ty> {
9088 let def_id = match self.kind {
91 ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(),
92 ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(),
93 ty::UnevaluatedConstKind::Free { def_id } => def_id.into(),
94 ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(),
89 ty::AliasConstKind::Projection { def_id } => def_id.into(),
90 ty::AliasConstKind::Inherent { def_id } => def_id.into(),
91 ty::AliasConstKind::Free { def_id } => def_id.into(),
92 ty::AliasConstKind::Anon { def_id } => def_id.into(),
9593 };
9694 interner.type_of(def_id).instantiate(interner, self.args)
9795 }
9896}
9997
100/// UnevaluatedConstKind is extremely similar to AliasTyKind, and likely should be reasoned about
98/// AliasConstKind is extremely similar to AliasTyKind, and likely should be reasoned about
10199/// and handled in very similar ways. The documentation for AliasTyKind/etc. may be helpful when
102/// learning about UnevaluatedConstKind.
100/// learning about AliasConstKind.
103101#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
104102#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)]
105103#[cfg_attr(
106104 feature = "nightly",
107105 derive(Encodable_NoContext, Decodable_NoContext, StableHash_NoContext)
108106)]
109pub enum UnevaluatedConstKind<I: Interner> {
107pub enum AliasConstKind<I: Interner> {
110108 /// A projection `<Type as Trait>::AssocConst`
111109 Projection { def_id: I::TraitAssocConstId },
112110 /// An associated constant in an inherent `impl`
......@@ -114,38 +112,38 @@ pub enum UnevaluatedConstKind<I: Interner> {
114112 /// A free constant, outside an impl block.
115113 Free { def_id: I::FreeConstAliasId },
116114 /// Anonymous constant, e.g. the `1 + 2` in `[u8; 1 + 2]`.
117 Anon { def_id: I::UnevaluatedConstId },
115 Anon { def_id: I::AnonConstId },
118116}
119117
120impl<I: Interner> UnevaluatedConstKind<I> {
118impl<I: Interner> AliasConstKind<I> {
121119 pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self {
122 interner.unevaluated_const_kind_from_def_id(def_id)
120 interner.alias_const_kind_from_def_id(def_id)
123121 }
124122
125123 pub fn is_type_const(self, interner: I) -> bool {
126124 match self {
127 UnevaluatedConstKind::Projection { def_id } => interner.is_type_const(def_id.into()),
128 UnevaluatedConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()),
129 UnevaluatedConstKind::Free { def_id } => interner.is_type_const(def_id.into()),
130 UnevaluatedConstKind::Anon { def_id } => interner.is_type_const(def_id.into()),
125 AliasConstKind::Projection { def_id } => interner.is_type_const(def_id.into()),
126 AliasConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()),
127 AliasConstKind::Free { def_id } => interner.is_type_const(def_id.into()),
128 AliasConstKind::Anon { def_id } => interner.is_type_const(def_id.into()),
131129 }
132130 }
133131
134132 pub fn def_span(self, interner: I) -> I::Span {
135133 match self {
136 UnevaluatedConstKind::Projection { def_id } => interner.def_span(def_id.into()),
137 UnevaluatedConstKind::Inherent { def_id } => interner.def_span(def_id.into()),
138 UnevaluatedConstKind::Free { def_id } => interner.def_span(def_id.into()),
139 UnevaluatedConstKind::Anon { def_id } => interner.def_span(def_id.into()),
134 AliasConstKind::Projection { def_id } => interner.def_span(def_id.into()),
135 AliasConstKind::Inherent { def_id } => interner.def_span(def_id.into()),
136 AliasConstKind::Free { def_id } => interner.def_span(def_id.into()),
137 AliasConstKind::Anon { def_id } => interner.def_span(def_id.into()),
140138 }
141139 }
142140
143141 pub fn opt_def_id(self) -> Option<I::DefId> {
144142 match self {
145 UnevaluatedConstKind::Projection { def_id } => Some(def_id.into()),
146 UnevaluatedConstKind::Inherent { def_id } => Some(def_id.into()),
147 UnevaluatedConstKind::Free { def_id } => Some(def_id.into()),
148 UnevaluatedConstKind::Anon { def_id } => Some(def_id.into()),
143 AliasConstKind::Projection { def_id } => Some(def_id.into()),
144 AliasConstKind::Inherent { def_id } => Some(def_id.into()),
145 AliasConstKind::Free { def_id } => Some(def_id.into()),
146 AliasConstKind::Anon { def_id } => Some(def_id.into()),
149147 }
150148 }
151149}
compiler/rustc_type_ir/src/fast_reject.rs+2-4
......@@ -478,7 +478,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
478478 }
479479
480480 ty::ConstKind::Expr(_)
481 | ty::ConstKind::Unevaluated(_, _)
481 | ty::ConstKind::Alias(_, _)
482482 | ty::ConstKind::Error(_)
483483 | ty::ConstKind::Infer(_)
484484 | ty::ConstKind::Bound(..) => {
......@@ -509,9 +509,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
509509
510510 // As we don't necessarily eagerly evaluate constants,
511511 // they might unify with any value.
512 ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Error(_) => {
513 true
514 }
512 ty::ConstKind::Expr(_) | ty::ConstKind::Alias(_, _) | ty::ConstKind::Error(_) => true,
515513
516514 ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) => true,
517515 }
compiler/rustc_type_ir/src/flags.rs+6-6
......@@ -79,10 +79,10 @@ bitflags::bitflags! {
7979 const HAS_TY_OPAQUE = 1 << 12;
8080 /// Does this have `Inherent`?
8181 const HAS_TY_INHERENT = 1 << 13;
82 /// Does this have `ConstKind::Unevaluated`?
82 /// Does this have `ConstKind::Alias`?
8383 const HAS_CT_PROJECTION = 1 << 14;
8484
85 /// Does this have `Alias` or `ConstKind::Unevaluated`?
85 /// Does this have `Alias` or `ConstKind::Alias`?
8686 ///
8787 /// Rephrased, could this term be normalized further?
8888 const HAS_ALIAS = TypeFlags::HAS_TY_PROJECTION.bits()
......@@ -432,8 +432,8 @@ impl<I: Interner> FlagComputation<I> {
432432 self.add_term(term);
433433 }
434434 ty::PredicateKind::DynCompatible(_def_id) => {}
435 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
436 self.add_const(uv);
435 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => {
436 self.add_const(alias_const);
437437 }
438438 ty::PredicateKind::ConstEquate(expected, found) => {
439439 self.add_const(expected);
......@@ -477,9 +477,9 @@ impl<I: Interner> FlagComputation<I> {
477477
478478 fn add_const_kind(&mut self, c: &ty::ConstKind<I>) {
479479 match *c {
480 ty::ConstKind::Unevaluated(is_rigid, uv) => {
480 ty::ConstKind::Alias(is_rigid, alias_const) => {
481481 self.add_is_rigid(is_rigid);
482 self.add_args(uv.args.as_slice());
482 self.add_args(alias_const.args.as_slice());
483483 self.add_flags(TypeFlags::HAS_CT_PROJECTION);
484484 }
485485 ty::ConstKind::Infer(infer) => match infer {
compiler/rustc_type_ir/src/fold.rs+3-3
......@@ -601,9 +601,9 @@ impl<I: Interner> TypeFolder<I> for RigidnessFolder<I> {
601601 }
602602
603603 match c.kind() {
604 ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => {
605 let uv = uv.fold_with(self);
606 I::Const::new_unevaluated(self.cx, ty::IsRigid::No, uv)
604 ty::ConstKind::Alias(ty::IsRigid::Yes, alias_const) => {
605 let alias_const = alias_const.fold_with(self);
606 I::Const::new_alias(self.cx, ty::IsRigid::No, alias_const)
607607 }
608608 _ => c.super_fold_with(self),
609609 }
compiler/rustc_type_ir/src/inherent.rs+3-3
......@@ -280,7 +280,7 @@ pub trait Const<I: Interner<Const = Self>>:
280280
281281 fn new_placeholder(interner: I, param: ty::PlaceholderConst<I>) -> Self;
282282
283 fn new_unevaluated(interner: I, is_rigid: ty::IsRigid, uv: ty::UnevaluatedConst<I>) -> Self;
283 fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_const: ty::AliasConst<I>) -> Self;
284284
285285 fn new_expr(interner: I, expr: I::ExprConst) -> Self;
286286
......@@ -411,7 +411,7 @@ pub trait Term<I: Interner<Term = Self>>:
411411 _ => None,
412412 },
413413 ty::TermKind::Const(ct) => match ct.kind() {
414 ty::ConstKind::Unevaluated(_, uv) => Some(uv.into()),
414 ty::ConstKind::Alias(_, alias_const) => Some(alias_const.into()),
415415 _ => None,
416416 },
417417 }
......@@ -424,7 +424,7 @@ pub trait Term<I: Interner<Term = Self>>:
424424 _ => false,
425425 },
426426 ty::TermKind::Const(ct) => match ct.kind() {
427 ty::ConstKind::Unevaluated(is_rigid, _) => is_rigid == ty::IsRigid::No,
427 ty::ConstKind::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No,
428428 _ => false,
429429 },
430430 }
compiler/rustc_type_ir/src/interner.rs+6-16
......@@ -56,13 +56,12 @@ pub trait Interner:
5656 type CoroutineId: SpecificDefId<Self>;
5757 type AdtId: SpecificDefId<Self>;
5858 type ImplId: SpecificDefId<Self>;
59 type UnevaluatedConstId: SpecificDefId<Self>;
59 type AnonConstId: SpecificDefId<Self>;
6060 type TraitAssocTyId: SpecificDefId<Self>
6161 + Into<Self::TraitAssocTermId>
6262 + TryFrom<Self::TraitAssocTermId>;
6363 type TraitAssocConstId: SpecificDefId<Self>
6464 + Into<Self::TraitAssocTermId>
65 + Into<Self::UnevaluatedConstId>
6665 + TryFrom<Self::TraitAssocTermId>;
6766 type TraitAssocTermId: SpecificDefId<Self>;
6867 type OpaqueTyId: SpecificDefId<Self, Self::LocalOpaqueTyId>;
......@@ -75,19 +74,13 @@ pub trait Interner:
7574 + Into<Self::DefId>
7675 + TypeFoldable<Self>;
7776 type FreeTyAliasId: SpecificDefId<Self> + Into<Self::FreeTermAliasId>;
78 type FreeConstAliasId: SpecificDefId<Self>
79 + Into<Self::UnevaluatedConstId>
80 + Into<Self::FreeTermAliasId>;
77 type FreeConstAliasId: SpecificDefId<Self> + Into<Self::FreeTermAliasId>;
8178 type FreeTermAliasId: SpecificDefId<Self>;
8279 type ImplOrTraitAssocTyId: SpecificDefId<Self> + Into<Self::ImplOrTraitAssocTermId>;
83 type ImplOrTraitAssocConstId: SpecificDefId<Self>
84 + Into<Self::UnevaluatedConstId>
85 + Into<Self::ImplOrTraitAssocTermId>;
80 type ImplOrTraitAssocConstId: SpecificDefId<Self> + Into<Self::ImplOrTraitAssocTermId>;
8681 type ImplOrTraitAssocTermId: SpecificDefId<Self>;
8782 type InherentAssocTyId: SpecificDefId<Self> + Into<Self::InherentAssocTermId>;
88 type InherentAssocConstId: SpecificDefId<Self>
89 + Into<Self::UnevaluatedConstId>
90 + Into<Self::InherentAssocTermId>;
83 type InherentAssocConstId: SpecificDefId<Self> + Into<Self::InherentAssocTermId>;
9184 type InherentAssocTermId: SpecificDefId<Self>;
9285 type Span: Span<Self>;
9386
......@@ -244,10 +237,7 @@ pub trait Interner:
244237 type AdtDef: AdtDef<Self>;
245238 fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef;
246239
247 fn unevaluated_const_kind_from_def_id(
248 self,
249 def_id: Self::DefId,
250 ) -> ty::UnevaluatedConstKind<Self>;
240 fn alias_const_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasConstKind<Self>;
251241
252242 // FIXME: remove in favor of explicit construction
253243 fn alias_term_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTermKind<Self>;
......@@ -519,7 +509,7 @@ declare_lift_into! {
519509 TraitId,
520510 Ty,
521511 Tys,
522 UnevaluatedConstId,
512 AnonConstId,
523513}
524514
525515/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`
compiler/rustc_type_ir/src/ir_print.rs+3-3
......@@ -1,12 +1,12 @@
11use std::fmt;
22
3#[cfg(feature = "nightly")]
4use crate::{AliasConst, ClosureKind};
35use crate::{
46 AliasTerm, AliasTy, Binder, CoercePredicate, ExistentialProjection, ExistentialTraitRef, FnSig,
57 HostEffectPredicate, Interner, NormalizesTo, OutlivesPredicate, PatternKind, Placeholder,
68 ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef,
79};
8#[cfg(feature = "nightly")]
9use crate::{ClosureKind, UnevaluatedConst};
1010
1111pub trait IrPrint<T> {
1212 fn print(t: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
......@@ -100,7 +100,7 @@ mod into_diag_arg_impls {
100100 }
101101 }
102102
103 impl<I: Interner> IntoDiagArg for UnevaluatedConst<I> {
103 impl<I: Interner> IntoDiagArg for AliasConst<I> {
104104 fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> DiagArgValue {
105105 format!("{self:?}").into_diag_arg(path)
106106 }
compiler/rustc_type_ir/src/relate.rs+10-13
......@@ -231,17 +231,17 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> {
231231 }
232232}
233233
234impl<I: Interner> Relate<I> for ty::UnevaluatedConst<I> {
234impl<I: Interner> Relate<I> for ty::AliasConst<I> {
235235 fn relate<R: TypeRelation<I>>(
236236 relation: &mut R,
237 a: ty::UnevaluatedConst<I>,
238 b: ty::UnevaluatedConst<I>,
239 ) -> RelateResult<I, ty::UnevaluatedConst<I>> {
237 a: ty::AliasConst<I>,
238 b: ty::AliasConst<I>,
239 ) -> RelateResult<I, ty::AliasConst<I>> {
240240 let cx = relation.cx();
241241 if a.kind != b.kind {
242242 Err(TypeError::ConstMismatch(ExpectedFound::new(
243 Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), a),
244 Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), b),
243 Const::new_alias(cx, ty::IsRigid::yes_if_next_solver(cx), a),
244 Const::new_alias(cx, ty::IsRigid::yes_if_next_solver(cx), b),
245245 )))
246246 } else {
247247 // FIXME(mgca): remove this
......@@ -249,7 +249,7 @@ impl<I: Interner> Relate<I> for ty::UnevaluatedConst<I> {
249249
250250 let args = relate_args_invariantly(relation, a.args, b.args)?;
251251
252 Ok(ty::UnevaluatedConst::new(cx, a.kind, args))
252 Ok(ty::AliasConst::new(cx, a.kind, args))
253253 }
254254 }
255255}
......@@ -550,7 +550,7 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
550550}
551551
552552/// Relates `a` and `b` structurally, calling the relation for all nested values.
553/// Any semantic equality, e.g. of unevaluated consts, and inference variables have
553/// Any semantic equality, e.g. of alias consts, and inference variables have
554554/// to be handled by the caller.
555555///
556556/// FIXME: This is not totally structural, which probably should be fixed.
......@@ -618,14 +618,11 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
618618 // While this is slightly incorrect, it shouldn't matter for `min_const_generics`
619619 // and is the better alternative to waiting until `generic_const_exprs` can
620620 // be stabilized.
621 (
622 ty::ConstKind::Unevaluated(is_rigid_a, au),
623 ty::ConstKind::Unevaluated(is_rigid_b, bu),
624 ) => {
621 (ty::ConstKind::Alias(is_rigid_a, au), ty::ConstKind::Alias(is_rigid_b, bu)) => {
625622 // Users shouldn't know about this so the mismatch should be caught
626623 // during development rather than presented as type error.
627624 debug_assert_eq!(is_rigid_a, is_rigid_b, "{a:?} != {b:?}");
628 return Ok(Const::new_unevaluated(cx, is_rigid_a, relation.relate(au, bu)?));
625 return Ok(Const::new_alias(cx, is_rigid_a, relation.relate(au, bu)?));
629626 }
630627 (ty::ConstKind::Expr(ae), ty::ConstKind::Expr(be)) => {
631628 let expr = relation.relate(ae, be)?;
compiler/rustc_type_ir/src/relate/combine.rs+4-5
......@@ -239,14 +239,13 @@ where
239239 Ok(a)
240240 }
241241
242 (
243 ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _),
244 ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _),
245 ) if (infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver()) => {
242 (ty::ConstKind::Alias(ty::IsRigid::Yes, _), ty::ConstKind::Alias(ty::IsRigid::Yes, _))
243 if (infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver()) =>
244 {
246245 structurally_relate_consts(relation, a, b)
247246 }
248247
249 (ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..))
248 (ty::ConstKind::Alias(..), _) | (_, ty::ConstKind::Alias(..))
250249 if infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver() =>
251250 {
252251 match relation.structurally_relate_aliases() {
compiler/rustc_type_ir/src/term_kind.rs+27-43
......@@ -60,9 +60,9 @@ pub enum AliasTermKind<I: Interner> {
6060 /// Can always be normalized away.
6161 FreeTy { def_id: I::FreeTyAliasId },
6262
63 /// An unevaluated anonymous constants.
64 AnonConst { def_id: I::UnevaluatedConstId },
65 /// An unevaluated const coming from an associated const.
63 /// An anonymous constant.
64 AnonConst { def_id: I::AnonConstId },
65 /// A const alias coming from an associated const.
6666 ProjectionConst { def_id: I::TraitAssocConstId },
6767 /// A top level const item not part of a trait or impl.
6868 FreeConst { def_id: I::FreeConstAliasId },
......@@ -79,8 +79,8 @@ impl<I: Interner> AliasTermKind<I> {
7979 AliasTermKind::InherentConst { .. } => "inherent associated const",
8080 AliasTermKind::OpaqueTy { .. } => "opaque type",
8181 AliasTermKind::FreeTy { .. } => "type alias",
82 AliasTermKind::FreeConst { .. } => "unevaluated constant",
83 AliasTermKind::AnonConst { .. } => "unevaluated constant",
82 AliasTermKind::FreeConst { .. } => "const alias",
83 AliasTermKind::AnonConst { .. } => "anonymous constant",
8484 }
8585 }
8686
......@@ -122,17 +122,13 @@ impl<I: Interner> From<ty::AliasTyKind<I>> for AliasTermKind<I> {
122122 }
123123}
124124
125impl<I: Interner> From<ty::UnevaluatedConstKind<I>> for AliasTermKind<I> {
126 fn from(value: ty::UnevaluatedConstKind<I>) -> Self {
125impl<I: Interner> From<ty::AliasConstKind<I>> for AliasTermKind<I> {
126 fn from(value: ty::AliasConstKind<I>) -> Self {
127127 match value {
128 ty::UnevaluatedConstKind::Projection { def_id } => {
129 AliasTermKind::ProjectionConst { def_id }
130 }
131 ty::UnevaluatedConstKind::Inherent { def_id } => {
132 AliasTermKind::InherentConst { def_id }
133 }
134 ty::UnevaluatedConstKind::Free { def_id } => AliasTermKind::FreeConst { def_id },
135 ty::UnevaluatedConstKind::Anon { def_id } => AliasTermKind::AnonConst { def_id },
128 ty::AliasConstKind::Projection { def_id } => AliasTermKind::ProjectionConst { def_id },
129 ty::AliasConstKind::Inherent { def_id } => AliasTermKind::InherentConst { def_id },
130 ty::AliasConstKind::Free { def_id } => AliasTermKind::FreeConst { def_id },
131 ty::AliasConstKind::Anon { def_id } => AliasTermKind::AnonConst { def_id },
136132 }
137133 }
138134}
......@@ -189,24 +185,20 @@ impl<I: Interner> AliasTerm<I> {
189185 ty::AliasTy { kind, args: self.args, _use_alias_new_instead: () }
190186 }
191187
192 pub fn expect_ct(self) -> ty::UnevaluatedConst<I> {
188 pub fn expect_ct(self) -> ty::AliasConst<I> {
193189 let kind = match self.kind {
194 AliasTermKind::InherentConst { def_id } => {
195 ty::UnevaluatedConstKind::Inherent { def_id }
196 }
197 AliasTermKind::FreeConst { def_id } => ty::UnevaluatedConstKind::Free { def_id },
198 AliasTermKind::AnonConst { def_id } => ty::UnevaluatedConstKind::Anon { def_id },
199 AliasTermKind::ProjectionConst { def_id } => {
200 ty::UnevaluatedConstKind::Projection { def_id }
201 }
190 AliasTermKind::InherentConst { def_id } => ty::AliasConstKind::Inherent { def_id },
191 AliasTermKind::FreeConst { def_id } => ty::AliasConstKind::Free { def_id },
192 AliasTermKind::AnonConst { def_id } => ty::AliasConstKind::Anon { def_id },
193 AliasTermKind::ProjectionConst { def_id } => ty::AliasConstKind::Projection { def_id },
202194 kind @ (AliasTermKind::ProjectionTy { .. }
203195 | AliasTermKind::InherentTy { .. }
204196 | AliasTermKind::OpaqueTy { .. }
205197 | AliasTermKind::FreeTy { .. }) => {
206 panic!("Cannot turn `{}` into `UnevaluatedConst`", kind.descr())
198 panic!("Cannot turn `{}` into `AliasConst`", kind.descr())
207199 }
208200 };
209 ty::UnevaluatedConst { kind, args: self.args, _use_alias_new_instead: () }
201 ty::AliasConst { kind, args: self.args, _use_alias_new_instead: () }
210202 }
211203
212204 pub fn to_term(self, interner: I, is_rigid: ty::IsRigid) -> I::Term {
......@@ -214,26 +206,18 @@ impl<I: Interner> AliasTerm<I> {
214206 Ty::new_alias(interner, is_rigid, ty::AliasTy::new_from_args(interner, kind, self.args))
215207 .into()
216208 };
217 let unevaluated_const = |kind| {
218 I::Const::new_unevaluated(
219 interner,
220 is_rigid,
221 ty::UnevaluatedConst::new(interner, kind, self.args),
222 )
223 .into()
209 let alias_const = |kind| {
210 I::Const::new_alias(interner, is_rigid, ty::AliasConst::new(interner, kind, self.args))
211 .into()
224212 };
225213 match self.kind {
226 AliasTermKind::FreeConst { def_id } => {
227 unevaluated_const(ty::UnevaluatedConstKind::Free { def_id })
228 }
214 AliasTermKind::FreeConst { def_id } => alias_const(ty::AliasConstKind::Free { def_id }),
229215 AliasTermKind::InherentConst { def_id } => {
230 unevaluated_const(ty::UnevaluatedConstKind::Inherent { def_id })
231 }
232 AliasTermKind::AnonConst { def_id } => {
233 unevaluated_const(ty::UnevaluatedConstKind::Anon { def_id })
216 alias_const(ty::AliasConstKind::Inherent { def_id })
234217 }
218 AliasTermKind::AnonConst { def_id } => alias_const(ty::AliasConstKind::Anon { def_id }),
235219 AliasTermKind::ProjectionConst { def_id } => {
236 unevaluated_const(ty::UnevaluatedConstKind::Projection { def_id })
220 alias_const(ty::AliasConstKind::Projection { def_id })
237221 }
238222 AliasTermKind::ProjectionTy { def_id } => alias_ty(ty::Projection { def_id }),
239223 AliasTermKind::InherentTy { def_id } => alias_ty(ty::Inherent { def_id }),
......@@ -367,8 +351,8 @@ impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> {
367351 }
368352}
369353
370impl<I: Interner> From<ty::UnevaluatedConst<I>> for AliasTerm<I> {
371 fn from(ty: ty::UnevaluatedConst<I>) -> Self {
354impl<I: Interner> From<ty::AliasConst<I>> for AliasTerm<I> {
355 fn from(ty: ty::AliasConst<I>) -> Self {
372356 AliasTerm { args: ty.args, kind: AliasTermKind::from(ty.kind), _use_alias_new_instead: () }
373357 }
374358}
compiler/rustc_type_ir/src/ty/alias.rs+2-2
......@@ -5,7 +5,7 @@ use rustc_type_ir_macros::{
55 GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
66};
77
8use crate::{AliasTermKind, AliasTyKind, Interner, UnevaluatedConstKind};
8use crate::{AliasConstKind, AliasTermKind, AliasTyKind, Interner};
99
1010/// Represents an alias of a type, constant, or other term-like item.
1111///
......@@ -55,4 +55,4 @@ pub type ProjectionAliasTy<I> = Alias<I, <I as Interner>::TraitAssocTyId>;
5555pub type InherentAliasTy<I> = Alias<I, <I as Interner>::InherentAssocTyId>;
5656pub type OpaqueAliasTy<I> = Alias<I, <I as Interner>::OpaqueTyId>;
5757pub type FreeAliasTy<I> = Alias<I, <I as Interner>::FreeTyAliasId>;
58pub type UnevaluatedConst<I> = Alias<I, UnevaluatedConstKind<I>>;
58pub type AliasConst<I> = Alias<I, AliasConstKind<I>>;
compiler/rustc_type_ir/src/walk.rs+1-1
......@@ -160,7 +160,7 @@ fn push_inner<I: Interner>(stack: &mut TypeWalkerStack<I>, parent: I::GenericArg
160160 ty::ConstKind::Value(cv) => stack.push(cv.ty().into()),
161161
162162 ty::ConstKind::Expr(expr) => stack.extend(expr.args().iter().rev()),
163 ty::ConstKind::Unevaluated(_, ct) => {
163 ty::ConstKind::Alias(_, ct) => {
164164 stack.extend(ct.args.iter().rev());
165165 }
166166 },
src/librustdoc/clean/utils.rs+5-5
......@@ -350,8 +350,8 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
350350
351351pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String {
352352 match n.kind() {
353 ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, .. }) => match kind {
354 ty::UnevaluatedConstKind::Projection { def_id } => {
353 ty::ConstKind::Alias(_, ty::AliasConst { kind, .. }) => match kind {
354 ty::AliasConstKind::Projection { def_id } => {
355355 if let Some(local_def_id) = def_id.as_local()
356356 && let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id)
357357 {
......@@ -360,9 +360,9 @@ pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String {
360360 n.to_string()
361361 }
362362 }
363 ty::UnevaluatedConstKind::Inherent { def_id }
364 | ty::UnevaluatedConstKind::Free { def_id }
365 | ty::UnevaluatedConstKind::Anon { def_id } => {
363 ty::AliasConstKind::Inherent { def_id }
364 | ty::AliasConstKind::Free { def_id }
365 | ty::AliasConstKind::Anon { def_id } => {
366366 if let Some(local_def_id) = def_id.as_local()
367367 && let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id)
368368 {
tests/mir-opt/issue_99325.main.built.after.32bit.mir+1-1
......@@ -2,7 +2,7 @@
22
33| User Type Annotations
44| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [AliasConst(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66|
77fn main() -> () {
88 let mut _0: ();
tests/mir-opt/issue_99325.main.built.after.64bit.mir+1-1
......@@ -2,7 +2,7 @@
22
33| User Type Annotations
44| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [AliasConst(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66|
77fn main() -> () {
88 let mut _0: ();
tests/ui/const-generics/mgca/cyclic-type-const-151251.rs+1-1
......@@ -5,6 +5,6 @@
55#![expect(incomplete_features)]
66
77type const A: u8 = A;
8//~^ ERROR overflow normalizing the unevaluated constant `A`
8//~^ ERROR overflow normalizing the const alias `A`
99
1010fn main() {}
tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr+1-1
......@@ -1,4 +1,4 @@
1error[E0275]: overflow normalizing the unevaluated constant `A`
1error[E0275]: overflow normalizing the const alias `A`
22 --> $DIR/cyclic-type-const-151251.rs:7:1
33 |
44LL | type const A: u8 = A;
tests/ui/const-generics/mgca/type_const-recursive.rs+1-1
......@@ -3,6 +3,6 @@
33
44
55type const A: u8 = A;
6//~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275]
6//~^ ERROR: overflow normalizing the const alias `A` [E0275]
77
88fn main() {}
tests/ui/const-generics/mgca/type_const-recursive.stderr+1-1
......@@ -1,4 +1,4 @@
1error[E0275]: overflow normalizing the unevaluated constant `A`
1error[E0275]: overflow normalizing the const alias `A`
22 --> $DIR/type_const-recursive.rs:5:1
33 |
44LL | type const A: u8 = A;
tests/ui/offset-of/inside-array-length.stderr+1-1
......@@ -37,7 +37,7 @@ LL | fn foo<'a, T: 'a>(_: [(); std::mem::offset_of!((T,), 0)]) {}
3737 = note: ...which requires caching mir of `foo::{constant#0}` for CTFE...
3838 = note: ...which requires elaborating drops for `foo::{constant#0}`...
3939 = note: ...which requires borrow-checking `foo::{constant#0}`...
40 = note: ...which requires normalizing `Binder { value: ConstEvaluatable(Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:7 ~ inside_array_length[07d6]::foo::{constant#0}) }, args: ['^c_1, T/#1], .. })), bound_vars: [] }`...
40 = note: ...which requires normalizing `Binder { value: ConstEvaluatable(AliasConst(No, Alias { kind: Anon { def_id: DefId(0:7 ~ inside_array_length[07d6]::foo::{constant#0}) }, args: ['^c_1, T/#1], .. })), bound_vars: [] }`...
4141 = note: ...which again requires evaluating type-level constant, completing the cycle
4242 = note: cycle used when normalizing `inside_array_length::::foo::{constant#0}`
4343 = note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>