diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 5281b85b1ed04..42f9e0aea8910 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1760,13 +1760,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { let tcx = self.tcx(); let maybe_uneval = match constant.const_ { Const::Ty(_, ct) => match ct.kind() { - ty::ConstKind::Unevaluated(_, uv) => match uv.kind { - ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Inherent { def_id } - | ty::UnevaluatedConstKind::Free { def_id } - | ty::UnevaluatedConstKind::Anon { def_id } => { - Some(UnevaluatedConst { def: def_id, args: uv.args, promoted: None }) - } + ty::ConstKind::Alias(_, alias_const) => match alias_const.kind { + ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Inherent { def_id } + | ty::AliasConstKind::Free { def_id } + | ty::AliasConstKind::Anon { def_id } => Some(UnevaluatedConst { + def: def_id, + args: alias_const.args, + promoted: None, + }), }, _ => None, }, diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index 111ada0241116..d6578def58692 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -344,13 +344,13 @@ where let uneval = match constant.const_ { Const::Ty(_, ct) => match ct.kind() { ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None, - // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`). - ty::ConstKind::Unevaluated(_, _) => None, + // Alias consts in MIR bodies don't have associated MIR (e.g. `type const`). + ty::ConstKind::Alias(_, _) => None, // FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly // strict, and if instead we should be doing some kind of value-based analysis. ty::ConstKind::Value(_) => None, _ => bug!( - "expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}", + "expected ConstKind::Param, ConstKind::Value, ConstKind::Alias, or ConstKind::Error here, found {:?}", ct ), }, diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index e98307c7c7b18..0aa31c3a016b9 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -778,8 +778,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), if has_default { // need to store default and type of default let ct = tcx.const_param_default(param.def_id).skip_binder(); - if let ty::ConstKind::Unevaluated(_, uv) = ct.kind() - && let Some(def_id) = uv.kind.opt_def_id() + if let ty::ConstKind::Alias(_, alias_const) = ct.kind() + && let Some(def_id) = alias_const.kind.opt_def_id() { tcx.ensure_ok().type_of(def_id); } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index bf8593eb61882..17141de79b4bf 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1488,7 +1488,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: // be sure if it will error or not as user might always specify the other. // FIXME(generic_const_exprs): This is incorrect when dealing with unused const params. // E.g: `struct Foo;`. Here, we should - // eagerly error but we don't as we have `ConstKind::Unevaluated(.., [N, M])`. + // eagerly error but we don't as we have `ConstKind::Alias(.., [N, M])`. if !default.has_param() { wfcx.register_wf_obligation( tcx.def_span(param.def_id), @@ -1509,7 +1509,9 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: | ty::ConstKind::Bound(_, _) => unreachable!(), ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => continue, ty::ConstKind::Value(cv) => cv.ty, - ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), + ty::ConstKind::Alias(_, alias_const) => { + alias_const.type_of(infcx.tcx).skip_norm_wip() + } ty::ConstKind::Param(param_ct) => { param_ct.find_const_ty_from_env(wfcx.param_env) } diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 64f12fd6644c5..811ed83e0bf48 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -124,11 +124,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { // ^ parent_def_id // // then we only want to return generics for params to the left of `N`. If we don't do that we - // end up with that const looking like: `ty::ConstKind::Unevaluated(def_id, args: [N#0])`. + // end up with that const looking like: `ty::ConstKind::Alias(def_id, args: [N#0])`. // // This causes ICEs (#86580) when building the args for Foo in `fn foo() -> Foo { .. }` as // we instantiate the defaults with the partially built args when we build the args. Instantiating - // the `N#0` on the unevaluated const indexes into the empty args we're in the process of building. + // the `N#0` on the alias const indexes into the empty args we're in the process of building. // // We fix this by having this function return the parent's generics ourselves and truncating the // generics to only include non-forward declared params (with the exception of the `Self` ty) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index e1798c24838d1..0dc89381c5eb6 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -415,8 +415,8 @@ fn const_evaluatable_predicates_of<'tcx>( preds: FxIndexSet<(ty::Clause<'tcx>, Span)>, } - fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::UnevaluatedConstKind<'_>) -> bool { - let ty::UnevaluatedConstKind::Anon { def_id } = kind else { return false }; + fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::AliasConstKind<'_>) -> bool { + let ty::AliasConstKind::Anon { def_id } = kind else { return false }; let Some(local) = def_id.as_local() else { return false }; let hir_id = tcx.local_def_id_to_hir_id(local); @@ -433,8 +433,8 @@ fn const_evaluatable_predicates_of<'tcx>( impl<'tcx> TypeVisitor> for ConstCollector<'tcx> { fn visit_const(&mut self, c: ty::Const<'tcx>) { - if let ty::ConstKind::Unevaluated(_, uv) = c.kind() { - if is_const_param_default(self.tcx, uv.kind) { + if let ty::ConstKind::Alias(_, alias_const) = c.kind() { + if is_const_param_default(self.tcx, alias_const.kind) { // Do not look into const param defaults, // these get checked when they are actually instantiated. // @@ -446,11 +446,11 @@ fn const_evaluatable_predicates_of<'tcx>( } // Skip type consts as mGCA doesn't support evaluatable clauses. - if uv.kind.is_type_const(self.tcx) { + if alias_const.kind.is_type_const(self.tcx) { return; } - let span = uv.kind.def_span(self.tcx); + let span = alias_const.kind.def_span(self.tcx); self.preds.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span)); } } diff --git a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs index 46b2eb538f080..a392ff5d3a552 100644 --- a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs +++ b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs @@ -93,7 +93,7 @@ impl<'tcx> TypeVisitor> for ParameterCollector { fn visit_const(&mut self, c: ty::Const<'tcx>) { match c.kind() { - ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => { + ty::ConstKind::Alias(..) if !self.include_nonconstraining => { // Constant expressions are not injective in general. return; } diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index baa9fddc2a651..0796b4f2e8644 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1402,7 +1402,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { if let Some(def_id) = alias_ct.kind.opt_def_id() { self.require_type_const_attribute(def_id, span)?; } - let ct = Const::new_unevaluated(tcx, ty::IsRigid::No, alias_ct); + let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct); let ct = self.check_param_uses_if_mcg(ct, span, false); Ok(ct) } @@ -1865,12 +1865,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ty::AssocTag::Const, )?; self.require_type_const_attribute(item_def_id, span)?; - let uv = ty::UnevaluatedConst::new( + let alias_const = ty::AliasConst::new( tcx, - ty::UnevaluatedConstKind::new_from_def_id(tcx, item_def_id), + ty::AliasConstKind::new_from_def_id(tcx, item_def_id), item_args, ); - Ok(Const::new_unevaluated(tcx, ty::IsRigid::No, uv)) + Ok(Const::new_alias(tcx, ty::IsRigid::No, alias_const)) } /// Lower a [resolved][hir::QPath::Resolved] (type-level) associated item path. @@ -2772,14 +2772,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let _ = self .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None); let args = self.lower_generic_args_of_path_segment(span, did, segment); - ty::Const::new_unevaluated( + ty::Const::new_alias( tcx, ty::IsRigid::No, - ty::UnevaluatedConst::new( - tcx, - ty::UnevaluatedConstKind::new_from_def_id(tcx, did), - args, - ), + ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, did), args), ) } Res::Def(kind @ DefKind::Ctor(ctor_of, CtorKind::Const), did) => { @@ -2915,7 +2911,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { self.check_param_uses_if_mcg(ct, span, false) } - /// Literals are eagerly converted to a constant, everything else becomes `Unevaluated`. + /// Literals are eagerly converted to a constant, everything else becomes `ConstKind::Alias`. #[instrument(skip(self), level = "debug")] fn lower_const_arg_anon(&self, anon: &AnonConst) -> Const<'tcx> { let tcx = self.tcx(); @@ -2930,12 +2926,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { match self.try_lower_anon_const_lit(ty, expr) { Some(v) => v, - None => ty::Const::new_unevaluated( + None => ty::Const::new_alias( tcx, ty::IsRigid::No, - ty::UnevaluatedConst::new( + ty::AliasConst::new( tcx, - ty::UnevaluatedConstKind::Anon { def_id: anon.def_id.to_def_id() }, + ty::AliasConstKind::Anon { def_id: anon.def_id.to_def_id() }, ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()), ), ), diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 095213322a9fd..a2e3883b0684e 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -408,8 +408,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance); match &c.kind() { - ty::ConstKind::Unevaluated(_, uv) => { - self.add_constraints_from_invariant_args(current, uv.args, variance); + ty::ConstKind::Alias(_, alias_const) => { + self.add_constraints_from_invariant_args(current, alias_const.args, variance); } _ => {} } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index c8c6de4f99c03..c94d278e99e56 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1453,7 +1453,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ct = self.resolve_vars_with_obligations(ct); if self.next_trait_solver() - && let ty::ConstKind::Unevaluated(..) = ct.kind() + && let ty::ConstKind::Alias(..) = ct.kind() { // We need to use a separate variable here as otherwise the temporary for // `self.fulfillment_cx.borrow_mut()` is alive in the `Err` branch, resulting diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 890110e431fa2..0ccda42515345 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -161,7 +161,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) | ty::ConstKind::Placeholder(_) - | ty::ConstKind::Unevaluated(_, _) => enforce_copy_bound(element, element_ty), + | ty::ConstKind::Alias(_, _) => enforce_copy_bound(element, element_ty), ty::ConstKind::Bound(_, _) | ty::ConstKind::Infer(_) | ty::ConstKind::Error(_) => { unreachable!() diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index c058bebddcf03..f0fd46e6cac74 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -158,7 +158,7 @@ impl<'a, 'tcx> TypeFolder> for TypeFreshener<'a, 'tcx> { ty::ConstKind::Param(_) | ty::ConstKind::Value(_) - | ty::ConstKind::Unevaluated(..) + | ty::ConstKind::Alias(..) | ty::ConstKind::Expr(..) | ty::ConstKind::Error(_) => ct.super_fold_with(self), } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 92be5dec28542..aa2fe2ee21dfa 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1266,7 +1266,7 @@ impl<'tcx> InferCtxt<'tcx> { ty::ConstKind::Param(_) | ty::ConstKind::Bound(_, _) | ty::ConstKind::Placeholder(_) - | ty::ConstKind::Unevaluated(_, _) + | ty::ConstKind::Alias(_, _) | ty::ConstKind::Value(_) | ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => ct, diff --git a/compiler/rustc_infer/src/infer/relate/generalize.rs b/compiler/rustc_infer/src/infer/relate/generalize.rs index f50fd4a32328e..7881b85997e8c 100644 --- a/compiler/rustc_infer/src/infer/relate/generalize.rs +++ b/compiler/rustc_infer/src/infer/relate/generalize.rs @@ -77,7 +77,7 @@ impl<'tcx> InferCtxt<'tcx> { /// would result in an infinite type as we continuously replace an inference variable /// in `ct` with `ct` itself. /// - /// This is especially important as unevaluated consts use their parents generics. + /// This is especially important as alias consts use their parents generics. /// They therefore often contain unused args, making these errors far more likely. /// /// A good example of this is the following: @@ -95,7 +95,7 @@ impl<'tcx> InferCtxt<'tcx> { /// } /// ``` /// - /// Here `3 + 4` ends up as `ConstKind::Unevaluated` which uses the generics + /// Here `3 + 4` ends up as `ConstKind::Alias` which uses the generics /// of `fn bind` (meaning that its args contain `N`). /// /// `bind(arr)` now infers that the type of `arr` must be `[u8; N]`. @@ -112,8 +112,8 @@ impl<'tcx> InferCtxt<'tcx> { target_vid: ty::ConstVid, source_ct: ty::Const<'tcx>, ) -> RelateResult<'tcx, ()> { - // FIXME(generic_const_exprs): Occurs check failures for unevaluated - // constants and generic expressions are not yet handled correctly. + // FIXME(generic_const_exprs): Occurs check failures for alias consts + // and generic expressions are not yet handled correctly. debug_assert!( self.inner.borrow_mut().const_unification_table().probe_value(target_vid).is_unknown() ); @@ -752,7 +752,7 @@ impl<'tcx> TypeRelation> for Generalizer<'_, 'tcx> { } } } - // FIXME: Unevaluated constants are also not rigid, so the current + // FIXME: Alias consts are also not rigid, so the current // approach of always relating them structurally is incomplete. // // FIXME: replace the StructurallyRelateAliases::Yes branch with @@ -760,26 +760,26 @@ impl<'tcx> TypeRelation> for Generalizer<'_, 'tcx> { // // We only need to be careful with potentially normalizeable // aliases here. See `generalize_alias_term` for more information. - ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => { + ty::ConstKind::Alias(ty::IsRigid::No, alias_const) => { match self.structurally_relate_aliases { // Hack: Fall back to old behavior if GCE is enabled (it used to just be the Yes // path), as doing this new No path breaks some GCE things. I expect GCE to be // ripped out soon so this shouldn't matter soon. StructurallyRelateAliases::No if !tcx.features().generic_const_exprs() => { - self.generalize_alias_term(uv.into()).map(|v| v.expect_const()) + self.generalize_alias_term(alias_const.into()).map(|v| v.expect_const()) } _ => { - let ty::UnevaluatedConst { kind, args, .. } = uv; + let ty::AliasConst { kind, args, .. } = alias_const; let args = self.relate_with_variance( ty::Invariant, ty::VarianceDiagInfo::default(), args, args, )?; - Ok(ty::Const::new_unevaluated( + Ok(ty::Const::new_alias( tcx, ty::IsRigid::No, - ty::UnevaluatedConst::new(tcx, kind, args), + ty::AliasConst::new(tcx, kind, args), )) } } diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index 6effeacac5fcf..44c5e66279c14 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -221,7 +221,7 @@ pub enum Const<'tcx> { /// An unevaluated mir constant which is not part of the type system. /// - /// Note that `Ty(ty::ConstKind::Unevaluated)` and this variant are *not* identical! `Ty` will + /// Note that `Ty(ty::ConstKind::Alias)` and this variant are *not* identical! `Ty` will /// always flow through a valtree, so all data not captured in the valtree is lost. This variant /// directly uses the evaluated result of the given constant, including e.g. data stored in /// padding. @@ -472,13 +472,9 @@ pub struct UnevaluatedConst<'tcx> { impl<'tcx> UnevaluatedConst<'tcx> { #[inline] - pub fn shrink(self, tcx: TyCtxt<'tcx>) -> ty::UnevaluatedConst<'tcx> { + pub fn shrink(self, tcx: TyCtxt<'tcx>) -> ty::AliasConst<'tcx> { assert_eq!(self.promoted, None); - ty::UnevaluatedConst::new( - tcx, - ty::UnevaluatedConstKind::new_from_def_id(tcx, self.def), - self.args, - ) + ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, self.def), self.args) } } diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index 51cf856a2d477..accd00a8ebb51 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -90,7 +90,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn const_eval_resolve_for_typeck( self, typing_env: ty::TypingEnv<'tcx>, - ct: ty::UnevaluatedConst<'tcx>, + ct: ty::AliasConst<'tcx>, span: Span, ) -> ConstToValTreeResult<'tcx> { // Cannot resolve `Unevaluated` constants that contain inference @@ -104,10 +104,10 @@ impl<'tcx> TyCtxt<'tcx> { } let def_id = match ct.kind { - ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Inherent { def_id } - | ty::UnevaluatedConstKind::Free { def_id } - | ty::UnevaluatedConstKind::Anon { def_id } => def_id, + ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Inherent { def_id } + | ty::AliasConstKind::Free { def_id } + | ty::AliasConstKind::Anon { def_id } => def_id, }; let cid = match ty::Instance::try_resolve(self, typing_env, def_id, ct.args) { diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index c1fd68b5702c8..8e83d44fbb78b 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1491,16 +1491,14 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { let val = match const_ { Const::Ty(_, ct) => match ct.kind() { ty::ConstKind::Param(p) => format!("ty::Param({p})"), - ty::ConstKind::Unevaluated(_, uv) => { - let kind = match uv.kind { - ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Inherent { def_id } - | ty::UnevaluatedConstKind::Free { def_id } - | ty::UnevaluatedConstKind::Anon { def_id } => { - self.tcx.def_path_str(def_id) - } + ty::ConstKind::Alias(_, alias_const) => { + let kind = match alias_const.kind { + ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Inherent { def_id } + | ty::AliasConstKind::Free { def_id } + | ty::AliasConstKind::Anon { def_id } => self.tcx.def_path_str(def_id), }; - format!("ty::Unevaluated({}, {:?})", kind, uv.args) + format!("ty::AliasConst({}, {:?})", kind, alias_const.args) } ty::ConstKind::Value(cv) => { format!("ty::Valtree({})", fmt_valtree(&cv)) diff --git a/compiler/rustc_middle/src/ty/abstract_const.rs b/compiler/rustc_middle/src/ty/abstract_const.rs index 08a34fd397357..43ed22927da56 100644 --- a/compiler/rustc_middle/src/ty/abstract_const.rs +++ b/compiler/rustc_middle/src/ty/abstract_const.rs @@ -52,13 +52,13 @@ impl<'tcx> TyCtxt<'tcx> { } fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> { let ct = match c.kind() { - ty::ConstKind::Unevaluated(_, uv) - if let Some(def_id) = uv.kind.opt_def_id() => + ty::ConstKind::Alias(_, alias_const) + if let Some(def_id) = alias_const.kind.opt_def_id() => { match self.tcx.thir_abstract_const(def_id) { Err(e) => ty::Const::new_error(self.tcx, e), Ok(Some(bac)) => { - let args = self.tcx.erase_and_anonymize_regions(uv.args); + let args = self.tcx.erase_and_anonymize_regions(alias_const.args); let bac = bac.instantiate(self.tcx, args).skip_norm_wip(); return bac.fold_with(self); } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 3455e770b40d1..df25b08168609 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -21,8 +21,8 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed}; pub use valtree::*; pub type ConstKind<'tcx> = ir::ConstKind>; -pub type UnevaluatedConst<'tcx> = ir::UnevaluatedConst>; -pub type UnevaluatedConstKind<'tcx> = ir::UnevaluatedConstKind>; +pub type AliasConst<'tcx> = ir::AliasConst>; +pub type AliasConstKind<'tcx> = ir::AliasConstKind>; #[cfg(target_pointer_width = "64")] rustc_data_structures::static_assert_size!(ConstKind<'_>, 32); @@ -107,12 +107,12 @@ impl<'tcx> Const<'tcx> { } #[inline] - pub fn new_unevaluated( + pub fn new_alias( tcx: TyCtxt<'tcx>, is_rigid: ty::IsRigid, - uv: ty::UnevaluatedConst<'tcx>, + alias_const: ty::AliasConst<'tcx>, ) -> Const<'tcx> { - Const::new(tcx, ty::ConstKind::Unevaluated(is_rigid, uv)) + Const::new(tcx, ty::ConstKind::Alias(is_rigid, alias_const)) } #[inline] @@ -157,7 +157,7 @@ impl<'tcx> Const<'tcx> { true } ty::ConstKind::Infer(_) - | ty::ConstKind::Unevaluated(..) + | ty::ConstKind::Alias(..) | ty::ConstKind::Value(_) | ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => false, @@ -194,12 +194,12 @@ impl<'tcx> rustc_type_ir::inherent::Const> for Const<'tcx> { Const::new_placeholder(tcx, placeholder) } - fn new_unevaluated( + fn new_alias( interner: TyCtxt<'tcx>, is_rigid: ty::IsRigid, - uv: ty::UnevaluatedConst<'tcx>, + alias_const: ty::AliasConst<'tcx>, ) -> Self { - Const::new_unevaluated(interner, is_rigid, uv) + Const::new_alias(interner, is_rigid, alias_const) } fn new_expr(interner: TyCtxt<'tcx>, expr: ty::Expr<'tcx>) -> Self { diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 60c2acdb4c4f9..5819470765e69 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -41,7 +41,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type CoroutineId = DefId; type AdtId = DefId; type ImplId = DefId; - type UnevaluatedConstId = DefId; + type AnonConstId = DefId; type TraitAssocTyId = DefId; type TraitAssocConstId = DefId; type TraitAssocTermId = DefId; @@ -208,23 +208,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> { self.adt_def(adt_def_id) } - fn unevaluated_const_kind_from_def_id( - self, - def_id: Self::DefId, - ) -> ty::UnevaluatedConstKind<'tcx> { + fn alias_const_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasConstKind<'tcx> { match self.def_kind(def_id) { DefKind::AssocConst { .. } => { if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { - ty::UnevaluatedConstKind::Inherent { def_id } + ty::AliasConstKind::Inherent { def_id } } else { - ty::UnevaluatedConstKind::Projection { def_id } + ty::AliasConstKind::Projection { def_id } } } - DefKind::Const { .. } => ty::UnevaluatedConstKind::Free { def_id }, + DefKind::Const { .. } => ty::AliasConstKind::Free { def_id }, DefKind::AnonConst | DefKind::InlineConst | DefKind::Ctor(_, CtorKind::Const) => { - ty::UnevaluatedConstKind::Anon { def_id } + ty::AliasConstKind::Anon { def_id } } - kind => bug!("unexpected DefKind in UnevaluatedConst: {kind:?}"), + kind => bug!("unexpected DefKind in AliasConst: {kind:?}"), } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 3ea798ee45fb2..f6709e9b64328 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -76,9 +76,9 @@ pub use self::closure::{ place_to_string_for_capture, }; pub use self::consts::{ - AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult, Expr, ExprKind, - LitToConstInput, ScalarInt, SimdAlign, UnevaluatedConst, UnevaluatedConstKind, ValTree, - ValTreeKindExt, Value, const_lit_matches_ty, + AliasConst, AliasConstKind, AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult, + Expr, ExprKind, LitToConstInput, ScalarInt, SimdAlign, ValTree, ValTreeKindExt, Value, + const_lit_matches_ty, }; pub use self::context::{ CtxtInterners, CurrentGcx, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls, @@ -692,7 +692,7 @@ impl<'tcx> Term<'tcx> { _ => None, }, TermKind::Const(ct) => match ct.kind() { - ConstKind::Unevaluated(_, uv) => Some(uv.into()), + ConstKind::Alias(_, alias_const) => Some(alias_const.into()), _ => None, }, } @@ -705,7 +705,7 @@ impl<'tcx> Term<'tcx> { _ => false, }, ty::TermKind::Const(ct) => match ct.kind() { - ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => true, + ty::ConstKind::Alias(ty::IsRigid::No, _) => true, _ => false, }, } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index c1f96c3a94fdd..a9258ba6c9a2d 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1568,14 +1568,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } match ct.kind() { - ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => { + ty::ConstKind::Alias(_, ty::AliasConst { kind, args, .. }) => { match kind { - ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Inherent { def_id } - | ty::UnevaluatedConstKind::Free { def_id } => { + ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Inherent { def_id } + | ty::AliasConstKind::Free { def_id } => { self.pretty_print_value_path(def_id, args)?; } - ty::UnevaluatedConstKind::Anon { def_id } => { + ty::AliasConstKind::Anon { def_id } => { if def_id.is_local() && let span = self.tcx().def_span(def_id) && let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 0bcc10a760725..49bac6a130231 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -634,8 +634,8 @@ impl<'tcx> TypeSuperFoldable> for ty::Const<'tcx> { folder: &mut F, ) -> Result { let kind = match self.kind() { - ConstKind::Unevaluated(is_rigid, uv) => { - ConstKind::Unevaluated(is_rigid, uv.try_fold_with(folder)?) + ConstKind::Alias(is_rigid, alias_const) => { + ConstKind::Alias(is_rigid, alias_const.try_fold_with(folder)?) } ConstKind::Value(v) => ConstKind::Value(v.try_fold_with(folder)?), ConstKind::Expr(e) => ConstKind::Expr(e.try_fold_with(folder)?), @@ -651,8 +651,8 @@ impl<'tcx> TypeSuperFoldable> for ty::Const<'tcx> { fn super_fold_with>>(self, folder: &mut F) -> Self { let kind = match self.kind() { - ConstKind::Unevaluated(is_rigid, uv) => { - ConstKind::Unevaluated(is_rigid, uv.fold_with(folder)) + ConstKind::Alias(is_rigid, alias_const) => { + ConstKind::Alias(is_rigid, alias_const.fold_with(folder)) } ConstKind::Value(v) => ConstKind::Value(v.fold_with(folder)), ConstKind::Expr(e) => ConstKind::Expr(e.fold_with(folder)), @@ -670,7 +670,7 @@ impl<'tcx> TypeSuperFoldable> for ty::Const<'tcx> { impl<'tcx> TypeSuperVisitable> for ty::Const<'tcx> { fn super_visit_with>>(&self, visitor: &mut V) -> V::Result { match self.kind() { - ConstKind::Unevaluated(_, uv) => uv.visit_with(visitor), + ConstKind::Alias(_, alias_const) => alias_const.visit_with(visitor), ConstKind::Value(v) => v.visit_with(visitor), ConstKind::Expr(e) => e.visit_with(visitor), ConstKind::Error(e) => e.visit_with(visitor), diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index 534629edd7895..620e6da6a8f88 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -200,10 +200,10 @@ impl<'tcx> TypeVisitor> for LateBoundRegionsCollector<'tcx> { fn visit_const(&mut self, c: ty::Const<'tcx>) { // if we are only looking for "constrained" region, we have to - // ignore the inputs of an unevaluated const, as they may not appear + // ignore the inputs of an alias const, as they may not appear // in the normalized form if self.just_constrained { - if let ty::ConstKind::Unevaluated(..) = c.kind() { + if let ty::ConstKind::Alias(..) = c.kind() { return; } } diff --git a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs index f0f7e166e9672..caf4f8d295c8a 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs @@ -72,12 +72,12 @@ pub(crate) fn as_constant_inner<'tcx>( ExprKind::NamedConst { def_id, args, ref user_ty } => { let user_ty = user_ty.as_ref().and_then(push_cuta); if tcx.is_type_const(def_id) { - let uneval = ty::UnevaluatedConst::new( + let uneval = ty::AliasConst::new( tcx, - ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id), + ty::AliasConstKind::new_from_def_id(tcx, def_id), args, ); - let ct = ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval); + let ct = ty::Const::new_alias(tcx, ty::IsRigid::No, uneval); let const_ = Const::Ty(ty, ct); return ConstOperand { span, user_ty, const_ }; diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index a9c194959b28a..7c714fd7281d5 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -49,7 +49,7 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { let mut convert = ConstToPat::new(self, id, span, c); match c.kind() { - ty::ConstKind::Unevaluated(_, uv) => convert.unevaluated_to_pat(uv, ty), + ty::ConstKind::Alias(_, alias_const) => convert.alias_to_pat(alias_const, ty), ty::ConstKind::Value(value) => convert.valtree_to_pat(value), _ => span_bug!(span, "Invalid `ConstKind` for `const_to_pat`: {:?}", c), } @@ -77,17 +77,17 @@ impl<'tcx> ConstToPat<'tcx> { /// We errored. Signal that in the pattern, so that follow up errors can be silenced. fn mk_err(&self, mut err: Diag<'_>, ty: Ty<'tcx>) -> Box> { - if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind() { - if let ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Inherent { def_id } = uv.kind + if let ty::ConstKind::Alias(_, alias_const) = self.c.kind() { + if let ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Inherent { def_id } = alias_const.kind && let Some(def_id) = def_id.as_local() { // Include the container item in the output. err.span_label(self.tcx.def_span(self.tcx.local_parent(def_id)), ""); } - if let ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Inherent { def_id } - | ty::UnevaluatedConstKind::Free { def_id } = uv.kind + if let ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Inherent { def_id } + | ty::AliasConstKind::Free { def_id } = alias_const.kind { err.span_label(self.tcx.def_span(def_id), msg!("constant defined here")); } @@ -95,11 +95,7 @@ impl<'tcx> ConstToPat<'tcx> { Box::new(Pat { span: self.span, ty, kind: PatKind::Error(err.emit()), extra: None }) } - fn unevaluated_to_pat( - &mut self, - uv: ty::UnevaluatedConst<'tcx>, - ty: Ty<'tcx>, - ) -> Box> { + fn alias_to_pat(&mut self, alias_const: ty::AliasConst<'tcx>, ty: Ty<'tcx>) -> Box> { // It's not *technically* correct to be revealing opaque types here as borrowcheck has // not run yet. However, CTFE itself uses `TypingMode::PostAnalysis` unconditionally even // during typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821). @@ -109,13 +105,13 @@ impl<'tcx> ConstToPat<'tcx> { // instead of having this logic here let typing_env = self.tcx.erase_and_anonymize_regions(self.typing_env).with_codegen_normalized(self.tcx); - let uv = self.tcx.erase_and_anonymize_regions(uv); + let alias_const = self.tcx.erase_and_anonymize_regions(alias_const); // FIXME(gca): This will become insufficient once associated constants can be // implemented as `type` consts (project-const-generics#76). At that point it'll // become necessary to just use type system normalization for all const patterns // but that's not yet possible. - let mut thir_pat = if uv.kind.is_type_const(self.tcx) { + let mut thir_pat = if alias_const.kind.is_type_const(self.tcx) { let Ok(normalize) = self .tcx .try_normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(self.c)) @@ -132,67 +128,68 @@ impl<'tcx> ConstToPat<'tcx> { } else { // try to resolve e.g. associated constants to their definition on an impl, and then // evaluate the const. - let valtree = match self.tcx.const_eval_resolve_for_typeck(typing_env, uv, self.span) { - Ok(Ok(c)) => c, - Err(ErrorHandled::Reported(_, _)) => { - // Let's tell the use where this failing const occurs. - let mut err = - self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span }); - // We've emitted an error on the original const, it would be redundant to complain - // on its use as well. - if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind() - && let ty::UnevaluatedConstKind::Projection { .. } - | ty::UnevaluatedConstKind::Inherent { .. } - | ty::UnevaluatedConstKind::Free { .. } = uv.kind - { - err.downgrade_to_delayed_bug(); - } - return self.mk_err(err, ty); - } - Err(ErrorHandled::TooGeneric(_)) => { - let mut e = self - .tcx - .dcx() - .create_err(ConstPatternDependsOnGenericParameter { span: self.span }); - for arg in uv.args { - if let ty::GenericArgKind::Type(ty) = arg.kind() - && let ty::Param(param_ty) = ty.kind() + let valtree = + match self.tcx.const_eval_resolve_for_typeck(typing_env, alias_const, self.span) { + Ok(Ok(c)) => c, + Err(ErrorHandled::Reported(_, _)) => { + // Let's tell the use where this failing const occurs. + let mut err = + self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span }); + // We've emitted an error on the original const, it would be redundant to complain + // on its use as well. + if let ty::ConstKind::Alias(_, alias_const) = self.c.kind() + && let ty::AliasConstKind::Projection { .. } + | ty::AliasConstKind::Inherent { .. } + | ty::AliasConstKind::Free { .. } = alias_const.kind { - let def_id = self.tcx.hir_enclosing_body_owner(self.id); - let generics = self.tcx.generics_of(def_id); - let param = generics.type_param(*param_ty, self.tcx); - let span = self.tcx.def_span(param.def_id); - e.span_label(span, "constant depends on this generic parameter"); - if let Some(ident) = self.tcx.def_ident_span(def_id) - && self.tcx.sess.source_map().is_multiline(ident.between(span)) + err.downgrade_to_delayed_bug(); + } + return self.mk_err(err, ty); + } + Err(ErrorHandled::TooGeneric(_)) => { + let mut err = self + .tcx + .dcx() + .create_err(ConstPatternDependsOnGenericParameter { span: self.span }); + for arg in alias_const.args { + if let ty::GenericArgKind::Type(ty) = arg.kind() + && let ty::Param(param_ty) = ty.kind() { - // Display the `fn` name as well in the diagnostic, as the generic isn't - // in the same line and it could be confusing otherwise. - e.span_label(ident, ""); + let def_id = self.tcx.hir_enclosing_body_owner(self.id); + let generics = self.tcx.generics_of(def_id); + let param = generics.type_param(*param_ty, self.tcx); + let span = self.tcx.def_span(param.def_id); + err.span_label(span, "constant depends on this generic parameter"); + if let Some(ident) = self.tcx.def_ident_span(def_id) + && self.tcx.sess.source_map().is_multiline(ident.between(span)) + { + // Display the `fn` name as well in the diagnostic, as the generic isn't + // in the same line and it could be confusing otherwise. + err.span_label(ident, ""); + } } } + return self.mk_err(err, ty); } - return self.mk_err(e, ty); - } - Ok(Err(bad_ty)) => { - // The pattern cannot be turned into a valtree. - let e = match bad_ty.kind() { - ty::Adt(def, ..) => { - assert!(def.is_union()); - self.tcx.dcx().create_err(UnionPattern { span: self.span }) - } - ty::FnPtr(..) | ty::RawPtr(..) => { - self.tcx.dcx().create_err(PointerPattern { span: self.span }) - } - _ => self.tcx.dcx().create_err(InvalidPattern { - span: self.span, - non_sm_ty: bad_ty, - prefix: bad_ty.prefix_string(self.tcx).to_string(), - }), - }; - return self.mk_err(e, ty); - } - }; + Ok(Err(bad_ty)) => { + // The pattern cannot be turned into a valtree. + let e = match bad_ty.kind() { + ty::Adt(def, ..) => { + assert!(def.is_union()); + self.tcx.dcx().create_err(UnionPattern { span: self.span }) + } + ty::FnPtr(..) | ty::RawPtr(..) => { + self.tcx.dcx().create_err(PointerPattern { span: self.span }) + } + _ => self.tcx.dcx().create_err(InvalidPattern { + span: self.span, + non_sm_ty: bad_ty, + prefix: bad_ty.prefix_string(self.tcx).to_string(), + }), + }; + return self.mk_err(e, ty); + } + }; // Lower the valtree to a THIR pattern. self.valtree_to_pat(ty::Value { ty, valtree }) @@ -209,7 +206,7 @@ impl<'tcx> ConstToPat<'tcx> { // Mark the pattern to indicate that it is the result of lowering a named // constant. This is used for diagnostics. - thir_pat.extra.get_or_insert_default().expanded_const = uv.kind.opt_def_id(); + thir_pat.extra.get_or_insert_default().expanded_const = alias_const.kind.opt_def_id(); thir_pat } @@ -253,7 +250,7 @@ impl<'tcx> ConstToPat<'tcx> { // then error about that instead, because `TypeNotStructural` gives advice that is // relevant only when the problem is that `ty` does not derive `PartialEq`. // - // Note that this is a duplicate of a check in `unevaluated_to_pat()`, + // Note that this is a duplicate of a check in `alias_to_pat()`, // which we would run later if we weren’t emitting an error now. if possibly_inapplicable_derived_partial_eq && !has_impl { let mut err = diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 4bf69b3a85520..11b31cb3976c9 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -657,12 +657,12 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { let args = self.typeck_results.node_args(id); // FIXME(mgca): we will need to special case IACs here to have type system compatible // generic args, instead of how we represent them in body expressions. - let c = ty::Const::new_unevaluated( + let c = ty::Const::new_alias( self.tcx, ty::IsRigid::No, - ty::UnevaluatedConst::new( + ty::AliasConst::new( self.tcx, - ty::UnevaluatedConstKind::new_from_def_id(self.tcx, def_id), + ty::AliasConstKind::new_from_def_id(self.tcx, def_id), args, ), ); diff --git a/compiler/rustc_mir_transform/src/impossible_predicates.rs b/compiler/rustc_mir_transform/src/impossible_predicates.rs index d099fc3b9ddeb..cc216c39b8599 100644 --- a/compiler/rustc_mir_transform/src/impossible_predicates.rs +++ b/compiler/rustc_mir_transform/src/impossible_predicates.rs @@ -44,7 +44,7 @@ pub(crate) fn has_impossible_predicates(tcx: TyCtxt<'_>, def_id: DefId) -> bool !p.has_type_flags( // Only consider global clauses to simplify. TypeFlags::HAS_FREE_LOCAL_NAMES - // Clauses that refer to unevaluated constants as they cause cycles. + // Clauses that refer to alias constants as they cause cycles. | TypeFlags::HAS_CT_PROJECTION, ) }); diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 7c8bef2aa3fe6..c36b687111c01 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -1026,7 +1026,7 @@ fn inline_call<'tcx, I: Inliner<'tcx>>( }); // Copy required constants from the callee_body into the caller_body. Although we are only - // pushing unevaluated consts to `required_consts`, here they may have been evaluated + // pushing constants that still need evaluation to `required_consts`, here they may have been evaluated // because we are calling `instantiate_and_normalize_erasing_regions` -- so we filter again. caller_body.required_consts.as_mut().unwrap().extend( callee_body.required_consts().into_iter().filter(|ct| ct.const_.is_required_const()), diff --git a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs index c7697e5b78ecb..5aa09e1ba7932 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs @@ -565,7 +565,7 @@ impl, I: Interner> TypeFolder for Canonicaliz }, // FIXME: See comment above -- we could fold the region separately or something. ty::ConstKind::Bound(_, _) - | ty::ConstKind::Unevaluated(_, _) + | ty::ConstKind::Alias(_, _) | ty::ConstKind::Value(_) | ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => return c.super_fold_with(self), diff --git a/compiler/rustc_next_trait_solver/src/delegate.rs b/compiler/rustc_next_trait_solver/src/delegate.rs index 8fd7d6d0471c7..2ebb0fb851a4c 100644 --- a/compiler/rustc_next_trait_solver/src/delegate.rs +++ b/compiler/rustc_next_trait_solver/src/delegate.rs @@ -37,7 +37,7 @@ pub trait SolverDelegate: Deref + Sized { fn evaluate_const( &self, param_env: ::ParamEnv, - uv: ty::UnevaluatedConst, + alias_const: ty::AliasConst, ) -> Option<::Const>; // FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`! diff --git a/compiler/rustc_next_trait_solver/src/normalize.rs b/compiler/rustc_next_trait_solver/src/normalize.rs index 1f9c4407af4c5..761b141202d98 100644 --- a/compiler/rustc_next_trait_solver/src/normalize.rs +++ b/compiler/rustc_next_trait_solver/src/normalize.rs @@ -231,7 +231,7 @@ where // With eager normalization, we should normalize the args of alias before // normalizing the alias itself. let ct = ct.try_super_fold_with(self)?; - let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return Ok(ct) }; + let ty::ConstKind::Alias(orig_is_rigid, alias_const) = ct.kind() else { return Ok(ct) }; // We support ambiguous aliases inside rigid alias. So we still recognize // the rigidness of the outer alias. if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { @@ -239,10 +239,10 @@ where } let normalized = if ct.has_escaping_bound_vars() { - let (uv, mapped_regions, mapped_types, mapped_consts) = - BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uv); + let (alias_const, mapped_regions, mapped_types, mapped_consts) = + BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, alias_const); let Some(result) = ensure_sufficient_stack(|| { - self.normalize_alias_term(uv.into(), HasEscapingBoundVars::Yes) + self.normalize_alias_term(alias_const.into(), HasEscapingBoundVars::Yes) })? else { return Ok(ct); @@ -257,7 +257,7 @@ where ) } else { ensure_sufficient_stack(|| { - self.normalize_alias_term(uv.into(), HasEscapingBoundVars::No) + self.normalize_alias_term(alias_const.into(), HasEscapingBoundVars::No) })? .map(|term| term.expect_const()) .unwrap_or(ct) diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index 05532cdb8924b..dd65342ea519d 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -1439,13 +1439,13 @@ where pub(super) fn evaluate_const( &mut self, param_env: I::ParamEnv, - uv: ty::UnevaluatedConst, + alias_const: ty::AliasConst, ) -> Result, RerunNonErased> { if self.typing_mode().is_erased_not_coherence() { self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)?; } - Ok(self.delegate.evaluate_const(param_env, uv)) + Ok(self.delegate.evaluate_const(param_env, alias_const)) } pub(super) fn evaluate_const_and_instantiate_projection_term( @@ -1453,9 +1453,9 @@ where param_env: I::ParamEnv, projection_term: ty::AliasTerm, expected_term: I::Term, - uv: ty::UnevaluatedConst, + alias_const: ty::AliasConst, ) -> QueryResultOrRerunNonErased { - match self.evaluate_const(param_env, uv)? { + match self.evaluate_const(param_env, alias_const)? { Some(evaluated) => { self.eq(param_env, expected_term, evaluated.into())?; self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) @@ -1468,11 +1468,11 @@ where // Perhaps we could split EvaluateConstErr::HasGenericsOrInfers into HasGenerics and // HasInfers or something, make evaluate_const return that, and make this branch be // based on that, rather than checking `has_non_region_infer`. - if self.resolve_vars_if_possible(uv).has_non_region_infer() { + if self.resolve_vars_if_possible(alias_const).has_non_region_infer() { self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) } else { - // We do not instantiate to the `uv` passed in, but rather - // `goal.predicate.alias`. The `uv` passed in might correspond to the `impl` + // We do not instantiate to the `alias_const` passed in, but rather + // `goal.predicate.alias`. The `alias_const` passed in might correspond to the `impl` // form of a constant (with generic arguments corresponding to the impl block), // however, we want to structurally instantiate to the original, non-rebased, // trait `Self` form of the constant (with generic arguments being the trait diff --git a/compiler/rustc_next_trait_solver/src/solve/mod.rs b/compiler/rustc_next_trait_solver/src/solve/mod.rs index 27efb582dafcf..8b838f3567c84 100644 --- a/compiler/rustc_next_trait_solver/src/solve/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs @@ -196,7 +196,7 @@ where Goal { param_env, predicate: ct }: Goal, ) -> QueryResultOrRerunNonErased { match ct.kind() { - ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _) + ty::ConstKind::Alias(ty::IsRigid::Yes, _) | ty::ConstKind::Placeholder(_) | ty::ConstKind::Value(_) | ty::ConstKind::Error(_) => { @@ -207,7 +207,7 @@ where self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) } - ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => { + ty::ConstKind::Alias(ty::IsRigid::No, alias_const) => { // We never return `NoSolution` here as `evaluate_const` emits an // error itself when failing to evaluate, so emitting an additional fulfillment // error in that case is unnecessary noise. This may change in the future once @@ -216,7 +216,7 @@ where // FIXME(generic_const_exprs): Implement handling for generic // const expressions here. - if let Some(_normalized) = self.evaluate_const(param_env, uv)? { + if let Some(_normalized) = self.evaluate_const(param_env, alias_const)? { self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } else { self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) @@ -252,10 +252,10 @@ where .evaluate_added_goals_and_make_canonical_response(Certainty::Yes) .map_err(Into::into); } - ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => { - uv.type_of(self.cx()).skip_norm_wip() + ty::ConstKind::Alias(ty::IsRigid::Yes, alias_const) => { + alias_const.type_of(self.cx()).skip_norm_wip() } - ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => unimplemented!( + ty::ConstKind::Alias(ty::IsRigid::No, _) => unimplemented!( "non-rigid unevaluated constant for compute_const_arg_has_type_goal: {ct:?}" ), ty::ConstKind::Expr(_) => unimplemented!( diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs index e0290dfbdebdf..b161fcb520afb 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs @@ -454,9 +454,9 @@ where c.into() } ty::AliasTermKind::ProjectionConst { .. } => { - let uv = ty::UnevaluatedConst::new( + let alias_const = ty::AliasConst::new( cx, - ty::UnevaluatedConstKind::Projection { + ty::AliasConstKind::Projection { def_id: target_item_def_id.into().try_into().unwrap(), }, target_args, @@ -465,7 +465,7 @@ where goal.param_env, goal.predicate.alias, goal.predicate.term, - uv, + alias_const, ); } kind => panic!("expected projection, found {kind:?}"), diff --git a/compiler/rustc_next_trait_solver/src/solve/project_goals/anon_const.rs b/compiler/rustc_next_trait_solver/src/solve/project_goals/anon_const.rs index f1baa608798fa..fc0c34e63e187 100644 --- a/compiler/rustc_next_trait_solver/src/solve/project_goals/anon_const.rs +++ b/compiler/rustc_next_trait_solver/src/solve/project_goals/anon_const.rs @@ -15,12 +15,12 @@ where &mut self, goal: Goal>, ) -> QueryResultOrRerunNonErased { - let uv = goal.predicate.projection_term.expect_ct(); + let alias_const = goal.predicate.projection_term.expect_ct(); self.evaluate_const_and_instantiate_projection_term( goal.param_env, goal.predicate.projection_term, goal.predicate.term, - uv, + alias_const, ) } } diff --git a/compiler/rustc_public/src/unstable/convert/stable/ty.rs b/compiler/rustc_public/src/unstable/convert/stable/ty.rs index 4d92660a1b8bb..2f280ef9fe4c0 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/ty.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/ty.rs @@ -552,16 +552,14 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { } } ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)), - ty::ConstKind::Unevaluated(_, uv) => { - let Some(def_id) = uv.kind.opt_def_id() else { - // FIXME: implement (both AliasTy and UnevaluatedConst will be needing this soon) - panic!( - "non-defid unevaluated constants are not supported by rustc_public at the moment" - ) + ty::ConstKind::Alias(_, alias_const) => { + let Some(def_id) = alias_const.kind.opt_def_id() else { + // FIXME: implement (both AliasTy and AliasConst will be needing this soon) + panic!("non-defid alias consts are not supported by rustc_public at the moment") }; crate::ty::TyConstKind::Unevaluated( tables.const_def(def_id), - uv.args.stable(tables, cx), + alias_const.args.stable(tables, cx), ) } ty::ConstKind::Error(_) => unreachable!(), diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index ed4489636f2d8..b26545fa2b4b0 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -696,13 +696,13 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> { return Ok(()); } - // We may still encounter unevaluated consts due to the printing + // We may still encounter alias consts due to the printing // logic sometimes passing identity-substituted impl headers. - ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => match kind { - ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Inherent { def_id } - | ty::UnevaluatedConstKind::Free { def_id } - | ty::UnevaluatedConstKind::Anon { def_id } => { + ty::ConstKind::Alias(_, ty::AliasConst { kind, args, .. }) => match kind { + ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Inherent { def_id } + | ty::AliasConstKind::Free { def_id } + | ty::AliasConstKind::Anon { def_id } => { return self.print_def_path(def_id, args); } }, diff --git a/compiler/rustc_trait_selection/src/diagnostics.rs b/compiler/rustc_trait_selection/src/diagnostics.rs index 662480587fdd2..ba89b0987659e 100644 --- a/compiler/rustc_trait_selection/src/diagnostics.rs +++ b/compiler/rustc_trait_selection/src/diagnostics.rs @@ -21,11 +21,11 @@ use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlig pub(crate) mod note_and_explain; #[derive(Diagnostic)] -#[diag("unable to construct a constant value for the unevaluated constant {$unevaluated}")] +#[diag("unable to construct a constant value for the alias const {$alias_const}")] pub(crate) struct UnableToConstructConstantValue<'a> { #[primary_span] pub span: Span, - pub unevaluated: ty::UnevaluatedConst<'a>, + pub alias_const: ty::AliasConst<'a>, } pub(crate) struct NegativePositiveConflict<'tcx> { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index 333f6f01c0ef1..624aef89911f7 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -1079,9 +1079,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { } } GenericArgKind::Const(ct) => { - if matches!(ct.kind(), ty::ConstKind::Unevaluated(..)) { + if matches!(ct.kind(), ty::ConstKind::Alias(..)) { // You can't write the generic arguments for - // unevaluated constants. + // alias constants. walker.skip_current_subtree(); } } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index d85a9c9d57ef8..973a088a7f5d4 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -3769,12 +3769,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { match obligation.predicate.kind().skip_binder() { ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => match ct.kind() { - ty::ConstKind::Unevaluated(_, uv) => { + ty::ConstKind::Alias(_, alias_const) => { let mut err = self.dcx().struct_span_err(span, "unconstrained generic constant"); - let const_span = uv.kind.def_span(self.tcx); + let const_span = alias_const.kind.def_span(self.tcx); - let const_ty = uv.type_of(self.tcx).skip_norm_wip(); + let const_ty = alias_const.type_of(self.tcx).skip_norm_wip(); let cast = if const_ty != self.tcx.types.usize { " as usize" } else { "" }; let msg = "try adding a `where` bound"; if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(const_span) { @@ -3812,7 +3812,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { Ok(err) } _ => { - bug!("const evaluatable failed for non-unevaluated const `{ct:?}`"); + bug!("const evaluatable failed for non-alias const `{ct:?}`"); } }, _ => { diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index f907b4ba19122..e0877829b25f3 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -218,9 +218,9 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< fn evaluate_const( &self, param_env: ty::ParamEnv<'tcx>, - uv: ty::UnevaluatedConst<'tcx>, + alias_const: ty::AliasConst<'tcx>, ) -> Option> { - let ct = ty::Const::new_unevaluated(self.tcx, ty::IsRigid::No, uv); + let ct = ty::Const::new_alias(self.tcx, ty::IsRigid::No, alias_const); match crate::traits::try_evaluate_const(&self.0, ct, param_env) { Ok(ct) => Some(ct), diff --git a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs index 0d3e2500d0e05..098dcfb30a7b6 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs @@ -34,7 +34,9 @@ pub(super) fn fulfillment_error_for_no_solution<'tcx>( } ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => { let ct_ty = match ct.kind() { - ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), + ty::ConstKind::Alias(_, alias_const) => { + alias_const.type_of(infcx.tcx).skip_norm_wip() + } ty::ConstKind::Param(param_ct) => { param_ct.find_const_ty_from_env(obligation.param_env) } diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index 56c89773a6285..a1a7fdc6f6b82 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -146,18 +146,21 @@ impl<'me, 'tcx> TypeFolder> for ReplaceAliasWithInfer<'me, 'tcx> { } let ct = ct.super_fold_with(self); - let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return ct }; + let ty::ConstKind::Alias(orig_is_rigid, alias_const) = ct.kind() else { return ct }; if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { return ct; } if ct.has_escaping_bound_vars() { - let (replaced, ..) = - BoundVarReplacer::replace_bound_vars(self.at.infcx, &mut self.universes, uv); + let (replaced, ..) = BoundVarReplacer::replace_bound_vars( + self.at.infcx, + &mut self.universes, + alias_const, + ); let _ = self.term_to_infer(replaced.into()); ct } else { - self.term_to_infer(uv.into()).expect_const() + self.term_to_infer(alias_const.into()).expect_const() } } } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 6d9c11789f2b7..a39f498e36fd8 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -774,15 +774,15 @@ impl<'tcx> AutoTraitFinder<'tcx> { } ty::PredicateKind::ConstEquate(c1, c2) => { let evaluate = |c: ty::Const<'tcx>| { - if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() { + if let ty::ConstKind::Alias(_, alias_const) = c.kind() { let ct = super::try_evaluate_const(selcx.infcx, c, obligation.param_env); if let Err(EvaluateConstErr::InvalidConstParamTy(_)) = ct { - let span = unevaluated.kind.def_span(self.tcx); + let span = alias_const.kind.def_span(self.tcx); self.tcx .dcx() - .emit_err(UnableToConstructConstantValue { span, unevaluated }); + .emit_err(UnableToConstructConstantValue { span, alias_const }); } ct diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 16009e5295f27..4b54f9c3a2c26 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -30,7 +30,7 @@ pub fn is_const_evaluatable<'tcx>( ) -> Result<(), NotConstEvaluatable> { let tcx = infcx.tcx; match tcx.expand_abstract_consts(unexpanded_ct).kind() { - ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Expr(_) => (), + ty::ConstKind::Alias(_, _) | ty::ConstKind::Expr(_) => (), ty::ConstKind::Param(_) | ty::ConstKind::Bound(_, _) | ty::ConstKind::Placeholder(_) @@ -44,10 +44,7 @@ pub fn is_const_evaluatable<'tcx>( let is_anon_ct = matches!( ct.kind(), - ty::ConstKind::Unevaluated( - _, - ty::UnevaluatedConst { kind: ty::UnevaluatedConstKind::Anon { .. }, .. } - ) + ty::ConstKind::Alias(_, ty::AliasConst { kind: ty::AliasConstKind::Anon { .. }, .. }) ); if !is_anon_ct { @@ -69,7 +66,7 @@ pub fn is_const_evaluatable<'tcx>( // here. tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported"); } - ty::ConstKind::Unevaluated(_, _) => { + ty::ConstKind::Alias(_, _) => { match crate::traits::try_evaluate_const(infcx, unexpanded_ct, param_env) { Err(EvaluateConstErr::HasGenericsOrInfers) => { Err(NotConstEvaluatable::Error(infcx.dcx().span_delayed_bug( @@ -93,8 +90,8 @@ pub fn is_const_evaluatable<'tcx>( crate::traits::evaluate_const(infcx, unexpanded_ct, param_env); Ok(()) } else { - let uv = match unexpanded_ct.kind() { - ty::ConstKind::Unevaluated(_, uv) => uv, + let alias_const = match unexpanded_ct.kind() { + ty::ConstKind::Alias(_, alias_const) => alias_const, ty::ConstKind::Expr(_) => { bug!("`ConstKind::Expr` without `feature(generic_const_exprs)` enabled") } @@ -117,7 +114,7 @@ pub fn is_const_evaluatable<'tcx>( tcx.dcx() .struct_span_fatal( // Slightly better span than just using `span` alone - if span == DUMMY_SP { uv.kind.def_span(tcx) } else { span }, + if span == DUMMY_SP { alias_const.kind.def_span(tcx) } else { span }, "failed to evaluate generic const expression", ) .with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`") @@ -131,9 +128,9 @@ pub fn is_const_evaluatable<'tcx>( } Err(EvaluateConstErr::HasGenericsOrInfers) => { - let err = if uv.has_non_region_infer() { + let err = if alias_const.has_non_region_infer() { NotConstEvaluatable::MentionsInfer - } else if uv.has_non_region_param() { + } else if alias_const.has_non_region_param() { NotConstEvaluatable::MentionsParam } else { let guar = infcx.dcx().span_delayed_bug( diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 36a562ab862fa..7b45dfe48a7fe 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -886,13 +886,9 @@ impl<'tcx> TypeVisitor> for IllegalSelfTypeVisitor<'tcx> { let ct = self.tcx.expand_abstract_consts(ct); match ct.kind() { - ty::ConstKind::Unevaluated( + ty::ConstKind::Alias( _, - ty::UnevaluatedConst { - kind: ty::UnevaluatedConstKind::Projection { def_id }, - args, - .. - }, + ty::AliasConst { kind: ty::AliasConstKind::Projection { def_id }, args, .. }, ) if self.tcx.features().min_generic_const_args() => { match self.allow_self_projections { AllowSelfProjections::Yes => { diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index ea2f17d266b78..12b9940a83f44 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -559,7 +559,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { return ProcessResult::Changed(PendingPredicateObligations::new()); } ty::ConstKind::Value(cv) => cv.ty, - ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), + ty::ConstKind::Alias(_, alias_const) => { + alias_const.type_of(infcx.tcx).skip_norm_wip() + } // FIXME(generic_const_exprs): we should construct an alias like // `>::Output` when this is an `Expr` representing // `lhs + rhs`. @@ -677,10 +679,10 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { } } - ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => { + ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => { match const_evaluatable::is_const_evaluatable( self.selcx.infcx, - uv, + alias_const, obligation.param_env, obligation.cause.span, ) { @@ -688,7 +690,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { Err(NotConstEvaluatable::MentionsInfer) => { pending_obligation.stalled_on.clear(); pending_obligation.stalled_on.extend( - uv.walk().filter_map(TyOrConstInferVar::maybe_from_generic_arg), + alias_const + .walk() + .filter_map(TyOrConstInferVar::maybe_from_generic_arg), ); ProcessResult::Unchanged } @@ -717,15 +721,13 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2); match (c1.kind(), c2.kind()) { - ( - ty::ConstKind::Unevaluated(_, a), - ty::ConstKind::Unevaluated(_, b), - ) if a.kind == b.kind - && matches!( - a.kind, - ty::UnevaluatedConstKind::Projection { .. } - | ty::UnevaluatedConstKind::Inherent { .. } - ) => + (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b)) + if a.kind == b.kind + && matches!( + a.kind, + ty::AliasConstKind::Projection { .. } + | ty::AliasConstKind::Inherent { .. } + ) => { if let Ok(new_obligations) = infcx .at(&obligation.cause, obligation.param_env) @@ -743,8 +745,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { )); } } - (_, ty::ConstKind::Unevaluated(_, _)) - | (ty::ConstKind::Unevaluated(_, _), _) => (), + (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (), (_, _) => { if let Ok(new_obligations) = infcx .at(&obligation.cause, obligation.param_env) @@ -764,7 +765,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { let stalled_on = &mut pending_obligation.stalled_on; let mut evaluate = |c: Const<'tcx>| { - if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() { + if let ty::ConstKind::Alias(_, alias_const) = c.kind() { match super::try_evaluate_const( self.selcx.infcx, c, @@ -773,7 +774,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { Ok(val) => Ok(val), e @ Err(EvaluateConstErr::HasGenericsOrInfers) => { stalled_on.extend( - unevaluated + alias_const .args .iter() .filter_map(TyOrConstInferVar::maybe_from_generic_arg), diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index c062198861ebe..a98d06351f258 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -369,8 +369,8 @@ pub fn normalize_param_env_or_error<'tcx>( // should actually be okay since without `feature(generic_const_exprs)` the only // const arguments that have a non-empty param env are array repeat counts. These // do not appear in the type system though. - if let ty::ConstKind::Unevaluated(_, uv) = c.kind() - && matches!(uv.kind, ty::UnevaluatedConstKind::Anon { .. }) + if let ty::ConstKind::Alias(_, alias_const) = c.kind() + && matches!(alias_const.kind, ty::AliasConstKind::Anon { .. }) { let infcx = self.0.infer_ctxt().build(TypingMode::non_body_analysis()); let c = evaluate_const(&infcx, c, ty::ParamEnv::empty()); @@ -401,10 +401,10 @@ pub fn normalize_param_env_or_error<'tcx>( // we cannot prove `T: Trait`. // // The same thing is true for const generics- attempting to prove - // `T: Trait` with the same thing as a where clauses + // `T: Trait` with the same thing as a where clauses // will fail. After normalization we may be attempting to prove `T: Trait<4>` with - // the unnormalized where clause `T: Trait`. In order - // for the obligation to hold `4` must be equal to `ConstKind::Unevaluated(...)` + // the unnormalized where clause `T: Trait`. In order + // for the obligation to hold `4` must be equal to `ConstKind::Alias(...)` // but as we do not have lazy norm implemented, equating the two consts fails outright. // // 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>( #[derive(Debug)] pub enum EvaluateConstErr { /// The constant being evaluated was either a generic parameter or inference variable, *or*, - /// some unevaluated constant with either generic parameters or inference variables in its + /// some alias const with either generic parameters or inference variables in its /// generic arguments. HasGenericsOrInfers, /// The type this constant evaluated to is not valid for use in const generics. This should @@ -560,7 +560,7 @@ pub enum EvaluateConstErr { } // FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine -// FIXME(generic_const_exprs): Consider accepting a `ty::UnevaluatedConst` when we are not rolling our own +// FIXME(generic_const_exprs): Consider accepting a `ty::AliasConst` when we are not rolling our own // normalization scheme /// Evaluates a type system constant returning a `ConstKind::Error` in cases where CTFE failed and /// 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>( } // FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine -// FIXME(generic_const_exprs): Consider accepting a `ty::UnevaluatedConst` when we are not rolling our own +// FIXME(generic_const_exprs): Consider accepting a `ty::AliasConst` when we are not rolling our own // normalization scheme /// Evaluates a type system constant making sure to not allow constants that depend on generic parameters /// or inference variables to succeed in evaluating. @@ -608,11 +608,9 @@ pub fn try_evaluate_const<'tcx>( | ty::ConstKind::Bound(_, _) | ty::ConstKind::Placeholder(_) | ty::ConstKind::Expr(_) => Err(EvaluateConstErr::HasGenericsOrInfers), - ty::ConstKind::Unevaluated(_, uv) => { - let opt_anon_const_kind = match uv.kind { - ty::UnevaluatedConstKind::Anon { def_id } => { - Some((def_id, tcx.anon_const_kind(def_id))) - } + ty::ConstKind::Alias(_, alias_const) => { + let opt_anon_const_kind = match alias_const.kind { + ty::AliasConstKind::Anon { def_id } => Some((def_id, tcx.anon_const_kind(def_id))), _ => None, }; @@ -632,14 +630,14 @@ pub fn try_evaluate_const<'tcx>( // completely fall apart under `generic_const_exprs` and makes this whole function Really hard to reason // about if you have to consider gce whatsoever. Some((def_id, ty::AnonConstKind::GCE)) => { - if uv.has_non_region_infer() || uv.has_non_region_param() { + if alias_const.has_non_region_infer() || alias_const.has_non_region_param() { // `feature(generic_const_exprs)` causes anon consts to inherit all parent generics. This can cause // inference variables and generic parameters to show up in `ty::Const` even though the anon const // does not actually make use of them. We handle this case specially and attempt to evaluate anyway. match tcx.thir_abstract_const(def_id) { Ok(Some(ct)) => { let ct = tcx.expand_abstract_consts( - ct.instantiate(tcx, uv.args).skip_norm_wip(), + ct.instantiate(tcx, alias_const.args).skip_norm_wip(), ); if let Err(e) = ct.error_reported() { return Err(EvaluateConstErr::EvaluationFailure(e)); @@ -648,8 +646,10 @@ pub fn try_evaluate_const<'tcx>( // the generic arguments provided for it, then we should *not* attempt to evaluate it. return Err(EvaluateConstErr::HasGenericsOrInfers); } else { - let args = - replace_param_and_infer_args_with_placeholder(tcx, uv.args); + let args = replace_param_and_infer_args_with_placeholder( + tcx, + alias_const.args, + ); let typing_env = infcx .typing_env(tcx.erase_and_anonymize_regions(param_env)) .with_post_analysis_normalized(tcx); @@ -666,11 +666,11 @@ pub fn try_evaluate_const<'tcx>( let typing_env = infcx .typing_env(tcx.erase_and_anonymize_regions(param_env)) .with_post_analysis_normalized(tcx); - (uv.args, typing_env) + (alias_const.args, typing_env) } } Some((def_id, ty::AnonConstKind::RepeatExprCount)) => { - if uv.has_non_region_infer() { + if alias_const.has_non_region_infer() { // Diagnostics will sometimes replace the identity args of anon consts in // array repeat expr counts with inference variables so we have to handle this // even though it is not something we should ever actually encounter. @@ -706,9 +706,9 @@ pub fn try_evaluate_const<'tcx>( // logic does not go through type system normalization. If it did this would // be a backwards compatibility problem as we do not enforce "syntactic" non- // usage of generic parameters like we do here. - if uv.args.has_non_region_param() - || uv.args.has_non_region_infer() - || uv.args.has_non_region_placeholders() + if alias_const.args.has_non_region_param() + || alias_const.args.has_non_region_infer() + || alias_const.args.has_non_region_placeholders() { return Err(EvaluateConstErr::HasGenericsOrInfers); } @@ -717,19 +717,21 @@ pub fn try_evaluate_const<'tcx>( // to prevent query cycle. let typing_env = ty::TypingEnv::fully_monomorphized(); - (uv.args, typing_env) + (alias_const.args, typing_env) } }; - let uv = ty::UnevaluatedConst::new(tcx, uv.kind, args); - let erased_uv = tcx.erase_and_anonymize_regions(uv); + let alias_const = ty::AliasConst::new(tcx, alias_const.kind, args); + let erased_alias_const = tcx.erase_and_anonymize_regions(alias_const); use rustc_middle::mir::interpret::ErrorHandled; // FIXME: `def_span` will point at the definition of this const; ideally, we'd point at // where it gets used as a const generic. - let span = uv.kind.def_span(tcx); - match tcx.const_eval_resolve_for_typeck(typing_env, erased_uv, span) { - Ok(Ok(val)) => Ok(ty::Const::new_value(tcx, val, uv.type_of(tcx).skip_norm_wip())), + let span = alias_const.kind.def_span(tcx); + match tcx.const_eval_resolve_for_typeck(typing_env, erased_alias_const, span) { + Ok(Ok(val)) => { + Ok(ty::Const::new_value(tcx, val, alias_const.type_of(tcx).skip_norm_wip())) + } Ok(Err(_)) => { let e = tcx.dcx().delayed_bug( "Type system constant with non valtree'able type evaluated but no error emitted", diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index f212079c76fbe..2a28fab776a12 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -469,14 +469,14 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx if tcx.features().generic_const_exprs() // Normalize type_const items even with feature `generic_const_exprs`. - && !matches!(ct.kind(), ty::ConstKind::Unevaluated(_, uv) if uv.kind.is_type_const(tcx)) + && !matches!(ct.kind(), ty::ConstKind::Alias(_, alias_const) if alias_const.kind.is_type_const(tcx)) || !needs_normalization(self.selcx.infcx, &ct) { return ct; } - let uv = match ct.kind() { - ty::ConstKind::Unevaluated(_, uv) => uv, + let alias_const = match ct.kind() { + ty::ConstKind::Alias(_, alias_const) => alias_const, _ => return ct.super_fold_with(self), }; @@ -484,20 +484,20 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx // unless a `min_generic_const_args` feature gate error has already // been emitted earlier in compilation. // - // That's because we can only end up with an Unevaluated ty::Const for a const item + // That's because we can only end up with an Alias ty::Const for a const item // if it was marked with `type const`. Using this attribute without the mgca // feature gate causes a parse error. - let ct = match uv.kind { - ty::UnevaluatedConstKind::Projection { .. } => { - self.normalize_trait_projection(uv.into()).expect_const() + let ct = match alias_const.kind { + ty::AliasConstKind::Projection { .. } => { + self.normalize_trait_projection(alias_const.into()).expect_const() } - ty::UnevaluatedConstKind::Inherent { .. } => { - self.normalize_inherent_projection(uv.into()).expect_const() + ty::AliasConstKind::Inherent { .. } => { + self.normalize_inherent_projection(alias_const.into()).expect_const() } - ty::UnevaluatedConstKind::Free { .. } => { - self.normalize_free_alias(uv.into()).expect_const() + ty::AliasConstKind::Free { .. } => { + self.normalize_free_alias(alias_const.into()).expect_const() } - ty::UnevaluatedConstKind::Anon { .. } => { + ty::AliasConstKind::Anon { .. } => { let ct = ct.super_fold_with(self); super::with_replaced_escaping_bound_vars( self.selcx.infcx, diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 45a3b5c85cdc8..e8371a3c0f257 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -272,21 +272,19 @@ impl<'a, 'tcx> FallibleTypeFolder> for QueryNormalizer<'a, 'tcx> { return Ok(constant); } - let uv = match constant.kind() { - ty::ConstKind::Unevaluated(_, uv) => uv, + let alias_const = match constant.kind() { + ty::ConstKind::Alias(_, alias_const) => alias_const, _ => return constant.try_super_fold_with(self), }; - let constant = match uv.kind { - ty::UnevaluatedConstKind::Anon { .. } => { - crate::traits::with_replaced_escaping_bound_vars( - self.infcx, - &mut self.universes, - constant, - |constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env), - ) - } - _ => self.try_fold_free_or_assoc(uv.into())?.expect_const(), + let constant = match alias_const.kind { + ty::AliasConstKind::Anon { .. } => crate::traits::with_replaced_escaping_bound_vars( + self.infcx, + &mut self.universes, + constant, + |constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env), + ), + _ => self.try_fold_free_or_assoc(alias_const.into())?.expect_const(), }; debug!(?constant, ?self.param_env); constant.try_super_fold_with(self) @@ -373,10 +371,10 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> { result.normalized_term }; // `tcx.normalize_canonicalized_projection` may normalize to a type that - // still has unevaluated consts, so keep normalizing here if that's the case. + // still has alias consts, so keep normalizing here if that's the case. // Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer // of type/const and we need to continue folding it to reveal the TAIT behind it - // or further normalize nested unevaluated consts. + // or further normalize nested alias consts. if res != term.to_term(tcx, ty::IsRigid::No) && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) || matches!( diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e33311ed07719..1f3d247a2f7d3 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -852,10 +852,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => { + ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => { match const_evaluatable::is_const_evaluatable( self.infcx, - uv, + alias_const, obligation.param_env, obligation.cause.span, ) { @@ -882,15 +882,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); match (c1.kind(), c2.kind()) { - ( - ty::ConstKind::Unevaluated(_, a), - ty::ConstKind::Unevaluated(_, b), - ) if a.kind == b.kind - && matches!( - a.kind, - ty::UnevaluatedConstKind::Projection { .. } - | ty::UnevaluatedConstKind::Inherent { .. } - ) => + (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b)) + if a.kind == b.kind + && matches!( + a.kind, + ty::AliasConstKind::Projection { .. } + | ty::AliasConstKind::Inherent { .. } + ) => { if let Ok(InferOk { obligations, value: () }) = self .infcx @@ -909,8 +907,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); } } - (_, ty::ConstKind::Unevaluated(_, _)) - | (ty::ConstKind::Unevaluated(_, _), _) => (), + (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (), (_, _) => { if let Ok(InferOk { obligations, value: () }) = self .infcx @@ -929,7 +926,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } let evaluate = |c: ty::Const<'tcx>| { - if let ty::ConstKind::Unevaluated(_, _) = c.kind() { + if let ty::ConstKind::Alias(_, _) = c.kind() { match crate::traits::try_evaluate_const( self.infcx, c, @@ -989,7 +986,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::ConstKind::Error(_) => return Ok(EvaluatedToOk), ty::ConstKind::Value(cv) => cv.ty, - ty::ConstKind::Unevaluated(_, uv) => uv.type_of(self.tcx()).skip_norm_wip(), + ty::ConstKind::Alias(_, alias_const) => { + alias_const.type_of(self.tcx()).skip_norm_wip() + } // FIXME(generic_const_exprs): See comment in `fulfill.rs` ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk), ty::ConstKind::Placeholder(_) => { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 8b1b2acc1f5a3..a47f933f5c25e 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -1064,10 +1064,11 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { let tcx = self.tcx(); match c.kind() { - ty::ConstKind::Unevaluated(_, uv) => { + ty::ConstKind::Alias(_, alias_const) => { if !c.has_escaping_bound_vars() { // Skip type consts as mGCA doesn't support evaluatable clauses - if !uv.kind.is_type_const(tcx) && !tcx.features().generic_const_args() { + if !alias_const.kind.is_type_const(tcx) && !tcx.features().generic_const_args() + { let predicate = ty::Binder::dummy(ty::PredicateKind::Clause( ty::ClauseKind::ConstEvaluatable(c), )); @@ -1081,15 +1082,15 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { )); } - match uv.kind { - ty::UnevaluatedConstKind::Inherent { .. } => { - self.add_wf_preds_for_inherent_projection(uv.into()); + match alias_const.kind { + ty::AliasConstKind::Inherent { .. } => { + self.add_wf_preds_for_inherent_projection(alias_const.into()); return; // Subtree is handled by above function } - ty::UnevaluatedConstKind::Projection { def_id } - | ty::UnevaluatedConstKind::Free { def_id } - | ty::UnevaluatedConstKind::Anon { def_id } => { - let obligations = self.nominal_obligations(def_id, uv.args); + ty::AliasConstKind::Projection { def_id } + | ty::AliasConstKind::Free { def_id } + | ty::AliasConstKind::Anon { def_id } => { + let obligations = self.nominal_obligations(def_id, alias_const.args); self.out.extend(obligations); } } @@ -1111,7 +1112,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { ty::ConstKind::Expr(_) => { // FIXME(generic_const_exprs): this doesn't verify that given `Expr(N + 1)` the // trait bound `typeof(N): Add` holds. This is currently unnecessary - // as `ConstKind::Expr` is only produced via normalization of `ConstKind::Unevaluated` + // as `ConstKind::Expr` is only produced via normalization of `ConstKind::Alias` // which means that the `DefId` would have been typeck'd elsewhere. However in // the future we may allow directly lowering to `ConstKind::Expr` in which case // we would not be proving bounds we should. diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 52964ae72f015..6f7a17c1e4a92 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -70,12 +70,9 @@ fn recurse_build<'tcx>( } &ExprKind::ZstLiteral { user_ty: _ } => ty::Const::zero_sized(tcx, node.ty), &ExprKind::NamedConst { def_id, args, user_ty: _ } => { - let uneval = ty::UnevaluatedConst::new( - tcx, - ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id), - args, - ); - ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval) + let uneval = + ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, def_id), args); + ty::Const::new_alias(tcx, ty::IsRigid::No, uneval) } ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param), diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 4126f9c887194..cdf280381247a 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -177,7 +177,7 @@ fn extract_const_value<'tcx>( } Err(error(cx, LayoutError::TooGeneric(ty))) } - ty::ConstKind::Unevaluated(_, _) => { + ty::ConstKind::Alias(_, _) => { let err = if ct.has_param() { LayoutError::TooGeneric(ty) } else { diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index f353b156757d9..0645839ef0263 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -9,7 +9,7 @@ use rustc_type_ir_macros::{ GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, }; -use crate::{self as ty, BoundVarIndexKind, Interner, UnevaluatedConst}; +use crate::{self as ty, AliasConst, BoundVarIndexKind, Interner}; /// Represents a constant in Rust. #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] @@ -34,7 +34,7 @@ pub enum ConstKind { /// An unnormalized const item such as an anon const or assoc const or free const item. /// Right now anything other than anon consts does not actually work properly but this /// should - Unevaluated(ty::IsRigid, ty::UnevaluatedConst), + Alias(ty::IsRigid, ty::AliasConst), /// Used to hold computed value. Value(I::ValueConst), @@ -43,7 +43,7 @@ pub enum ConstKind { /// propagated to avoid useless error messages. Error(I::ErrorGuaranteed), - /// Unevaluated non-const-item, used by `feature(generic_const_exprs)` to represent + /// A non-const-item expression awaiting evaluation, used by `feature(generic_const_exprs)` to represent /// const arguments such as `N + 1` or `foo(N)` Expr(I::ExprConst), } @@ -59,7 +59,9 @@ impl fmt::Debug for ConstKind { Infer(var) => write!(f, "{var:?}"), Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var), Placeholder(placeholder) => write!(f, "{placeholder:?}"), - Unevaluated(is_rigid, uv) => write!(f, "Unevaluated({is_rigid:?}, {uv:?})"), + Alias(is_rigid, alias_const) => { + write!(f, "AliasConst({is_rigid:?}, {alias_const:?})") + } Value(val) => write!(f, "{val:?}"), Error(_) => write!(f, "{{const error}}"), Expr(expr) => write!(f, "{expr:?}"), @@ -67,46 +69,42 @@ impl fmt::Debug for ConstKind { } } -impl UnevaluatedConst { +impl AliasConst { #[inline] - pub fn new( - interner: I, - kind: UnevaluatedConstKind, - args: I::GenericArgs, - ) -> UnevaluatedConst { + pub fn new(interner: I, kind: AliasConstKind, args: I::GenericArgs) -> AliasConst { if cfg!(debug_assertions) { let def_id = match kind { - ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(), - ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(), - ty::UnevaluatedConstKind::Free { def_id } => def_id.into(), - ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(), + ty::AliasConstKind::Projection { def_id } => def_id.into(), + ty::AliasConstKind::Inherent { def_id } => def_id.into(), + ty::AliasConstKind::Free { def_id } => def_id.into(), + ty::AliasConstKind::Anon { def_id } => def_id.into(), }; interner.debug_assert_args_compatible(def_id, args); } - UnevaluatedConst { kind, args, _use_alias_new_instead: () } + AliasConst { kind, args, _use_alias_new_instead: () } } pub fn type_of(self, interner: I) -> ty::Unnormalized { let def_id = match self.kind { - ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(), - ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(), - ty::UnevaluatedConstKind::Free { def_id } => def_id.into(), - ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(), + ty::AliasConstKind::Projection { def_id } => def_id.into(), + ty::AliasConstKind::Inherent { def_id } => def_id.into(), + ty::AliasConstKind::Free { def_id } => def_id.into(), + ty::AliasConstKind::Anon { def_id } => def_id.into(), }; interner.type_of(def_id).instantiate(interner, self.args) } } -/// UnevaluatedConstKind is extremely similar to AliasTyKind, and likely should be reasoned about +/// AliasConstKind is extremely similar to AliasTyKind, and likely should be reasoned about /// and handled in very similar ways. The documentation for AliasTyKind/etc. may be helpful when -/// learning about UnevaluatedConstKind. +/// learning about AliasConstKind. #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, StableHash_NoContext) )] -pub enum UnevaluatedConstKind { +pub enum AliasConstKind { /// A projection `::AssocConst` Projection { def_id: I::TraitAssocConstId }, /// An associated constant in an inherent `impl` @@ -114,38 +112,38 @@ pub enum UnevaluatedConstKind { /// A free constant, outside an impl block. Free { def_id: I::FreeConstAliasId }, /// Anonymous constant, e.g. the `1 + 2` in `[u8; 1 + 2]`. - Anon { def_id: I::UnevaluatedConstId }, + Anon { def_id: I::AnonConstId }, } -impl UnevaluatedConstKind { +impl AliasConstKind { pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self { - interner.unevaluated_const_kind_from_def_id(def_id) + interner.alias_const_kind_from_def_id(def_id) } pub fn is_type_const(self, interner: I) -> bool { match self { - UnevaluatedConstKind::Projection { def_id } => interner.is_type_const(def_id.into()), - UnevaluatedConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()), - UnevaluatedConstKind::Free { def_id } => interner.is_type_const(def_id.into()), - UnevaluatedConstKind::Anon { def_id } => interner.is_type_const(def_id.into()), + AliasConstKind::Projection { def_id } => interner.is_type_const(def_id.into()), + AliasConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()), + AliasConstKind::Free { def_id } => interner.is_type_const(def_id.into()), + AliasConstKind::Anon { def_id } => interner.is_type_const(def_id.into()), } } pub fn def_span(self, interner: I) -> I::Span { match self { - UnevaluatedConstKind::Projection { def_id } => interner.def_span(def_id.into()), - UnevaluatedConstKind::Inherent { def_id } => interner.def_span(def_id.into()), - UnevaluatedConstKind::Free { def_id } => interner.def_span(def_id.into()), - UnevaluatedConstKind::Anon { def_id } => interner.def_span(def_id.into()), + AliasConstKind::Projection { def_id } => interner.def_span(def_id.into()), + AliasConstKind::Inherent { def_id } => interner.def_span(def_id.into()), + AliasConstKind::Free { def_id } => interner.def_span(def_id.into()), + AliasConstKind::Anon { def_id } => interner.def_span(def_id.into()), } } pub fn opt_def_id(self) -> Option { match self { - UnevaluatedConstKind::Projection { def_id } => Some(def_id.into()), - UnevaluatedConstKind::Inherent { def_id } => Some(def_id.into()), - UnevaluatedConstKind::Free { def_id } => Some(def_id.into()), - UnevaluatedConstKind::Anon { def_id } => Some(def_id.into()), + AliasConstKind::Projection { def_id } => Some(def_id.into()), + AliasConstKind::Inherent { def_id } => Some(def_id.into()), + AliasConstKind::Free { def_id } => Some(def_id.into()), + AliasConstKind::Anon { def_id } => Some(def_id.into()), } } } diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index 14ebffb70b8bf..ac296f204a914 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -469,7 +469,7 @@ impl { @@ -500,9 +500,7 @@ impl { - true - } + ty::ConstKind::Expr(_) | ty::ConstKind::Alias(_, _) | ty::ConstKind::Error(_) => true, ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) => true, } diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index 1749ec99cad4e..da7d8b5acbc1e 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -79,10 +79,10 @@ bitflags::bitflags! { const HAS_TY_OPAQUE = 1 << 12; /// Does this have `Inherent`? const HAS_TY_INHERENT = 1 << 13; - /// Does this have `ConstKind::Unevaluated`? + /// Does this have `ConstKind::Alias`? const HAS_CT_PROJECTION = 1 << 14; - /// Does this have `Alias` or `ConstKind::Unevaluated`? + /// Does this have `Alias` or `ConstKind::Alias`? /// /// Rephrased, could this term be normalized further? const HAS_ALIAS = TypeFlags::HAS_TY_PROJECTION.bits() @@ -432,8 +432,8 @@ impl FlagComputation { self.add_term(term); } ty::PredicateKind::DynCompatible(_def_id) => {} - ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => { - self.add_const(uv); + ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => { + self.add_const(alias_const); } ty::PredicateKind::ConstEquate(expected, found) => { self.add_const(expected); @@ -477,9 +477,9 @@ impl FlagComputation { fn add_const_kind(&mut self, c: &ty::ConstKind) { match *c { - ty::ConstKind::Unevaluated(is_rigid, uv) => { + ty::ConstKind::Alias(is_rigid, alias_const) => { self.add_is_rigid(is_rigid); - self.add_args(uv.args.as_slice()); + self.add_args(alias_const.args.as_slice()); self.add_flags(TypeFlags::HAS_CT_PROJECTION); } ty::ConstKind::Infer(infer) => match infer { diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index 99a1028209e2d..8b1401c0609f9 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -601,9 +601,9 @@ impl TypeFolder for RigidnessFolder { } match c.kind() { - ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => { - let uv = uv.fold_with(self); - I::Const::new_unevaluated(self.cx, ty::IsRigid::No, uv) + ty::ConstKind::Alias(ty::IsRigid::Yes, alias_const) => { + let alias_const = alias_const.fold_with(self); + I::Const::new_alias(self.cx, ty::IsRigid::No, alias_const) } _ => c.super_fold_with(self), } diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 6263f4436abd4..77e5fcac07b3f 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -280,7 +280,7 @@ pub trait Const>: fn new_placeholder(interner: I, param: ty::PlaceholderConst) -> Self; - fn new_unevaluated(interner: I, is_rigid: ty::IsRigid, uv: ty::UnevaluatedConst) -> Self; + fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_const: ty::AliasConst) -> Self; fn new_expr(interner: I, expr: I::ExprConst) -> Self; @@ -411,7 +411,7 @@ pub trait Term>: _ => None, }, ty::TermKind::Const(ct) => match ct.kind() { - ty::ConstKind::Unevaluated(_, uv) => Some(uv.into()), + ty::ConstKind::Alias(_, alias_const) => Some(alias_const.into()), _ => None, }, } @@ -424,7 +424,7 @@ pub trait Term>: _ => false, }, ty::TermKind::Const(ct) => match ct.kind() { - ty::ConstKind::Unevaluated(is_rigid, _) => is_rigid == ty::IsRigid::No, + ty::ConstKind::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No, _ => false, }, } diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 1c1fbcff0d928..6fd19f9362a9b 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -56,13 +56,12 @@ pub trait Interner: type CoroutineId: SpecificDefId; type AdtId: SpecificDefId; type ImplId: SpecificDefId; - type UnevaluatedConstId: SpecificDefId; + type AnonConstId: SpecificDefId; type TraitAssocTyId: SpecificDefId + Into + TryFrom; type TraitAssocConstId: SpecificDefId + Into - + Into + TryFrom; type TraitAssocTermId: SpecificDefId; type OpaqueTyId: SpecificDefId; @@ -75,19 +74,13 @@ pub trait Interner: + Into + TypeFoldable; type FreeTyAliasId: SpecificDefId + Into; - type FreeConstAliasId: SpecificDefId - + Into - + Into; + type FreeConstAliasId: SpecificDefId + Into; type FreeTermAliasId: SpecificDefId; type ImplOrTraitAssocTyId: SpecificDefId + Into; - type ImplOrTraitAssocConstId: SpecificDefId - + Into - + Into; + type ImplOrTraitAssocConstId: SpecificDefId + Into; type ImplOrTraitAssocTermId: SpecificDefId; type InherentAssocTyId: SpecificDefId + Into; - type InherentAssocConstId: SpecificDefId - + Into - + Into; + type InherentAssocConstId: SpecificDefId + Into; type InherentAssocTermId: SpecificDefId; type Span: Span; @@ -244,10 +237,7 @@ pub trait Interner: type AdtDef: AdtDef; fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef; - fn unevaluated_const_kind_from_def_id( - self, - def_id: Self::DefId, - ) -> ty::UnevaluatedConstKind; + fn alias_const_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasConstKind; // FIXME: remove in favor of explicit construction fn alias_term_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTermKind; @@ -519,7 +509,7 @@ declare_lift_into! { TraitId, Ty, Tys, - UnevaluatedConstId, + AnonConstId, } /// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter` diff --git a/compiler/rustc_type_ir/src/ir_print.rs b/compiler/rustc_type_ir/src/ir_print.rs index c6ab804d81c9f..f3bacff256d19 100644 --- a/compiler/rustc_type_ir/src/ir_print.rs +++ b/compiler/rustc_type_ir/src/ir_print.rs @@ -1,12 +1,12 @@ use std::fmt; +#[cfg(feature = "nightly")] +use crate::{AliasConst, ClosureKind}; use crate::{ AliasTerm, AliasTy, Binder, CoercePredicate, ExistentialProjection, ExistentialTraitRef, FnSig, HostEffectPredicate, Interner, NormalizesTo, OutlivesPredicate, PatternKind, Placeholder, ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef, }; -#[cfg(feature = "nightly")] -use crate::{ClosureKind, UnevaluatedConst}; pub trait IrPrint { fn print(t: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; @@ -100,7 +100,7 @@ mod into_diag_arg_impls { } } - impl IntoDiagArg for UnevaluatedConst { + impl IntoDiagArg for AliasConst { fn into_diag_arg(self, path: &mut Option) -> DiagArgValue { format!("{self:?}").into_diag_arg(path) } diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index d64cc2450eb19..1c532fef76ad3 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -227,17 +227,17 @@ impl Relate for ty::AliasTy { } } -impl Relate for ty::UnevaluatedConst { +impl Relate for ty::AliasConst { fn relate>( relation: &mut R, - a: ty::UnevaluatedConst, - b: ty::UnevaluatedConst, - ) -> RelateResult> { + a: ty::AliasConst, + b: ty::AliasConst, + ) -> RelateResult> { let cx = relation.cx(); if a.kind != b.kind { Err(TypeError::ConstMismatch(ExpectedFound::new( - Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), a), - Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), b), + Const::new_alias(cx, ty::IsRigid::yes_if_next_solver(cx), a), + Const::new_alias(cx, ty::IsRigid::yes_if_next_solver(cx), b), ))) } else { // FIXME(mgca): remove this @@ -245,7 +245,7 @@ impl Relate for ty::UnevaluatedConst { let args = relate_args_invariantly(relation, a.args, b.args)?; - Ok(ty::UnevaluatedConst::new(cx, a.kind, args)) + Ok(ty::AliasConst::new(cx, a.kind, args)) } } } @@ -546,7 +546,7 @@ pub fn structurally_relate_tys>( } /// Relates `a` and `b` structurally, calling the relation for all nested values. -/// Any semantic equality, e.g. of unevaluated consts, and inference variables have +/// Any semantic equality, e.g. of alias consts, and inference variables have /// to be handled by the caller. /// /// FIXME: This is not totally structural, which probably should be fixed. @@ -614,14 +614,11 @@ pub fn structurally_relate_consts>( // While this is slightly incorrect, it shouldn't matter for `min_const_generics` // and is the better alternative to waiting until `generic_const_exprs` can // be stabilized. - ( - ty::ConstKind::Unevaluated(is_rigid_a, au), - ty::ConstKind::Unevaluated(is_rigid_b, bu), - ) => { + (ty::ConstKind::Alias(is_rigid_a, au), ty::ConstKind::Alias(is_rigid_b, bu)) => { // Users shouldn't know about this so the mismatch should be caught // during development rather than presented as type error. debug_assert_eq!(is_rigid_a, is_rigid_b, "{a:?} != {b:?}"); - return Ok(Const::new_unevaluated(cx, is_rigid_a, relation.relate(au, bu)?)); + return Ok(Const::new_alias(cx, is_rigid_a, relation.relate(au, bu)?)); } (ty::ConstKind::Expr(ae), ty::ConstKind::Expr(be)) => { let expr = relation.relate(ae, be)?; diff --git a/compiler/rustc_type_ir/src/relate/combine.rs b/compiler/rustc_type_ir/src/relate/combine.rs index 76fa888147971..d5f9df2249df7 100644 --- a/compiler/rustc_type_ir/src/relate/combine.rs +++ b/compiler/rustc_type_ir/src/relate/combine.rs @@ -239,14 +239,13 @@ where Ok(a) } - ( - ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _), - ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _), - ) if (infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver()) => { + (ty::ConstKind::Alias(ty::IsRigid::Yes, _), ty::ConstKind::Alias(ty::IsRigid::Yes, _)) + if (infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver()) => + { structurally_relate_consts(relation, a, b) } - (ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..)) + (ty::ConstKind::Alias(..), _) | (_, ty::ConstKind::Alias(..)) if infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver() => { match relation.structurally_relate_aliases() { diff --git a/compiler/rustc_type_ir/src/term_kind.rs b/compiler/rustc_type_ir/src/term_kind.rs index 8a6c2c8231adf..aed634d4f3a21 100644 --- a/compiler/rustc_type_ir/src/term_kind.rs +++ b/compiler/rustc_type_ir/src/term_kind.rs @@ -60,9 +60,9 @@ pub enum AliasTermKind { /// Can always be normalized away. FreeTy { def_id: I::FreeTyAliasId }, - /// An unevaluated anonymous constants. - AnonConst { def_id: I::UnevaluatedConstId }, - /// An unevaluated const coming from an associated const. + /// An anonymous constant. + AnonConst { def_id: I::AnonConstId }, + /// A const alias coming from an associated const. ProjectionConst { def_id: I::TraitAssocConstId }, /// A top level const item not part of a trait or impl. FreeConst { def_id: I::FreeConstAliasId }, @@ -79,8 +79,8 @@ impl AliasTermKind { AliasTermKind::InherentConst { .. } => "inherent associated const", AliasTermKind::OpaqueTy { .. } => "opaque type", AliasTermKind::FreeTy { .. } => "type alias", - AliasTermKind::FreeConst { .. } => "unevaluated constant", - AliasTermKind::AnonConst { .. } => "unevaluated constant", + AliasTermKind::FreeConst { .. } => "const alias", + AliasTermKind::AnonConst { .. } => "anonymous constant", } } @@ -122,17 +122,13 @@ impl From> for AliasTermKind { } } -impl From> for AliasTermKind { - fn from(value: ty::UnevaluatedConstKind) -> Self { +impl From> for AliasTermKind { + fn from(value: ty::AliasConstKind) -> Self { match value { - ty::UnevaluatedConstKind::Projection { def_id } => { - AliasTermKind::ProjectionConst { def_id } - } - ty::UnevaluatedConstKind::Inherent { def_id } => { - AliasTermKind::InherentConst { def_id } - } - ty::UnevaluatedConstKind::Free { def_id } => AliasTermKind::FreeConst { def_id }, - ty::UnevaluatedConstKind::Anon { def_id } => AliasTermKind::AnonConst { def_id }, + ty::AliasConstKind::Projection { def_id } => AliasTermKind::ProjectionConst { def_id }, + ty::AliasConstKind::Inherent { def_id } => AliasTermKind::InherentConst { def_id }, + ty::AliasConstKind::Free { def_id } => AliasTermKind::FreeConst { def_id }, + ty::AliasConstKind::Anon { def_id } => AliasTermKind::AnonConst { def_id }, } } } @@ -189,24 +185,20 @@ impl AliasTerm { ty::AliasTy { kind, args: self.args, _use_alias_new_instead: () } } - pub fn expect_ct(self) -> ty::UnevaluatedConst { + pub fn expect_ct(self) -> ty::AliasConst { let kind = match self.kind { - AliasTermKind::InherentConst { def_id } => { - ty::UnevaluatedConstKind::Inherent { def_id } - } - AliasTermKind::FreeConst { def_id } => ty::UnevaluatedConstKind::Free { def_id }, - AliasTermKind::AnonConst { def_id } => ty::UnevaluatedConstKind::Anon { def_id }, - AliasTermKind::ProjectionConst { def_id } => { - ty::UnevaluatedConstKind::Projection { def_id } - } + AliasTermKind::InherentConst { def_id } => ty::AliasConstKind::Inherent { def_id }, + AliasTermKind::FreeConst { def_id } => ty::AliasConstKind::Free { def_id }, + AliasTermKind::AnonConst { def_id } => ty::AliasConstKind::Anon { def_id }, + AliasTermKind::ProjectionConst { def_id } => ty::AliasConstKind::Projection { def_id }, kind @ (AliasTermKind::ProjectionTy { .. } | AliasTermKind::InherentTy { .. } | AliasTermKind::OpaqueTy { .. } | AliasTermKind::FreeTy { .. }) => { - panic!("Cannot turn `{}` into `UnevaluatedConst`", kind.descr()) + panic!("Cannot turn `{}` into `AliasConst`", kind.descr()) } }; - ty::UnevaluatedConst { kind, args: self.args, _use_alias_new_instead: () } + ty::AliasConst { kind, args: self.args, _use_alias_new_instead: () } } pub fn to_term(self, interner: I, is_rigid: ty::IsRigid) -> I::Term { @@ -214,26 +206,18 @@ impl AliasTerm { Ty::new_alias(interner, is_rigid, ty::AliasTy::new_from_args(interner, kind, self.args)) .into() }; - let unevaluated_const = |kind| { - I::Const::new_unevaluated( - interner, - is_rigid, - ty::UnevaluatedConst::new(interner, kind, self.args), - ) - .into() + let alias_const = |kind| { + I::Const::new_alias(interner, is_rigid, ty::AliasConst::new(interner, kind, self.args)) + .into() }; match self.kind { - AliasTermKind::FreeConst { def_id } => { - unevaluated_const(ty::UnevaluatedConstKind::Free { def_id }) - } + AliasTermKind::FreeConst { def_id } => alias_const(ty::AliasConstKind::Free { def_id }), AliasTermKind::InherentConst { def_id } => { - unevaluated_const(ty::UnevaluatedConstKind::Inherent { def_id }) - } - AliasTermKind::AnonConst { def_id } => { - unevaluated_const(ty::UnevaluatedConstKind::Anon { def_id }) + alias_const(ty::AliasConstKind::Inherent { def_id }) } + AliasTermKind::AnonConst { def_id } => alias_const(ty::AliasConstKind::Anon { def_id }), AliasTermKind::ProjectionConst { def_id } => { - unevaluated_const(ty::UnevaluatedConstKind::Projection { def_id }) + alias_const(ty::AliasConstKind::Projection { def_id }) } AliasTermKind::ProjectionTy { def_id } => alias_ty(ty::Projection { def_id }), AliasTermKind::InherentTy { def_id } => alias_ty(ty::Inherent { def_id }), @@ -367,8 +351,8 @@ impl From> for AliasTerm { } } -impl From> for AliasTerm { - fn from(ty: ty::UnevaluatedConst) -> Self { +impl From> for AliasTerm { + fn from(ty: ty::AliasConst) -> Self { AliasTerm { args: ty.args, kind: AliasTermKind::from(ty.kind), _use_alias_new_instead: () } } } diff --git a/compiler/rustc_type_ir/src/ty/alias.rs b/compiler/rustc_type_ir/src/ty/alias.rs index 0f99c8d787ee7..10fd4c6a25394 100644 --- a/compiler/rustc_type_ir/src/ty/alias.rs +++ b/compiler/rustc_type_ir/src/ty/alias.rs @@ -5,7 +5,7 @@ use rustc_type_ir_macros::{ GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, }; -use crate::{AliasTermKind, AliasTyKind, Interner, UnevaluatedConstKind}; +use crate::{AliasConstKind, AliasTermKind, AliasTyKind, Interner}; /// Represents an alias of a type, constant, or other term-like item. /// @@ -55,4 +55,4 @@ pub type ProjectionAliasTy = Alias::TraitAssocTyId>; pub type InherentAliasTy = Alias::InherentAssocTyId>; pub type OpaqueAliasTy = Alias::OpaqueTyId>; pub type FreeAliasTy = Alias::FreeTyAliasId>; -pub type UnevaluatedConst = Alias>; +pub type AliasConst = Alias>; diff --git a/compiler/rustc_type_ir/src/walk.rs b/compiler/rustc_type_ir/src/walk.rs index 196c14d5197eb..d2442358b13cb 100644 --- a/compiler/rustc_type_ir/src/walk.rs +++ b/compiler/rustc_type_ir/src/walk.rs @@ -160,7 +160,7 @@ fn push_inner(stack: &mut TypeWalkerStack, parent: I::GenericArg ty::ConstKind::Value(cv) => stack.push(cv.ty().into()), ty::ConstKind::Expr(expr) => stack.extend(expr.args().iter().rev()), - ty::ConstKind::Unevaluated(_, ct) => { + ty::ConstKind::Alias(_, ct) => { stack.extend(ct.args.iter().rev()); } }, diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index ec5c9a66d4b65..554bcb2621ac6 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -350,8 +350,8 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String { match n.kind() { - ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, .. }) => match kind { - ty::UnevaluatedConstKind::Projection { def_id } => { + ty::ConstKind::Alias(_, ty::AliasConst { kind, .. }) => match kind { + ty::AliasConstKind::Projection { def_id } => { if let Some(local_def_id) = def_id.as_local() && let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id) { @@ -360,9 +360,9 @@ pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String { n.to_string() } } - ty::UnevaluatedConstKind::Inherent { def_id } - | ty::UnevaluatedConstKind::Free { def_id } - | ty::UnevaluatedConstKind::Anon { def_id } => { + ty::AliasConstKind::Inherent { def_id } + | ty::AliasConstKind::Free { def_id } + | ty::AliasConstKind::Anon { def_id } => { if let Some(local_def_id) = def_id.as_local() && let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id) { diff --git a/tests/mir-opt/issue_99325.main.built.after.32bit.mir b/tests/mir-opt/issue_99325.main.built.after.32bit.mir index 8989903939d42..4a028248d6633 100644 --- a/tests/mir-opt/issue_99325.main.built.after.32bit.mir +++ b/tests/mir-opt/issue_99325.main.built.after.32bit.mir @@ -2,7 +2,7 @@ | User Type Annotations | 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">} -| 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">} +| 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">} | fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/issue_99325.main.built.after.64bit.mir b/tests/mir-opt/issue_99325.main.built.after.64bit.mir index 8989903939d42..4a028248d6633 100644 --- a/tests/mir-opt/issue_99325.main.built.after.64bit.mir +++ b/tests/mir-opt/issue_99325.main.built.after.64bit.mir @@ -2,7 +2,7 @@ | User Type Annotations | 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">} -| 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">} +| 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">} | fn main() -> () { let mut _0: (); diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs index a7e46ad877e72..b3dfef1cb26ca 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs @@ -5,6 +5,6 @@ #![expect(incomplete_features)] type const A: u8 = A; -//~^ ERROR overflow normalizing the unevaluated constant `A` +//~^ ERROR overflow normalizing the const alias `A` fn main() {} diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr index 47653dd1896f7..07b4ca43eb77b 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow normalizing the unevaluated constant `A` +error[E0275]: overflow normalizing the const alias `A` --> $DIR/cyclic-type-const-151251.rs:7:1 | LL | type const A: u8 = A; diff --git a/tests/ui/const-generics/mgca/type_const-recursive.rs b/tests/ui/const-generics/mgca/type_const-recursive.rs index ebaab51bbc3b6..0791325d603be 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.rs +++ b/tests/ui/const-generics/mgca/type_const-recursive.rs @@ -3,6 +3,6 @@ type const A: u8 = A; -//~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275] +//~^ ERROR: overflow normalizing the const alias `A` [E0275] fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-recursive.stderr b/tests/ui/const-generics/mgca/type_const-recursive.stderr index d21ccb22bc90b..f9e0965dc5412 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.stderr +++ b/tests/ui/const-generics/mgca/type_const-recursive.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow normalizing the unevaluated constant `A` +error[E0275]: overflow normalizing the const alias `A` --> $DIR/type_const-recursive.rs:5:1 | LL | type const A: u8 = A; diff --git a/tests/ui/offset-of/inside-array-length.stderr b/tests/ui/offset-of/inside-array-length.stderr index 0305603c1f547..0c430f0424ced 100644 --- a/tests/ui/offset-of/inside-array-length.stderr +++ b/tests/ui/offset-of/inside-array-length.stderr @@ -37,7 +37,7 @@ LL | fn foo<'a, T: 'a>(_: [(); std::mem::offset_of!((T,), 0)]) {} = note: ...which requires caching mir of `foo::{constant#0}` for CTFE... = note: ...which requires elaborating drops for `foo::{constant#0}`... = note: ...which requires borrow-checking `foo::{constant#0}`... - = 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: [] }`... + = 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: [] }`... = note: ...which again requires evaluating type-level constant, completing the cycle = note: cycle used when normalizing `inside_array_length::::foo::{constant#0}` = note: for more information, see and