| author | bors <bors@rust-lang.org> 2026-06-27 11:04:54 UTC |
| committer | bors <bors@rust-lang.org> 2026-06-27 11:04:54 UTC |
| log | cb41b6d3daa0c1ad088a8802a6d8700c61290865 |
| tree | 658da1cea11084c57bc938a766d014c1d2592eaa |
| parent | 267c4057bad01b0cf9733081d170c1358b4b3674 |
| parent | c502825eefefcf21c152991de428948f6be609da |
Rename UnevaluatedConst to AliasConst
refer: https://github.com/rust-lang/project-const-generics/issues/115
r? @khyperia
I only renamed the type system version to `AliasConst`/`AliasConstKind`. I did not rename MIR’s `UnevaluatedConst`, it currently holds direct def_id instead of kind variant we have in type-system. I also left `rustc_public`’s `UnevaluatedConst` unchanged.75 files changed, 465 insertions(+), 517 deletions(-)
compiler/rustc_borrowck/src/type_check/mod.rs+9-7| ... | ... | @@ -1759,13 +1759,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { |
| 1759 | 1759 | let tcx = self.tcx(); |
| 1760 | 1760 | let maybe_uneval = match constant.const_ { |
| 1761 | 1761 | Const::Ty(_, ct) => match ct.kind() { |
| 1762 | ty::ConstKind::Unevaluated(_, uv) => match uv.kind { | |
| 1763 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 1764 | | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 1765 | | ty::UnevaluatedConstKind::Free { def_id } | |
| 1766 | | ty::UnevaluatedConstKind::Anon { def_id } => { | |
| 1767 | Some(UnevaluatedConst { def: def_id, args: uv.args, promoted: None }) | |
| 1768 | } | |
| 1762 | ty::ConstKind::Alias(_, alias_const) => match alias_const.kind { | |
| 1763 | ty::AliasConstKind::Projection { def_id } | |
| 1764 | | ty::AliasConstKind::Inherent { def_id } | |
| 1765 | | ty::AliasConstKind::Free { def_id } | |
| 1766 | | ty::AliasConstKind::Anon { def_id } => Some(UnevaluatedConst { | |
| 1767 | def: def_id, | |
| 1768 | args: alias_const.args, | |
| 1769 | promoted: None, | |
| 1770 | }), | |
| 1769 | 1771 | }, |
| 1770 | 1772 | _ => None, |
| 1771 | 1773 | }, |
compiler/rustc_const_eval/src/check_consts/qualifs.rs+3-3| ... | ... | @@ -344,13 +344,13 @@ where |
| 344 | 344 | let uneval = match constant.const_ { |
| 345 | 345 | Const::Ty(_, ct) => match ct.kind() { |
| 346 | 346 | ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None, |
| 347 | // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`). | |
| 348 | ty::ConstKind::Unevaluated(_, _) => None, | |
| 347 | // Alias consts in MIR bodies don't have associated MIR (e.g. `type const`). | |
| 348 | ty::ConstKind::Alias(_, _) => None, | |
| 349 | 349 | // FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly |
| 350 | 350 | // strict, and if instead we should be doing some kind of value-based analysis. |
| 351 | 351 | ty::ConstKind::Value(_) => None, |
| 352 | 352 | _ => bug!( |
| 353 | "expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}", | |
| 353 | "expected ConstKind::Param, ConstKind::Value, ConstKind::Alias, or ConstKind::Error here, found {:?}", | |
| 354 | 354 | ct |
| 355 | 355 | ), |
| 356 | 356 | }, |
compiler/rustc_hir_analysis/src/check/check.rs+2-2| ... | ... | @@ -778,8 +778,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), |
| 778 | 778 | if has_default { |
| 779 | 779 | // need to store default and type of default |
| 780 | 780 | let ct = tcx.const_param_default(param.def_id).skip_binder(); |
| 781 | if let ty::ConstKind::Unevaluated(_, uv) = ct.kind() | |
| 782 | && let Some(def_id) = uv.kind.opt_def_id() | |
| 781 | if let ty::ConstKind::Alias(_, alias_const) = ct.kind() | |
| 782 | && let Some(def_id) = alias_const.kind.opt_def_id() | |
| 783 | 783 | { |
| 784 | 784 | tcx.ensure_ok().type_of(def_id); |
| 785 | 785 | } |
compiler/rustc_hir_analysis/src/check/wfcheck.rs+4-2| ... | ... | @@ -1488,7 +1488,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: |
| 1488 | 1488 | // be sure if it will error or not as user might always specify the other. |
| 1489 | 1489 | // FIXME(generic_const_exprs): This is incorrect when dealing with unused const params. |
| 1490 | 1490 | // E.g: `struct Foo<const N: usize, const M: usize = { 1 - 2 }>;`. Here, we should |
| 1491 | // eagerly error but we don't as we have `ConstKind::Unevaluated(.., [N, M])`. | |
| 1491 | // eagerly error but we don't as we have `ConstKind::Alias(.., [N, M])`. | |
| 1492 | 1492 | if !default.has_param() { |
| 1493 | 1493 | wfcx.register_wf_obligation( |
| 1494 | 1494 | tcx.def_span(param.def_id), |
| ... | ... | @@ -1509,7 +1509,9 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: |
| 1509 | 1509 | | ty::ConstKind::Bound(_, _) => unreachable!(), |
| 1510 | 1510 | ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => continue, |
| 1511 | 1511 | ty::ConstKind::Value(cv) => cv.ty, |
| 1512 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 1512 | ty::ConstKind::Alias(_, alias_const) => { | |
| 1513 | alias_const.type_of(infcx.tcx).skip_norm_wip() | |
| 1514 | } | |
| 1513 | 1515 | ty::ConstKind::Param(param_ct) => { |
| 1514 | 1516 | param_ct.find_const_ty_from_env(wfcx.param_env) |
| 1515 | 1517 | } |
compiler/rustc_hir_analysis/src/collect/generics_of.rs+2-2| ... | ... | @@ -124,11 +124,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { |
| 124 | 124 | // ^ parent_def_id |
| 125 | 125 | // |
| 126 | 126 | // then we only want to return generics for params to the left of `N`. If we don't do that we |
| 127 | // end up with that const looking like: `ty::ConstKind::Unevaluated(def_id, args: [N#0])`. | |
| 127 | // end up with that const looking like: `ty::ConstKind::Alias(def_id, args: [N#0])`. | |
| 128 | 128 | // |
| 129 | 129 | // This causes ICEs (#86580) when building the args for Foo in `fn foo() -> Foo { .. }` as |
| 130 | 130 | // we instantiate the defaults with the partially built args when we build the args. Instantiating |
| 131 | // the `N#0` on the unevaluated const indexes into the empty args we're in the process of building. | |
| 131 | // the `N#0` on the alias const indexes into the empty args we're in the process of building. | |
| 132 | 132 | // |
| 133 | 133 | // We fix this by having this function return the parent's generics ourselves and truncating the |
| 134 | 134 | // generics to only include non-forward declared params (with the exception of the `Self` ty) |
compiler/rustc_hir_analysis/src/collect/predicates_of.rs+6-6| ... | ... | @@ -415,8 +415,8 @@ fn const_evaluatable_predicates_of<'tcx>( |
| 415 | 415 | preds: FxIndexSet<(ty::Clause<'tcx>, Span)>, |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::UnevaluatedConstKind<'_>) -> bool { | |
| 419 | let ty::UnevaluatedConstKind::Anon { def_id } = kind else { return false }; | |
| 418 | fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::AliasConstKind<'_>) -> bool { | |
| 419 | let ty::AliasConstKind::Anon { def_id } = kind else { return false }; | |
| 420 | 420 | let Some(local) = def_id.as_local() else { return false }; |
| 421 | 421 | |
| 422 | 422 | let hir_id = tcx.local_def_id_to_hir_id(local); |
| ... | ... | @@ -433,8 +433,8 @@ fn const_evaluatable_predicates_of<'tcx>( |
| 433 | 433 | |
| 434 | 434 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> { |
| 435 | 435 | fn visit_const(&mut self, c: ty::Const<'tcx>) { |
| 436 | if let ty::ConstKind::Unevaluated(_, uv) = c.kind() { | |
| 437 | if is_const_param_default(self.tcx, uv.kind) { | |
| 436 | if let ty::ConstKind::Alias(_, alias_const) = c.kind() { | |
| 437 | if is_const_param_default(self.tcx, alias_const.kind) { | |
| 438 | 438 | // Do not look into const param defaults, |
| 439 | 439 | // these get checked when they are actually instantiated. |
| 440 | 440 | // |
| ... | ... | @@ -446,11 +446,11 @@ fn const_evaluatable_predicates_of<'tcx>( |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // Skip type consts as mGCA doesn't support evaluatable clauses. |
| 449 | if uv.kind.is_type_const(self.tcx) { | |
| 449 | if alias_const.kind.is_type_const(self.tcx) { | |
| 450 | 450 | return; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | let span = uv.kind.def_span(self.tcx); | |
| 453 | let span = alias_const.kind.def_span(self.tcx); | |
| 454 | 454 | self.preds.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span)); |
| 455 | 455 | } |
| 456 | 456 | } |
compiler/rustc_hir_analysis/src/constrained_generic_params.rs+1-1| ... | ... | @@ -93,7 +93,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector { |
| 93 | 93 | |
| 94 | 94 | fn visit_const(&mut self, c: ty::Const<'tcx>) { |
| 95 | 95 | match c.kind() { |
| 96 | ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => { | |
| 96 | ty::ConstKind::Alias(..) if !self.include_nonconstraining => { | |
| 97 | 97 | // Constant expressions are not injective in general. |
| 98 | 98 | return; |
| 99 | 99 | } |
compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs+10-14| ... | ... | @@ -1402,7 +1402,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1402 | 1402 | if let Some(def_id) = alias_ct.kind.opt_def_id() { |
| 1403 | 1403 | self.require_type_const_attribute(def_id, span)?; |
| 1404 | 1404 | } |
| 1405 | let ct = Const::new_unevaluated(tcx, ty::IsRigid::No, alias_ct); | |
| 1405 | let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct); | |
| 1406 | 1406 | let ct = self.check_param_uses_if_mcg(ct, span, false); |
| 1407 | 1407 | Ok(ct) |
| 1408 | 1408 | } |
| ... | ... | @@ -1865,12 +1865,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1865 | 1865 | ty::AssocTag::Const, |
| 1866 | 1866 | )?; |
| 1867 | 1867 | self.require_type_const_attribute(item_def_id, span)?; |
| 1868 | let uv = ty::UnevaluatedConst::new( | |
| 1868 | let alias_const = ty::AliasConst::new( | |
| 1869 | 1869 | tcx, |
| 1870 | ty::UnevaluatedConstKind::new_from_def_id(tcx, item_def_id), | |
| 1870 | ty::AliasConstKind::new_from_def_id(tcx, item_def_id), | |
| 1871 | 1871 | item_args, |
| 1872 | 1872 | ); |
| 1873 | Ok(Const::new_unevaluated(tcx, ty::IsRigid::No, uv)) | |
| 1873 | Ok(Const::new_alias(tcx, ty::IsRigid::No, alias_const)) | |
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | 1876 | /// Lower a [resolved][hir::QPath::Resolved] (type-level) associated item path. |
| ... | ... | @@ -2772,14 +2772,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2772 | 2772 | let _ = self |
| 2773 | 2773 | .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None); |
| 2774 | 2774 | let args = self.lower_generic_args_of_path_segment(span, did, segment); |
| 2775 | ty::Const::new_unevaluated( | |
| 2775 | ty::Const::new_alias( | |
| 2776 | 2776 | tcx, |
| 2777 | 2777 | ty::IsRigid::No, |
| 2778 | ty::UnevaluatedConst::new( | |
| 2779 | tcx, | |
| 2780 | ty::UnevaluatedConstKind::new_from_def_id(tcx, did), | |
| 2781 | args, | |
| 2782 | ), | |
| 2778 | ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, did), args), | |
| 2783 | 2779 | ) |
| 2784 | 2780 | } |
| 2785 | 2781 | Res::Def(kind @ DefKind::Ctor(ctor_of, CtorKind::Const), did) => { |
| ... | ... | @@ -2915,7 +2911,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2915 | 2911 | self.check_param_uses_if_mcg(ct, span, false) |
| 2916 | 2912 | } |
| 2917 | 2913 | |
| 2918 | /// Literals are eagerly converted to a constant, everything else becomes `Unevaluated`. | |
| 2914 | /// Literals are eagerly converted to a constant, everything else becomes `ConstKind::Alias`. | |
| 2919 | 2915 | #[instrument(skip(self), level = "debug")] |
| 2920 | 2916 | fn lower_const_arg_anon(&self, anon: &AnonConst) -> Const<'tcx> { |
| 2921 | 2917 | let tcx = self.tcx(); |
| ... | ... | @@ -2930,12 +2926,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2930 | 2926 | |
| 2931 | 2927 | match self.try_lower_anon_const_lit(ty, expr) { |
| 2932 | 2928 | Some(v) => v, |
| 2933 | None => ty::Const::new_unevaluated( | |
| 2929 | None => ty::Const::new_alias( | |
| 2934 | 2930 | tcx, |
| 2935 | 2931 | ty::IsRigid::No, |
| 2936 | ty::UnevaluatedConst::new( | |
| 2932 | ty::AliasConst::new( | |
| 2937 | 2933 | tcx, |
| 2938 | ty::UnevaluatedConstKind::Anon { def_id: anon.def_id.to_def_id() }, | |
| 2934 | ty::AliasConstKind::Anon { def_id: anon.def_id.to_def_id() }, | |
| 2939 | 2935 | ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()), |
| 2940 | 2936 | ), |
| 2941 | 2937 | ), |
compiler/rustc_hir_analysis/src/variance/constraints.rs+2-2| ... | ... | @@ -408,8 +408,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { |
| 408 | 408 | debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance); |
| 409 | 409 | |
| 410 | 410 | match &c.kind() { |
| 411 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 412 | self.add_constraints_from_invariant_args(current, uv.args, variance); | |
| 411 | ty::ConstKind::Alias(_, alias_const) => { | |
| 412 | self.add_constraints_from_invariant_args(current, alias_const.args, variance); | |
| 413 | 413 | } |
| 414 | 414 | _ => {} |
| 415 | 415 | } |
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs+1-1| ... | ... | @@ -1488,7 +1488,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1488 | 1488 | let ct = self.resolve_vars_with_obligations(ct); |
| 1489 | 1489 | |
| 1490 | 1490 | if self.next_trait_solver() |
| 1491 | && let ty::ConstKind::Unevaluated(..) = ct.kind() | |
| 1491 | && let ty::ConstKind::Alias(..) = ct.kind() | |
| 1492 | 1492 | { |
| 1493 | 1493 | // We need to use a separate variable here as otherwise the temporary for |
| 1494 | 1494 | // `self.fulfillment_cx.borrow_mut()` is alive in the `Err` branch, resulting |
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs+1-1| ... | ... | @@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 174 | 174 | ty::ConstKind::Param(_) |
| 175 | 175 | | ty::ConstKind::Expr(_) |
| 176 | 176 | | ty::ConstKind::Placeholder(_) |
| 177 | | ty::ConstKind::Unevaluated(_, _) => enforce_copy_bound(element, element_ty), | |
| 177 | | ty::ConstKind::Alias(_, _) => enforce_copy_bound(element, element_ty), | |
| 178 | 178 | |
| 179 | 179 | ty::ConstKind::Bound(_, _) | ty::ConstKind::Infer(_) | ty::ConstKind::Error(_) => { |
| 180 | 180 | unreachable!() |
compiler/rustc_infer/src/infer/freshen.rs+1-1| ... | ... | @@ -158,7 +158,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> { |
| 158 | 158 | |
| 159 | 159 | ty::ConstKind::Param(_) |
| 160 | 160 | | ty::ConstKind::Value(_) |
| 161 | | ty::ConstKind::Unevaluated(..) | |
| 161 | | ty::ConstKind::Alias(..) | |
| 162 | 162 | | ty::ConstKind::Expr(..) |
| 163 | 163 | | ty::ConstKind::Error(_) => ct.super_fold_with(self), |
| 164 | 164 | } |
compiler/rustc_infer/src/infer/mod.rs+1-1| ... | ... | @@ -1266,7 +1266,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 1266 | 1266 | ty::ConstKind::Param(_) |
| 1267 | 1267 | | ty::ConstKind::Bound(_, _) |
| 1268 | 1268 | | ty::ConstKind::Placeholder(_) |
| 1269 | | ty::ConstKind::Unevaluated(_, _) | |
| 1269 | | ty::ConstKind::Alias(_, _) | |
| 1270 | 1270 | | ty::ConstKind::Value(_) |
| 1271 | 1271 | | ty::ConstKind::Error(_) |
| 1272 | 1272 | | ty::ConstKind::Expr(_) => ct, |
compiler/rustc_infer/src/infer/relate/generalize.rs+10-10| ... | ... | @@ -77,7 +77,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 77 | 77 | /// would result in an infinite type as we continuously replace an inference variable |
| 78 | 78 | /// in `ct` with `ct` itself. |
| 79 | 79 | /// |
| 80 | /// This is especially important as unevaluated consts use their parents generics. | |
| 80 | /// This is especially important as alias consts use their parents generics. | |
| 81 | 81 | /// They therefore often contain unused args, making these errors far more likely. |
| 82 | 82 | /// |
| 83 | 83 | /// A good example of this is the following: |
| ... | ... | @@ -95,7 +95,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 95 | 95 | /// } |
| 96 | 96 | /// ``` |
| 97 | 97 | /// |
| 98 | /// Here `3 + 4` ends up as `ConstKind::Unevaluated` which uses the generics | |
| 98 | /// Here `3 + 4` ends up as `ConstKind::Alias` which uses the generics | |
| 99 | 99 | /// of `fn bind` (meaning that its args contain `N`). |
| 100 | 100 | /// |
| 101 | 101 | /// `bind(arr)` now infers that the type of `arr` must be `[u8; N]`. |
| ... | ... | @@ -112,8 +112,8 @@ impl<'tcx> InferCtxt<'tcx> { |
| 112 | 112 | target_vid: ty::ConstVid, |
| 113 | 113 | source_ct: ty::Const<'tcx>, |
| 114 | 114 | ) -> RelateResult<'tcx, ()> { |
| 115 | // FIXME(generic_const_exprs): Occurs check failures for unevaluated | |
| 116 | // constants and generic expressions are not yet handled correctly. | |
| 115 | // FIXME(generic_const_exprs): Occurs check failures for alias consts | |
| 116 | // and generic expressions are not yet handled correctly. | |
| 117 | 117 | debug_assert!( |
| 118 | 118 | self.inner.borrow_mut().const_unification_table().probe_value(target_vid).is_unknown() |
| 119 | 119 | ); |
| ... | ... | @@ -752,7 +752,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { |
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | } |
| 755 | // FIXME: Unevaluated constants are also not rigid, so the current | |
| 755 | // FIXME: Alias consts are also not rigid, so the current | |
| 756 | 756 | // approach of always relating them structurally is incomplete. |
| 757 | 757 | // |
| 758 | 758 | // FIXME: replace the StructurallyRelateAliases::Yes branch with |
| ... | ... | @@ -760,26 +760,26 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { |
| 760 | 760 | // |
| 761 | 761 | // We only need to be careful with potentially normalizeable |
| 762 | 762 | // aliases here. See `generalize_alias_term` for more information. |
| 763 | ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => { | |
| 763 | ty::ConstKind::Alias(ty::IsRigid::No, alias_const) => { | |
| 764 | 764 | match self.structurally_relate_aliases { |
| 765 | 765 | // Hack: Fall back to old behavior if GCE is enabled (it used to just be the Yes |
| 766 | 766 | // path), as doing this new No path breaks some GCE things. I expect GCE to be |
| 767 | 767 | // ripped out soon so this shouldn't matter soon. |
| 768 | 768 | StructurallyRelateAliases::No if !tcx.features().generic_const_exprs() => { |
| 769 | self.generalize_alias_term(uv.into()).map(|v| v.expect_const()) | |
| 769 | self.generalize_alias_term(alias_const.into()).map(|v| v.expect_const()) | |
| 770 | 770 | } |
| 771 | 771 | _ => { |
| 772 | let ty::UnevaluatedConst { kind, args, .. } = uv; | |
| 772 | let ty::AliasConst { kind, args, .. } = alias_const; | |
| 773 | 773 | let args = self.relate_with_variance( |
| 774 | 774 | ty::Invariant, |
| 775 | 775 | ty::VarianceDiagInfo::default(), |
| 776 | 776 | args, |
| 777 | 777 | args, |
| 778 | 778 | )?; |
| 779 | Ok(ty::Const::new_unevaluated( | |
| 779 | Ok(ty::Const::new_alias( | |
| 780 | 780 | tcx, |
| 781 | 781 | ty::IsRigid::No, |
| 782 | ty::UnevaluatedConst::new(tcx, kind, args), | |
| 782 | ty::AliasConst::new(tcx, kind, args), | |
| 783 | 783 | )) |
| 784 | 784 | } |
| 785 | 785 | } |
compiler/rustc_middle/src/mir/consts.rs+3-7| ... | ... | @@ -221,7 +221,7 @@ pub enum Const<'tcx> { |
| 221 | 221 | |
| 222 | 222 | /// An unevaluated mir constant which is not part of the type system. |
| 223 | 223 | /// |
| 224 | /// Note that `Ty(ty::ConstKind::Unevaluated)` and this variant are *not* identical! `Ty` will | |
| 224 | /// Note that `Ty(ty::ConstKind::Alias)` and this variant are *not* identical! `Ty` will | |
| 225 | 225 | /// always flow through a valtree, so all data not captured in the valtree is lost. This variant |
| 226 | 226 | /// directly uses the evaluated result of the given constant, including e.g. data stored in |
| 227 | 227 | /// padding. |
| ... | ... | @@ -472,13 +472,9 @@ pub struct UnevaluatedConst<'tcx> { |
| 472 | 472 | |
| 473 | 473 | impl<'tcx> UnevaluatedConst<'tcx> { |
| 474 | 474 | #[inline] |
| 475 | pub fn shrink(self, tcx: TyCtxt<'tcx>) -> ty::UnevaluatedConst<'tcx> { | |
| 475 | pub fn shrink(self, tcx: TyCtxt<'tcx>) -> ty::AliasConst<'tcx> { | |
| 476 | 476 | assert_eq!(self.promoted, None); |
| 477 | ty::UnevaluatedConst::new( | |
| 478 | tcx, | |
| 479 | ty::UnevaluatedConstKind::new_from_def_id(tcx, self.def), | |
| 480 | self.args, | |
| 481 | ) | |
| 477 | ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, self.def), self.args) | |
| 482 | 478 | } |
| 483 | 479 | } |
| 484 | 480 |
compiler/rustc_middle/src/mir/interpret/queries.rs+5-5| ... | ... | @@ -90,7 +90,7 @@ impl<'tcx> TyCtxt<'tcx> { |
| 90 | 90 | pub fn const_eval_resolve_for_typeck( |
| 91 | 91 | self, |
| 92 | 92 | typing_env: ty::TypingEnv<'tcx>, |
| 93 | ct: ty::UnevaluatedConst<'tcx>, | |
| 93 | ct: ty::AliasConst<'tcx>, | |
| 94 | 94 | span: Span, |
| 95 | 95 | ) -> ConstToValTreeResult<'tcx> { |
| 96 | 96 | // Cannot resolve `Unevaluated` constants that contain inference |
| ... | ... | @@ -104,10 +104,10 @@ impl<'tcx> TyCtxt<'tcx> { |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | let def_id = match ct.kind { |
| 107 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 108 | | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 109 | | ty::UnevaluatedConstKind::Free { def_id } | |
| 110 | | ty::UnevaluatedConstKind::Anon { def_id } => def_id, | |
| 107 | ty::AliasConstKind::Projection { def_id } | |
| 108 | | ty::AliasConstKind::Inherent { def_id } | |
| 109 | | ty::AliasConstKind::Free { def_id } | |
| 110 | | ty::AliasConstKind::Anon { def_id } => def_id, | |
| 111 | 111 | }; |
| 112 | 112 | |
| 113 | 113 | let cid = match ty::Instance::try_resolve(self, typing_env, def_id, ct.args) { |
compiler/rustc_middle/src/mir/pretty.rs+7-9| ... | ... | @@ -1491,16 +1491,14 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { |
| 1491 | 1491 | let val = match const_ { |
| 1492 | 1492 | Const::Ty(_, ct) => match ct.kind() { |
| 1493 | 1493 | ty::ConstKind::Param(p) => format!("ty::Param({p})"), |
| 1494 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 1495 | let kind = match uv.kind { | |
| 1496 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 1497 | | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 1498 | | ty::UnevaluatedConstKind::Free { def_id } | |
| 1499 | | ty::UnevaluatedConstKind::Anon { def_id } => { | |
| 1500 | self.tcx.def_path_str(def_id) | |
| 1501 | } | |
| 1494 | ty::ConstKind::Alias(_, alias_const) => { | |
| 1495 | let kind = match alias_const.kind { | |
| 1496 | ty::AliasConstKind::Projection { def_id } | |
| 1497 | | ty::AliasConstKind::Inherent { def_id } | |
| 1498 | | ty::AliasConstKind::Free { def_id } | |
| 1499 | | ty::AliasConstKind::Anon { def_id } => self.tcx.def_path_str(def_id), | |
| 1502 | 1500 | }; |
| 1503 | format!("ty::Unevaluated({}, {:?})", kind, uv.args) | |
| 1501 | format!("ty::AliasConst({}, {:?})", kind, alias_const.args) | |
| 1504 | 1502 | } |
| 1505 | 1503 | ty::ConstKind::Value(cv) => { |
| 1506 | 1504 | format!("ty::Valtree({})", fmt_valtree(&cv)) |
compiler/rustc_middle/src/ty/abstract_const.rs+3-3| ... | ... | @@ -52,13 +52,13 @@ impl<'tcx> TyCtxt<'tcx> { |
| 52 | 52 | } |
| 53 | 53 | fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> { |
| 54 | 54 | let ct = match c.kind() { |
| 55 | ty::ConstKind::Unevaluated(_, uv) | |
| 56 | if let Some(def_id) = uv.kind.opt_def_id() => | |
| 55 | ty::ConstKind::Alias(_, alias_const) | |
| 56 | if let Some(def_id) = alias_const.kind.opt_def_id() => | |
| 57 | 57 | { |
| 58 | 58 | match self.tcx.thir_abstract_const(def_id) { |
| 59 | 59 | Err(e) => ty::Const::new_error(self.tcx, e), |
| 60 | 60 | Ok(Some(bac)) => { |
| 61 | let args = self.tcx.erase_and_anonymize_regions(uv.args); | |
| 61 | let args = self.tcx.erase_and_anonymize_regions(alias_const.args); | |
| 62 | 62 | let bac = bac.instantiate(self.tcx, args).skip_norm_wip(); |
| 63 | 63 | return bac.fold_with(self); |
| 64 | 64 | } |
compiler/rustc_middle/src/ty/consts.rs+9-9| ... | ... | @@ -21,8 +21,8 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed}; |
| 21 | 21 | pub use valtree::*; |
| 22 | 22 | |
| 23 | 23 | pub type ConstKind<'tcx> = ir::ConstKind<TyCtxt<'tcx>>; |
| 24 | pub type UnevaluatedConst<'tcx> = ir::UnevaluatedConst<TyCtxt<'tcx>>; | |
| 25 | pub type UnevaluatedConstKind<'tcx> = ir::UnevaluatedConstKind<TyCtxt<'tcx>>; | |
| 24 | pub type AliasConst<'tcx> = ir::AliasConst<TyCtxt<'tcx>>; | |
| 25 | pub type AliasConstKind<'tcx> = ir::AliasConstKind<TyCtxt<'tcx>>; | |
| 26 | 26 | |
| 27 | 27 | #[cfg(target_pointer_width = "64")] |
| 28 | 28 | rustc_data_structures::static_assert_size!(ConstKind<'_>, 32); |
| ... | ... | @@ -107,12 +107,12 @@ impl<'tcx> Const<'tcx> { |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | #[inline] |
| 110 | pub fn new_unevaluated( | |
| 110 | pub fn new_alias( | |
| 111 | 111 | tcx: TyCtxt<'tcx>, |
| 112 | 112 | is_rigid: ty::IsRigid, |
| 113 | uv: ty::UnevaluatedConst<'tcx>, | |
| 113 | alias_const: ty::AliasConst<'tcx>, | |
| 114 | 114 | ) -> Const<'tcx> { |
| 115 | Const::new(tcx, ty::ConstKind::Unevaluated(is_rigid, uv)) | |
| 115 | Const::new(tcx, ty::ConstKind::Alias(is_rigid, alias_const)) | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | #[inline] |
| ... | ... | @@ -157,7 +157,7 @@ impl<'tcx> Const<'tcx> { |
| 157 | 157 | true |
| 158 | 158 | } |
| 159 | 159 | ty::ConstKind::Infer(_) |
| 160 | | ty::ConstKind::Unevaluated(..) | |
| 160 | | ty::ConstKind::Alias(..) | |
| 161 | 161 | | ty::ConstKind::Value(_) |
| 162 | 162 | | ty::ConstKind::Error(_) |
| 163 | 163 | | ty::ConstKind::Expr(_) => false, |
| ... | ... | @@ -194,12 +194,12 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> { |
| 194 | 194 | Const::new_placeholder(tcx, placeholder) |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | fn new_unevaluated( | |
| 197 | fn new_alias( | |
| 198 | 198 | interner: TyCtxt<'tcx>, |
| 199 | 199 | is_rigid: ty::IsRigid, |
| 200 | uv: ty::UnevaluatedConst<'tcx>, | |
| 200 | alias_const: ty::AliasConst<'tcx>, | |
| 201 | 201 | ) -> Self { |
| 202 | Const::new_unevaluated(interner, is_rigid, uv) | |
| 202 | Const::new_alias(interner, is_rigid, alias_const) | |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | fn new_expr(interner: TyCtxt<'tcx>, expr: ty::Expr<'tcx>) -> Self { |
compiler/rustc_middle/src/ty/context/impl_interner.rs+7-10| ... | ... | @@ -41,7 +41,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 41 | 41 | type CoroutineId = DefId; |
| 42 | 42 | type AdtId = DefId; |
| 43 | 43 | type ImplId = DefId; |
| 44 | type UnevaluatedConstId = DefId; | |
| 44 | type AnonConstId = DefId; | |
| 45 | 45 | type TraitAssocTyId = DefId; |
| 46 | 46 | type TraitAssocConstId = DefId; |
| 47 | 47 | type TraitAssocTermId = DefId; |
| ... | ... | @@ -208,23 +208,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 208 | 208 | self.adt_def(adt_def_id) |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | fn unevaluated_const_kind_from_def_id( | |
| 212 | self, | |
| 213 | def_id: Self::DefId, | |
| 214 | ) -> ty::UnevaluatedConstKind<'tcx> { | |
| 211 | fn alias_const_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasConstKind<'tcx> { | |
| 215 | 212 | match self.def_kind(def_id) { |
| 216 | 213 | DefKind::AssocConst { .. } => { |
| 217 | 214 | if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { |
| 218 | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 215 | ty::AliasConstKind::Inherent { def_id } | |
| 219 | 216 | } else { |
| 220 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 217 | ty::AliasConstKind::Projection { def_id } | |
| 221 | 218 | } |
| 222 | 219 | } |
| 223 | DefKind::Const { .. } => ty::UnevaluatedConstKind::Free { def_id }, | |
| 220 | DefKind::Const { .. } => ty::AliasConstKind::Free { def_id }, | |
| 224 | 221 | DefKind::AnonConst | DefKind::InlineConst | DefKind::Ctor(_, CtorKind::Const) => { |
| 225 | ty::UnevaluatedConstKind::Anon { def_id } | |
| 222 | ty::AliasConstKind::Anon { def_id } | |
| 226 | 223 | } |
| 227 | kind => bug!("unexpected DefKind in UnevaluatedConst: {kind:?}"), | |
| 224 | kind => bug!("unexpected DefKind in AliasConst: {kind:?}"), | |
| 228 | 225 | } |
| 229 | 226 | } |
| 230 | 227 |
compiler/rustc_middle/src/ty/mod.rs+5-5| ... | ... | @@ -76,9 +76,9 @@ pub use self::closure::{ |
| 76 | 76 | place_to_string_for_capture, |
| 77 | 77 | }; |
| 78 | 78 | pub use self::consts::{ |
| 79 | AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult, Expr, ExprKind, | |
| 80 | LitToConstInput, ScalarInt, SimdAlign, UnevaluatedConst, UnevaluatedConstKind, ValTree, | |
| 81 | ValTreeKindExt, Value, const_lit_matches_ty, | |
| 79 | AliasConst, AliasConstKind, AtomicOrdering, Const, ConstInt, ConstKind, ConstToValTreeResult, | |
| 80 | Expr, ExprKind, LitToConstInput, ScalarInt, SimdAlign, ValTree, ValTreeKindExt, Value, | |
| 81 | const_lit_matches_ty, | |
| 82 | 82 | }; |
| 83 | 83 | pub use self::context::{ |
| 84 | 84 | CtxtInterners, CurrentGcx, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls, |
| ... | ... | @@ -693,7 +693,7 @@ impl<'tcx> Term<'tcx> { |
| 693 | 693 | _ => None, |
| 694 | 694 | }, |
| 695 | 695 | TermKind::Const(ct) => match ct.kind() { |
| 696 | ConstKind::Unevaluated(_, uv) => Some(uv.into()), | |
| 696 | ConstKind::Alias(_, alias_const) => Some(alias_const.into()), | |
| 697 | 697 | _ => None, |
| 698 | 698 | }, |
| 699 | 699 | } |
| ... | ... | @@ -706,7 +706,7 @@ impl<'tcx> Term<'tcx> { |
| 706 | 706 | _ => false, |
| 707 | 707 | }, |
| 708 | 708 | ty::TermKind::Const(ct) => match ct.kind() { |
| 709 | ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => true, | |
| 709 | ty::ConstKind::Alias(ty::IsRigid::No, _) => true, | |
| 710 | 710 | _ => false, |
| 711 | 711 | }, |
| 712 | 712 | } |
compiler/rustc_middle/src/ty/print/pretty.rs+5-5| ... | ... | @@ -1579,14 +1579,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 1579 | 1579 | } |
| 1580 | 1580 | |
| 1581 | 1581 | match ct.kind() { |
| 1582 | ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => { | |
| 1582 | ty::ConstKind::Alias(_, ty::AliasConst { kind, args, .. }) => { | |
| 1583 | 1583 | match kind { |
| 1584 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 1585 | | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 1586 | | ty::UnevaluatedConstKind::Free { def_id } => { | |
| 1584 | ty::AliasConstKind::Projection { def_id } | |
| 1585 | | ty::AliasConstKind::Inherent { def_id } | |
| 1586 | | ty::AliasConstKind::Free { def_id } => { | |
| 1587 | 1587 | self.pretty_print_value_path(def_id, args)?; |
| 1588 | 1588 | } |
| 1589 | ty::UnevaluatedConstKind::Anon { def_id } => { | |
| 1589 | ty::AliasConstKind::Anon { def_id } => { | |
| 1590 | 1590 | if def_id.is_local() |
| 1591 | 1591 | && let span = self.tcx().def_span(def_id) |
| 1592 | 1592 | && let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) |
compiler/rustc_middle/src/ty/structural_impls.rs+5-5| ... | ... | @@ -634,8 +634,8 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 634 | 634 | folder: &mut F, |
| 635 | 635 | ) -> Result<Self, F::Error> { |
| 636 | 636 | let kind = match self.kind() { |
| 637 | ConstKind::Unevaluated(is_rigid, uv) => { | |
| 638 | ConstKind::Unevaluated(is_rigid, uv.try_fold_with(folder)?) | |
| 637 | ConstKind::Alias(is_rigid, alias_const) => { | |
| 638 | ConstKind::Alias(is_rigid, alias_const.try_fold_with(folder)?) | |
| 639 | 639 | } |
| 640 | 640 | ConstKind::Value(v) => ConstKind::Value(v.try_fold_with(folder)?), |
| 641 | 641 | ConstKind::Expr(e) => ConstKind::Expr(e.try_fold_with(folder)?), |
| ... | ... | @@ -651,8 +651,8 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 651 | 651 | |
| 652 | 652 | fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self { |
| 653 | 653 | let kind = match self.kind() { |
| 654 | ConstKind::Unevaluated(is_rigid, uv) => { | |
| 655 | ConstKind::Unevaluated(is_rigid, uv.fold_with(folder)) | |
| 654 | ConstKind::Alias(is_rigid, alias_const) => { | |
| 655 | ConstKind::Alias(is_rigid, alias_const.fold_with(folder)) | |
| 656 | 656 | } |
| 657 | 657 | ConstKind::Value(v) => ConstKind::Value(v.fold_with(folder)), |
| 658 | 658 | ConstKind::Expr(e) => ConstKind::Expr(e.fold_with(folder)), |
| ... | ... | @@ -670,7 +670,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 670 | 670 | impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 671 | 671 | fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result { |
| 672 | 672 | match self.kind() { |
| 673 | ConstKind::Unevaluated(_, uv) => uv.visit_with(visitor), | |
| 673 | ConstKind::Alias(_, alias_const) => alias_const.visit_with(visitor), | |
| 674 | 674 | ConstKind::Value(v) => v.visit_with(visitor), |
| 675 | 675 | ConstKind::Expr(e) => e.visit_with(visitor), |
| 676 | 676 | ConstKind::Error(e) => e.visit_with(visitor), |
compiler/rustc_middle/src/ty/visit.rs+2-2| ... | ... | @@ -200,10 +200,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector<'tcx> { |
| 200 | 200 | |
| 201 | 201 | fn visit_const(&mut self, c: ty::Const<'tcx>) { |
| 202 | 202 | // if we are only looking for "constrained" region, we have to |
| 203 | // ignore the inputs of an unevaluated const, as they may not appear | |
| 203 | // ignore the inputs of an alias const, as they may not appear | |
| 204 | 204 | // in the normalized form |
| 205 | 205 | if self.just_constrained { |
| 206 | if let ty::ConstKind::Unevaluated(..) = c.kind() { | |
| 206 | if let ty::ConstKind::Alias(..) = c.kind() { | |
| 207 | 207 | return; |
| 208 | 208 | } |
| 209 | 209 | } |
compiler/rustc_mir_build/src/builder/expr/as_constant.rs+3-3| ... | ... | @@ -72,12 +72,12 @@ pub(crate) fn as_constant_inner<'tcx>( |
| 72 | 72 | ExprKind::NamedConst { def_id, args, ref user_ty } => { |
| 73 | 73 | let user_ty = user_ty.as_ref().and_then(push_cuta); |
| 74 | 74 | if tcx.is_type_const(def_id) { |
| 75 | let uneval = ty::UnevaluatedConst::new( | |
| 75 | let uneval = ty::AliasConst::new( | |
| 76 | 76 | tcx, |
| 77 | ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id), | |
| 77 | ty::AliasConstKind::new_from_def_id(tcx, def_id), | |
| 78 | 78 | args, |
| 79 | 79 | ); |
| 80 | let ct = ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval); | |
| 80 | let ct = ty::Const::new_alias(tcx, ty::IsRigid::No, uneval); | |
| 81 | 81 | |
| 82 | 82 | let const_ = Const::Ty(ty, ct); |
| 83 | 83 | return ConstOperand { span, user_ty, const_ }; |
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs+69-72| ... | ... | @@ -49,7 +49,7 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { |
| 49 | 49 | let mut convert = ConstToPat::new(self, id, span, c); |
| 50 | 50 | |
| 51 | 51 | match c.kind() { |
| 52 | ty::ConstKind::Unevaluated(_, uv) => convert.unevaluated_to_pat(uv, ty), | |
| 52 | ty::ConstKind::Alias(_, alias_const) => convert.alias_to_pat(alias_const, ty), | |
| 53 | 53 | ty::ConstKind::Value(value) => convert.valtree_to_pat(value), |
| 54 | 54 | _ => span_bug!(span, "Invalid `ConstKind` for `const_to_pat`: {:?}", c), |
| 55 | 55 | } |
| ... | ... | @@ -77,17 +77,17 @@ impl<'tcx> ConstToPat<'tcx> { |
| 77 | 77 | |
| 78 | 78 | /// We errored. Signal that in the pattern, so that follow up errors can be silenced. |
| 79 | 79 | fn mk_err(&self, mut err: Diag<'_>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> { |
| 80 | if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind() { | |
| 81 | if let ty::UnevaluatedConstKind::Projection { def_id } | |
| 82 | | ty::UnevaluatedConstKind::Inherent { def_id } = uv.kind | |
| 80 | if let ty::ConstKind::Alias(_, alias_const) = self.c.kind() { | |
| 81 | if let ty::AliasConstKind::Projection { def_id } | |
| 82 | | ty::AliasConstKind::Inherent { def_id } = alias_const.kind | |
| 83 | 83 | && let Some(def_id) = def_id.as_local() |
| 84 | 84 | { |
| 85 | 85 | // Include the container item in the output. |
| 86 | 86 | err.span_label(self.tcx.def_span(self.tcx.local_parent(def_id)), ""); |
| 87 | 87 | } |
| 88 | if let ty::UnevaluatedConstKind::Projection { def_id } | |
| 89 | | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 90 | | ty::UnevaluatedConstKind::Free { def_id } = uv.kind | |
| 88 | if let ty::AliasConstKind::Projection { def_id } | |
| 89 | | ty::AliasConstKind::Inherent { def_id } | |
| 90 | | ty::AliasConstKind::Free { def_id } = alias_const.kind | |
| 91 | 91 | { |
| 92 | 92 | err.span_label(self.tcx.def_span(def_id), msg!("constant defined here")); |
| 93 | 93 | } |
| ... | ... | @@ -95,11 +95,7 @@ impl<'tcx> ConstToPat<'tcx> { |
| 95 | 95 | Box::new(Pat { span: self.span, ty, kind: PatKind::Error(err.emit()), extra: None }) |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | fn unevaluated_to_pat( | |
| 99 | &mut self, | |
| 100 | uv: ty::UnevaluatedConst<'tcx>, | |
| 101 | ty: Ty<'tcx>, | |
| 102 | ) -> Box<Pat<'tcx>> { | |
| 98 | fn alias_to_pat(&mut self, alias_const: ty::AliasConst<'tcx>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> { | |
| 103 | 99 | // It's not *technically* correct to be revealing opaque types here as borrowcheck has |
| 104 | 100 | // not run yet. However, CTFE itself uses `TypingMode::PostAnalysis` unconditionally even |
| 105 | 101 | // during typeck and not doing so has a lot of (undesirable) fallout (#101478, #119821). |
| ... | ... | @@ -109,13 +105,13 @@ impl<'tcx> ConstToPat<'tcx> { |
| 109 | 105 | // instead of having this logic here |
| 110 | 106 | let typing_env = |
| 111 | 107 | self.tcx.erase_and_anonymize_regions(self.typing_env).with_codegen_normalized(self.tcx); |
| 112 | let uv = self.tcx.erase_and_anonymize_regions(uv); | |
| 108 | let alias_const = self.tcx.erase_and_anonymize_regions(alias_const); | |
| 113 | 109 | |
| 114 | 110 | // FIXME(gca): This will become insufficient once associated constants can be |
| 115 | 111 | // implemented as `type` consts (project-const-generics#76). At that point it'll |
| 116 | 112 | // become necessary to just use type system normalization for all const patterns |
| 117 | 113 | // but that's not yet possible. |
| 118 | let mut thir_pat = if uv.kind.is_type_const(self.tcx) { | |
| 114 | let mut thir_pat = if alias_const.kind.is_type_const(self.tcx) { | |
| 119 | 115 | let Ok(normalize) = self |
| 120 | 116 | .tcx |
| 121 | 117 | .try_normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(self.c)) |
| ... | ... | @@ -132,67 +128,68 @@ impl<'tcx> ConstToPat<'tcx> { |
| 132 | 128 | } else { |
| 133 | 129 | // try to resolve e.g. associated constants to their definition on an impl, and then |
| 134 | 130 | // evaluate the const. |
| 135 | let valtree = match self.tcx.const_eval_resolve_for_typeck(typing_env, uv, self.span) { | |
| 136 | Ok(Ok(c)) => c, | |
| 137 | Err(ErrorHandled::Reported(_, _)) => { | |
| 138 | // Let's tell the use where this failing const occurs. | |
| 139 | let mut err = | |
| 140 | self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span }); | |
| 141 | // We've emitted an error on the original const, it would be redundant to complain | |
| 142 | // on its use as well. | |
| 143 | if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind() | |
| 144 | && let ty::UnevaluatedConstKind::Projection { .. } | |
| 145 | | ty::UnevaluatedConstKind::Inherent { .. } | |
| 146 | | ty::UnevaluatedConstKind::Free { .. } = uv.kind | |
| 147 | { | |
| 148 | err.downgrade_to_delayed_bug(); | |
| 149 | } | |
| 150 | return self.mk_err(err, ty); | |
| 151 | } | |
| 152 | Err(ErrorHandled::TooGeneric(_)) => { | |
| 153 | let mut e = self | |
| 154 | .tcx | |
| 155 | .dcx() | |
| 156 | .create_err(ConstPatternDependsOnGenericParameter { span: self.span }); | |
| 157 | for arg in uv.args { | |
| 158 | if let ty::GenericArgKind::Type(ty) = arg.kind() | |
| 159 | && let ty::Param(param_ty) = ty.kind() | |
| 131 | let valtree = | |
| 132 | match self.tcx.const_eval_resolve_for_typeck(typing_env, alias_const, self.span) { | |
| 133 | Ok(Ok(c)) => c, | |
| 134 | Err(ErrorHandled::Reported(_, _)) => { | |
| 135 | // Let's tell the use where this failing const occurs. | |
| 136 | let mut err = | |
| 137 | self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span }); | |
| 138 | // We've emitted an error on the original const, it would be redundant to complain | |
| 139 | // on its use as well. | |
| 140 | if let ty::ConstKind::Alias(_, alias_const) = self.c.kind() | |
| 141 | && let ty::AliasConstKind::Projection { .. } | |
| 142 | | ty::AliasConstKind::Inherent { .. } | |
| 143 | | ty::AliasConstKind::Free { .. } = alias_const.kind | |
| 160 | 144 | { |
| 161 | let def_id = self.tcx.hir_enclosing_body_owner(self.id); | |
| 162 | let generics = self.tcx.generics_of(def_id); | |
| 163 | let param = generics.type_param(*param_ty, self.tcx); | |
| 164 | let span = self.tcx.def_span(param.def_id); | |
| 165 | e.span_label(span, "constant depends on this generic parameter"); | |
| 166 | if let Some(ident) = self.tcx.def_ident_span(def_id) | |
| 167 | && self.tcx.sess.source_map().is_multiline(ident.between(span)) | |
| 145 | err.downgrade_to_delayed_bug(); | |
| 146 | } | |
| 147 | return self.mk_err(err, ty); | |
| 148 | } | |
| 149 | Err(ErrorHandled::TooGeneric(_)) => { | |
| 150 | let mut err = self | |
| 151 | .tcx | |
| 152 | .dcx() | |
| 153 | .create_err(ConstPatternDependsOnGenericParameter { span: self.span }); | |
| 154 | for arg in alias_const.args { | |
| 155 | if let ty::GenericArgKind::Type(ty) = arg.kind() | |
| 156 | && let ty::Param(param_ty) = ty.kind() | |
| 168 | 157 | { |
| 169 | // Display the `fn` name as well in the diagnostic, as the generic isn't | |
| 170 | // in the same line and it could be confusing otherwise. | |
| 171 | e.span_label(ident, ""); | |
| 158 | let def_id = self.tcx.hir_enclosing_body_owner(self.id); | |
| 159 | let generics = self.tcx.generics_of(def_id); | |
| 160 | let param = generics.type_param(*param_ty, self.tcx); | |
| 161 | let span = self.tcx.def_span(param.def_id); | |
| 162 | err.span_label(span, "constant depends on this generic parameter"); | |
| 163 | if let Some(ident) = self.tcx.def_ident_span(def_id) | |
| 164 | && self.tcx.sess.source_map().is_multiline(ident.between(span)) | |
| 165 | { | |
| 166 | // Display the `fn` name as well in the diagnostic, as the generic isn't | |
| 167 | // in the same line and it could be confusing otherwise. | |
| 168 | err.span_label(ident, ""); | |
| 169 | } | |
| 172 | 170 | } |
| 173 | 171 | } |
| 172 | return self.mk_err(err, ty); | |
| 174 | 173 | } |
| 175 | return self.mk_err(e, ty); | |
| 176 | } | |
| 177 | Ok(Err(bad_ty)) => { | |
| 178 | // The pattern cannot be turned into a valtree. | |
| 179 | let e = match bad_ty.kind() { | |
| 180 | ty::Adt(def, ..) => { | |
| 181 | assert!(def.is_union()); | |
| 182 | self.tcx.dcx().create_err(UnionPattern { span: self.span }) | |
| 183 | } | |
| 184 | ty::FnPtr(..) | ty::RawPtr(..) => { | |
| 185 | self.tcx.dcx().create_err(PointerPattern { span: self.span }) | |
| 186 | } | |
| 187 | _ => self.tcx.dcx().create_err(InvalidPattern { | |
| 188 | span: self.span, | |
| 189 | non_sm_ty: bad_ty, | |
| 190 | prefix: bad_ty.prefix_string(self.tcx).to_string(), | |
| 191 | }), | |
| 192 | }; | |
| 193 | return self.mk_err(e, ty); | |
| 194 | } | |
| 195 | }; | |
| 174 | Ok(Err(bad_ty)) => { | |
| 175 | // The pattern cannot be turned into a valtree. | |
| 176 | let e = match bad_ty.kind() { | |
| 177 | ty::Adt(def, ..) => { | |
| 178 | assert!(def.is_union()); | |
| 179 | self.tcx.dcx().create_err(UnionPattern { span: self.span }) | |
| 180 | } | |
| 181 | ty::FnPtr(..) | ty::RawPtr(..) => { | |
| 182 | self.tcx.dcx().create_err(PointerPattern { span: self.span }) | |
| 183 | } | |
| 184 | _ => self.tcx.dcx().create_err(InvalidPattern { | |
| 185 | span: self.span, | |
| 186 | non_sm_ty: bad_ty, | |
| 187 | prefix: bad_ty.prefix_string(self.tcx).to_string(), | |
| 188 | }), | |
| 189 | }; | |
| 190 | return self.mk_err(e, ty); | |
| 191 | } | |
| 192 | }; | |
| 196 | 193 | |
| 197 | 194 | // Lower the valtree to a THIR pattern. |
| 198 | 195 | self.valtree_to_pat(ty::Value { ty, valtree }) |
| ... | ... | @@ -209,7 +206,7 @@ impl<'tcx> ConstToPat<'tcx> { |
| 209 | 206 | |
| 210 | 207 | // Mark the pattern to indicate that it is the result of lowering a named |
| 211 | 208 | // constant. This is used for diagnostics. |
| 212 | thir_pat.extra.get_or_insert_default().expanded_const = uv.kind.opt_def_id(); | |
| 209 | thir_pat.extra.get_or_insert_default().expanded_const = alias_const.kind.opt_def_id(); | |
| 213 | 210 | thir_pat |
| 214 | 211 | } |
| 215 | 212 | |
| ... | ... | @@ -253,7 +250,7 @@ impl<'tcx> ConstToPat<'tcx> { |
| 253 | 250 | // then error about that instead, because `TypeNotStructural` gives advice that is |
| 254 | 251 | // relevant only when the problem is that `ty` does not derive `PartialEq`. |
| 255 | 252 | // |
| 256 | // Note that this is a duplicate of a check in `unevaluated_to_pat()`, | |
| 253 | // Note that this is a duplicate of a check in `alias_to_pat()`, | |
| 257 | 254 | // which we would run later if we weren’t emitting an error now. |
| 258 | 255 | if possibly_inapplicable_derived_partial_eq && !has_impl { |
| 259 | 256 | let mut err = |
compiler/rustc_mir_build/src/thir/pattern/mod.rs+3-3| ... | ... | @@ -657,12 +657,12 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { |
| 657 | 657 | let args = self.typeck_results.node_args(id); |
| 658 | 658 | // FIXME(mgca): we will need to special case IACs here to have type system compatible |
| 659 | 659 | // generic args, instead of how we represent them in body expressions. |
| 660 | let c = ty::Const::new_unevaluated( | |
| 660 | let c = ty::Const::new_alias( | |
| 661 | 661 | self.tcx, |
| 662 | 662 | ty::IsRigid::No, |
| 663 | ty::UnevaluatedConst::new( | |
| 663 | ty::AliasConst::new( | |
| 664 | 664 | self.tcx, |
| 665 | ty::UnevaluatedConstKind::new_from_def_id(self.tcx, def_id), | |
| 665 | ty::AliasConstKind::new_from_def_id(self.tcx, def_id), | |
| 666 | 666 | args, |
| 667 | 667 | ), |
| 668 | 668 | ); |
compiler/rustc_mir_transform/src/impossible_predicates.rs+1-1| ... | ... | @@ -44,7 +44,7 @@ pub(crate) fn has_impossible_predicates(tcx: TyCtxt<'_>, def_id: DefId) -> bool |
| 44 | 44 | !p.has_type_flags( |
| 45 | 45 | // Only consider global clauses to simplify. |
| 46 | 46 | TypeFlags::HAS_FREE_LOCAL_NAMES |
| 47 | // Clauses that refer to unevaluated constants as they cause cycles. | |
| 47 | // Clauses that refer to alias constants as they cause cycles. | |
| 48 | 48 | | TypeFlags::HAS_CT_PROJECTION, |
| 49 | 49 | ) |
| 50 | 50 | }); |
compiler/rustc_mir_transform/src/inline.rs+1-1| ... | ... | @@ -1026,7 +1026,7 @@ fn inline_call<'tcx, I: Inliner<'tcx>>( |
| 1026 | 1026 | }); |
| 1027 | 1027 | |
| 1028 | 1028 | // Copy required constants from the callee_body into the caller_body. Although we are only |
| 1029 | // pushing unevaluated consts to `required_consts`, here they may have been evaluated | |
| 1029 | // pushing constants that still need evaluation to `required_consts`, here they may have been evaluated | |
| 1030 | 1030 | // because we are calling `instantiate_and_normalize_erasing_regions` -- so we filter again. |
| 1031 | 1031 | caller_body.required_consts.as_mut().unwrap().extend( |
| 1032 | 1032 | callee_body.required_consts().into_iter().filter(|ct| ct.const_.is_required_const()), |
compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs+1-1| ... | ... | @@ -565,7 +565,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz |
| 565 | 565 | }, |
| 566 | 566 | // FIXME: See comment above -- we could fold the region separately or something. |
| 567 | 567 | ty::ConstKind::Bound(_, _) |
| 568 | | ty::ConstKind::Unevaluated(_, _) | |
| 568 | | ty::ConstKind::Alias(_, _) | |
| 569 | 569 | | ty::ConstKind::Value(_) |
| 570 | 570 | | ty::ConstKind::Error(_) |
| 571 | 571 | | ty::ConstKind::Expr(_) => return c.super_fold_with(self), |
compiler/rustc_next_trait_solver/src/delegate.rs+1-1| ... | ... | @@ -37,7 +37,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized { |
| 37 | 37 | fn evaluate_const( |
| 38 | 38 | &self, |
| 39 | 39 | param_env: <Self::Interner as Interner>::ParamEnv, |
| 40 | uv: ty::UnevaluatedConst<Self::Interner>, | |
| 40 | alias_const: ty::AliasConst<Self::Interner>, | |
| 41 | 41 | ) -> Option<<Self::Interner as Interner>::Const>; |
| 42 | 42 | |
| 43 | 43 | // FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`! |
compiler/rustc_next_trait_solver/src/normalize.rs+5-5| ... | ... | @@ -231,7 +231,7 @@ where |
| 231 | 231 | // With eager normalization, we should normalize the args of alias before |
| 232 | 232 | // normalizing the alias itself. |
| 233 | 233 | let ct = ct.try_super_fold_with(self)?; |
| 234 | let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return Ok(ct) }; | |
| 234 | let ty::ConstKind::Alias(orig_is_rigid, alias_const) = ct.kind() else { return Ok(ct) }; | |
| 235 | 235 | // We support ambiguous aliases inside rigid alias. So we still recognize |
| 236 | 236 | // the rigidness of the outer alias. |
| 237 | 237 | if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { |
| ... | ... | @@ -239,10 +239,10 @@ where |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | let normalized = if ct.has_escaping_bound_vars() { |
| 242 | let (uv, mapped_regions, mapped_types, mapped_consts) = | |
| 243 | BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uv); | |
| 242 | let (alias_const, mapped_regions, mapped_types, mapped_consts) = | |
| 243 | BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, alias_const); | |
| 244 | 244 | let Some(result) = ensure_sufficient_stack(|| { |
| 245 | self.normalize_alias_term(uv.into(), HasEscapingBoundVars::Yes) | |
| 245 | self.normalize_alias_term(alias_const.into(), HasEscapingBoundVars::Yes) | |
| 246 | 246 | })? |
| 247 | 247 | else { |
| 248 | 248 | return Ok(ct); |
| ... | ... | @@ -257,7 +257,7 @@ where |
| 257 | 257 | ) |
| 258 | 258 | } else { |
| 259 | 259 | ensure_sufficient_stack(|| { |
| 260 | self.normalize_alias_term(uv.into(), HasEscapingBoundVars::No) | |
| 260 | self.normalize_alias_term(alias_const.into(), HasEscapingBoundVars::No) | |
| 261 | 261 | })? |
| 262 | 262 | .map(|term| term.expect_const()) |
| 263 | 263 | .unwrap_or(ct) |
compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs+7-7| ... | ... | @@ -1439,13 +1439,13 @@ where |
| 1439 | 1439 | pub(super) fn evaluate_const( |
| 1440 | 1440 | &mut self, |
| 1441 | 1441 | param_env: I::ParamEnv, |
| 1442 | uv: ty::UnevaluatedConst<I>, | |
| 1442 | alias_const: ty::AliasConst<I>, | |
| 1443 | 1443 | ) -> Result<Option<I::Const>, RerunNonErased> { |
| 1444 | 1444 | if self.typing_mode().is_erased_not_coherence() { |
| 1445 | 1445 | match self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)? {} |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | Ok(self.delegate.evaluate_const(param_env, uv)) | |
| 1448 | Ok(self.delegate.evaluate_const(param_env, alias_const)) | |
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | 1451 | pub(super) fn evaluate_const_and_instantiate_projection_term( |
| ... | ... | @@ -1453,9 +1453,9 @@ where |
| 1453 | 1453 | param_env: I::ParamEnv, |
| 1454 | 1454 | projection_term: ty::AliasTerm<I>, |
| 1455 | 1455 | expected_term: I::Term, |
| 1456 | uv: ty::UnevaluatedConst<I>, | |
| 1456 | alias_const: ty::AliasConst<I>, | |
| 1457 | 1457 | ) -> QueryResultOrRerunNonErased<I> { |
| 1458 | match self.evaluate_const(param_env, uv)? { | |
| 1458 | match self.evaluate_const(param_env, alias_const)? { | |
| 1459 | 1459 | Some(evaluated) => { |
| 1460 | 1460 | self.eq(param_env, expected_term, evaluated.into())?; |
| 1461 | 1461 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| ... | ... | @@ -1468,11 +1468,11 @@ where |
| 1468 | 1468 | // Perhaps we could split EvaluateConstErr::HasGenericsOrInfers into HasGenerics and |
| 1469 | 1469 | // HasInfers or something, make evaluate_const return that, and make this branch be |
| 1470 | 1470 | // based on that, rather than checking `has_non_region_infer`. |
| 1471 | if self.resolve_vars_if_possible(uv).has_non_region_infer() { | |
| 1471 | if self.resolve_vars_if_possible(alias_const).has_non_region_infer() { | |
| 1472 | 1472 | self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) |
| 1473 | 1473 | } else { |
| 1474 | // We do not instantiate to the `uv` passed in, but rather | |
| 1475 | // `goal.predicate.alias`. The `uv` passed in might correspond to the `impl` | |
| 1474 | // We do not instantiate to the `alias_const` passed in, but rather | |
| 1475 | // `goal.predicate.alias`. The `alias_const` passed in might correspond to the `impl` | |
| 1476 | 1476 | // form of a constant (with generic arguments corresponding to the impl block), |
| 1477 | 1477 | // however, we want to structurally instantiate to the original, non-rebased, |
| 1478 | 1478 | // trait `Self` form of the constant (with generic arguments being the trait |
compiler/rustc_next_trait_solver/src/solve/mod.rs+6-6| ... | ... | @@ -196,7 +196,7 @@ where |
| 196 | 196 | Goal { param_env, predicate: ct }: Goal<I, I::Const>, |
| 197 | 197 | ) -> QueryResultOrRerunNonErased<I> { |
| 198 | 198 | match ct.kind() { |
| 199 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _) | |
| 199 | ty::ConstKind::Alias(ty::IsRigid::Yes, _) | |
| 200 | 200 | | ty::ConstKind::Placeholder(_) |
| 201 | 201 | | ty::ConstKind::Value(_) |
| 202 | 202 | | ty::ConstKind::Error(_) => { |
| ... | ... | @@ -207,7 +207,7 @@ where |
| 207 | 207 | self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => { | |
| 210 | ty::ConstKind::Alias(ty::IsRigid::No, alias_const) => { | |
| 211 | 211 | // We never return `NoSolution` here as `evaluate_const` emits an |
| 212 | 212 | // error itself when failing to evaluate, so emitting an additional fulfillment |
| 213 | 213 | // error in that case is unnecessary noise. This may change in the future once |
| ... | ... | @@ -216,7 +216,7 @@ where |
| 216 | 216 | |
| 217 | 217 | // FIXME(generic_const_exprs): Implement handling for generic |
| 218 | 218 | // const expressions here. |
| 219 | if let Some(_normalized) = self.evaluate_const(param_env, uv)? { | |
| 219 | if let Some(_normalized) = self.evaluate_const(param_env, alias_const)? { | |
| 220 | 220 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 221 | 221 | } else { |
| 222 | 222 | self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) |
| ... | ... | @@ -252,10 +252,10 @@ where |
| 252 | 252 | .evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 253 | 253 | .map_err(Into::into); |
| 254 | 254 | } |
| 255 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => { | |
| 256 | uv.type_of(self.cx()).skip_norm_wip() | |
| 255 | ty::ConstKind::Alias(ty::IsRigid::Yes, alias_const) => { | |
| 256 | alias_const.type_of(self.cx()).skip_norm_wip() | |
| 257 | 257 | } |
| 258 | ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => unimplemented!( | |
| 258 | ty::ConstKind::Alias(ty::IsRigid::No, _) => unimplemented!( | |
| 259 | 259 | "non-rigid unevaluated constant for compute_const_arg_has_type_goal: {ct:?}" |
| 260 | 260 | ), |
| 261 | 261 | ty::ConstKind::Expr(_) => unimplemented!( |
compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs+3-3| ... | ... | @@ -445,9 +445,9 @@ where |
| 445 | 445 | c.into() |
| 446 | 446 | } |
| 447 | 447 | ty::AliasTermKind::ProjectionConst { .. } => { |
| 448 | let uv = ty::UnevaluatedConst::new( | |
| 448 | let alias_const = ty::AliasConst::new( | |
| 449 | 449 | cx, |
| 450 | ty::UnevaluatedConstKind::Projection { | |
| 450 | ty::AliasConstKind::Projection { | |
| 451 | 451 | def_id: target_item_def_id.into().try_into().unwrap(), |
| 452 | 452 | }, |
| 453 | 453 | target_args, |
| ... | ... | @@ -456,7 +456,7 @@ where |
| 456 | 456 | goal.param_env, |
| 457 | 457 | goal.predicate.alias, |
| 458 | 458 | goal.predicate.term, |
| 459 | uv, | |
| 459 | alias_const, | |
| 460 | 460 | ); |
| 461 | 461 | } |
| 462 | 462 | kind => panic!("expected projection, found {kind:?}"), |
compiler/rustc_next_trait_solver/src/solve/project_goals/anon_const.rs+2-2| ... | ... | @@ -15,12 +15,12 @@ where |
| 15 | 15 | &mut self, |
| 16 | 16 | goal: Goal<I, ty::ProjectionPredicate<I>>, |
| 17 | 17 | ) -> QueryResultOrRerunNonErased<I> { |
| 18 | let uv = goal.predicate.projection_term.expect_ct(); | |
| 18 | let alias_const = goal.predicate.projection_term.expect_ct(); | |
| 19 | 19 | self.evaluate_const_and_instantiate_projection_term( |
| 20 | 20 | goal.param_env, |
| 21 | 21 | goal.predicate.projection_term, |
| 22 | 22 | goal.predicate.term, |
| 23 | uv, | |
| 23 | alias_const, | |
| 24 | 24 | ) |
| 25 | 25 | } |
| 26 | 26 | } |
compiler/rustc_public/src/unstable/convert/stable/ty.rs+5-7| ... | ... | @@ -552,16 +552,14 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { |
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 | ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)), |
| 555 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 556 | let Some(def_id) = uv.kind.opt_def_id() else { | |
| 557 | // FIXME: implement (both AliasTy and UnevaluatedConst will be needing this soon) | |
| 558 | panic!( | |
| 559 | "non-defid unevaluated constants are not supported by rustc_public at the moment" | |
| 560 | ) | |
| 555 | ty::ConstKind::Alias(_, alias_const) => { | |
| 556 | let Some(def_id) = alias_const.kind.opt_def_id() else { | |
| 557 | // FIXME: implement (both AliasTy and AliasConst will be needing this soon) | |
| 558 | panic!("non-defid alias consts are not supported by rustc_public at the moment") | |
| 561 | 559 | }; |
| 562 | 560 | crate::ty::TyConstKind::Unevaluated( |
| 563 | 561 | tables.const_def(def_id), |
| 564 | uv.args.stable(tables, cx), | |
| 562 | alias_const.args.stable(tables, cx), | |
| 565 | 563 | ) |
| 566 | 564 | } |
| 567 | 565 | ty::ConstKind::Error(_) => unreachable!(), |
compiler/rustc_symbol_mangling/src/v0.rs+6-6| ... | ... | @@ -696,13 +696,13 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> { |
| 696 | 696 | return Ok(()); |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | // We may still encounter unevaluated consts due to the printing | |
| 699 | // We may still encounter alias consts due to the printing | |
| 700 | 700 | // logic sometimes passing identity-substituted impl headers. |
| 701 | ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => match kind { | |
| 702 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 703 | | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 704 | | ty::UnevaluatedConstKind::Free { def_id } | |
| 705 | | ty::UnevaluatedConstKind::Anon { def_id } => { | |
| 701 | ty::ConstKind::Alias(_, ty::AliasConst { kind, args, .. }) => match kind { | |
| 702 | ty::AliasConstKind::Projection { def_id } | |
| 703 | | ty::AliasConstKind::Inherent { def_id } | |
| 704 | | ty::AliasConstKind::Free { def_id } | |
| 705 | | ty::AliasConstKind::Anon { def_id } => { | |
| 706 | 706 | return self.print_def_path(def_id, args); |
| 707 | 707 | } |
| 708 | 708 | }, |
compiler/rustc_trait_selection/src/diagnostics.rs+2-2| ... | ... | @@ -21,11 +21,11 @@ use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlig |
| 21 | 21 | pub(crate) mod note_and_explain; |
| 22 | 22 | |
| 23 | 23 | #[derive(Diagnostic)] |
| 24 | #[diag("unable to construct a constant value for the unevaluated constant {$unevaluated}")] | |
| 24 | #[diag("unable to construct a constant value for the alias const {$alias_const}")] | |
| 25 | 25 | pub(crate) struct UnableToConstructConstantValue<'a> { |
| 26 | 26 | #[primary_span] |
| 27 | 27 | pub span: Span, |
| 28 | pub unevaluated: ty::UnevaluatedConst<'a>, | |
| 28 | pub alias_const: ty::AliasConst<'a>, | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | pub(crate) struct NegativePositiveConflict<'tcx> { |
compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs+2-2| ... | ... | @@ -1079,9 +1079,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { |
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | GenericArgKind::Const(ct) => { |
| 1082 | if matches!(ct.kind(), ty::ConstKind::Unevaluated(..)) { | |
| 1082 | if matches!(ct.kind(), ty::ConstKind::Alias(..)) { | |
| 1083 | 1083 | // You can't write the generic arguments for |
| 1084 | // unevaluated constants. | |
| 1084 | // alias constants. | |
| 1085 | 1085 | walker.skip_current_subtree(); |
| 1086 | 1086 | } |
| 1087 | 1087 | } |
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs+4-4| ... | ... | @@ -3769,12 +3769,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3769 | 3769 | |
| 3770 | 3770 | match obligation.predicate.kind().skip_binder() { |
| 3771 | 3771 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => match ct.kind() { |
| 3772 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 3772 | ty::ConstKind::Alias(_, alias_const) => { | |
| 3773 | 3773 | let mut err = |
| 3774 | 3774 | self.dcx().struct_span_err(span, "unconstrained generic constant"); |
| 3775 | let const_span = uv.kind.def_span(self.tcx); | |
| 3775 | let const_span = alias_const.kind.def_span(self.tcx); | |
| 3776 | 3776 | |
| 3777 | let const_ty = uv.type_of(self.tcx).skip_norm_wip(); | |
| 3777 | let const_ty = alias_const.type_of(self.tcx).skip_norm_wip(); | |
| 3778 | 3778 | let cast = if const_ty != self.tcx.types.usize { " as usize" } else { "" }; |
| 3779 | 3779 | let msg = "try adding a `where` bound"; |
| 3780 | 3780 | if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(const_span) { |
| ... | ... | @@ -3812,7 +3812,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3812 | 3812 | Ok(err) |
| 3813 | 3813 | } |
| 3814 | 3814 | _ => { |
| 3815 | bug!("const evaluatable failed for non-unevaluated const `{ct:?}`"); | |
| 3815 | bug!("const evaluatable failed for non-alias const `{ct:?}`"); | |
| 3816 | 3816 | } |
| 3817 | 3817 | }, |
| 3818 | 3818 | _ => { |
compiler/rustc_trait_selection/src/solve/delegate.rs+2-2| ... | ... | @@ -218,9 +218,9 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< |
| 218 | 218 | fn evaluate_const( |
| 219 | 219 | &self, |
| 220 | 220 | param_env: ty::ParamEnv<'tcx>, |
| 221 | uv: ty::UnevaluatedConst<'tcx>, | |
| 221 | alias_const: ty::AliasConst<'tcx>, | |
| 222 | 222 | ) -> Option<ty::Const<'tcx>> { |
| 223 | let ct = ty::Const::new_unevaluated(self.tcx, ty::IsRigid::No, uv); | |
| 223 | let ct = ty::Const::new_alias(self.tcx, ty::IsRigid::No, alias_const); | |
| 224 | 224 | |
| 225 | 225 | match crate::traits::try_evaluate_const(&self.0, ct, param_env) { |
| 226 | 226 | Ok(ct) => Some(ct), |
compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs+3-1| ... | ... | @@ -34,7 +34,9 @@ pub(super) fn fulfillment_error_for_no_solution<'tcx>( |
| 34 | 34 | } |
| 35 | 35 | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => { |
| 36 | 36 | let ct_ty = match ct.kind() { |
| 37 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 37 | ty::ConstKind::Alias(_, alias_const) => { | |
| 38 | alias_const.type_of(infcx.tcx).skip_norm_wip() | |
| 39 | } | |
| 38 | 40 | ty::ConstKind::Param(param_ct) => { |
| 39 | 41 | param_ct.find_const_ty_from_env(obligation.param_env) |
| 40 | 42 | } |
compiler/rustc_trait_selection/src/solve/normalize.rs+7-4| ... | ... | @@ -146,18 +146,21 @@ impl<'me, 'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'me, 'tcx> { |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | let ct = ct.super_fold_with(self); |
| 149 | let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return ct }; | |
| 149 | let ty::ConstKind::Alias(orig_is_rigid, alias_const) = ct.kind() else { return ct }; | |
| 150 | 150 | if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { |
| 151 | 151 | return ct; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if ct.has_escaping_bound_vars() { |
| 155 | let (replaced, ..) = | |
| 156 | BoundVarReplacer::replace_bound_vars(self.at.infcx, &mut self.universes, uv); | |
| 155 | let (replaced, ..) = BoundVarReplacer::replace_bound_vars( | |
| 156 | self.at.infcx, | |
| 157 | &mut self.universes, | |
| 158 | alias_const, | |
| 159 | ); | |
| 157 | 160 | let _ = self.term_to_infer(replaced.into()); |
| 158 | 161 | ct |
| 159 | 162 | } else { |
| 160 | self.term_to_infer(uv.into()).expect_const() | |
| 163 | self.term_to_infer(alias_const.into()).expect_const() | |
| 161 | 164 | } |
| 162 | 165 | } |
| 163 | 166 | } |
compiler/rustc_trait_selection/src/traits/auto_trait.rs+3-3| ... | ... | @@ -774,15 +774,15 @@ impl<'tcx> AutoTraitFinder<'tcx> { |
| 774 | 774 | } |
| 775 | 775 | ty::PredicateKind::ConstEquate(c1, c2) => { |
| 776 | 776 | let evaluate = |c: ty::Const<'tcx>| { |
| 777 | if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() { | |
| 777 | if let ty::ConstKind::Alias(_, alias_const) = c.kind() { | |
| 778 | 778 | let ct = |
| 779 | 779 | super::try_evaluate_const(selcx.infcx, c, obligation.param_env); |
| 780 | 780 | |
| 781 | 781 | if let Err(EvaluateConstErr::InvalidConstParamTy(_)) = ct { |
| 782 | let span = unevaluated.kind.def_span(self.tcx); | |
| 782 | let span = alias_const.kind.def_span(self.tcx); | |
| 783 | 783 | self.tcx |
| 784 | 784 | .dcx() |
| 785 | .emit_err(UnableToConstructConstantValue { span, unevaluated }); | |
| 785 | .emit_err(UnableToConstructConstantValue { span, alias_const }); | |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | ct |
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs+8-11| ... | ... | @@ -30,7 +30,7 @@ pub fn is_const_evaluatable<'tcx>( |
| 30 | 30 | ) -> Result<(), NotConstEvaluatable> { |
| 31 | 31 | let tcx = infcx.tcx; |
| 32 | 32 | match tcx.expand_abstract_consts(unexpanded_ct).kind() { |
| 33 | ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Expr(_) => (), | |
| 33 | ty::ConstKind::Alias(_, _) | ty::ConstKind::Expr(_) => (), | |
| 34 | 34 | ty::ConstKind::Param(_) |
| 35 | 35 | | ty::ConstKind::Bound(_, _) |
| 36 | 36 | | ty::ConstKind::Placeholder(_) |
| ... | ... | @@ -44,10 +44,7 @@ pub fn is_const_evaluatable<'tcx>( |
| 44 | 44 | |
| 45 | 45 | let is_anon_ct = matches!( |
| 46 | 46 | ct.kind(), |
| 47 | ty::ConstKind::Unevaluated( | |
| 48 | _, | |
| 49 | ty::UnevaluatedConst { kind: ty::UnevaluatedConstKind::Anon { .. }, .. } | |
| 50 | ) | |
| 47 | ty::ConstKind::Alias(_, ty::AliasConst { kind: ty::AliasConstKind::Anon { .. }, .. }) | |
| 51 | 48 | ); |
| 52 | 49 | |
| 53 | 50 | if !is_anon_ct { |
| ... | ... | @@ -69,7 +66,7 @@ pub fn is_const_evaluatable<'tcx>( |
| 69 | 66 | // here. |
| 70 | 67 | tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported"); |
| 71 | 68 | } |
| 72 | ty::ConstKind::Unevaluated(_, _) => { | |
| 69 | ty::ConstKind::Alias(_, _) => { | |
| 73 | 70 | match crate::traits::try_evaluate_const(infcx, unexpanded_ct, param_env) { |
| 74 | 71 | Err(EvaluateConstErr::HasGenericsOrInfers) => { |
| 75 | 72 | Err(NotConstEvaluatable::Error(infcx.dcx().span_delayed_bug( |
| ... | ... | @@ -93,8 +90,8 @@ pub fn is_const_evaluatable<'tcx>( |
| 93 | 90 | crate::traits::evaluate_const(infcx, unexpanded_ct, param_env); |
| 94 | 91 | Ok(()) |
| 95 | 92 | } else { |
| 96 | let uv = match unexpanded_ct.kind() { | |
| 97 | ty::ConstKind::Unevaluated(_, uv) => uv, | |
| 93 | let alias_const = match unexpanded_ct.kind() { | |
| 94 | ty::ConstKind::Alias(_, alias_const) => alias_const, | |
| 98 | 95 | ty::ConstKind::Expr(_) => { |
| 99 | 96 | bug!("`ConstKind::Expr` without `feature(generic_const_exprs)` enabled") |
| 100 | 97 | } |
| ... | ... | @@ -117,7 +114,7 @@ pub fn is_const_evaluatable<'tcx>( |
| 117 | 114 | tcx.dcx() |
| 118 | 115 | .struct_span_fatal( |
| 119 | 116 | // Slightly better span than just using `span` alone |
| 120 | if span == DUMMY_SP { uv.kind.def_span(tcx) } else { span }, | |
| 117 | if span == DUMMY_SP { alias_const.kind.def_span(tcx) } else { span }, | |
| 121 | 118 | "failed to evaluate generic const expression", |
| 122 | 119 | ) |
| 123 | 120 | .with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`") |
| ... | ... | @@ -131,9 +128,9 @@ pub fn is_const_evaluatable<'tcx>( |
| 131 | 128 | } |
| 132 | 129 | |
| 133 | 130 | Err(EvaluateConstErr::HasGenericsOrInfers) => { |
| 134 | let err = if uv.has_non_region_infer() { | |
| 131 | let err = if alias_const.has_non_region_infer() { | |
| 135 | 132 | NotConstEvaluatable::MentionsInfer |
| 136 | } else if uv.has_non_region_param() { | |
| 133 | } else if alias_const.has_non_region_param() { | |
| 137 | 134 | NotConstEvaluatable::MentionsParam |
| 138 | 135 | } else { |
| 139 | 136 | let guar = infcx.dcx().span_delayed_bug( |
compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs+2-6| ... | ... | @@ -886,13 +886,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> { |
| 886 | 886 | let ct = self.tcx.expand_abstract_consts(ct); |
| 887 | 887 | |
| 888 | 888 | match ct.kind() { |
| 889 | ty::ConstKind::Unevaluated( | |
| 889 | ty::ConstKind::Alias( | |
| 890 | 890 | _, |
| 891 | ty::UnevaluatedConst { | |
| 892 | kind: ty::UnevaluatedConstKind::Projection { def_id }, | |
| 893 | args, | |
| 894 | .. | |
| 895 | }, | |
| 891 | ty::AliasConst { kind: ty::AliasConstKind::Projection { def_id }, args, .. }, | |
| 896 | 892 | ) if self.tcx.features().min_generic_const_args() => { |
| 897 | 893 | match self.allow_self_projections { |
| 898 | 894 | AllowSelfProjections::Yes => { |
compiler/rustc_trait_selection/src/traits/fulfill.rs+18-17| ... | ... | @@ -559,7 +559,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 559 | 559 | return ProcessResult::Changed(PendingPredicateObligations::new()); |
| 560 | 560 | } |
| 561 | 561 | ty::ConstKind::Value(cv) => cv.ty, |
| 562 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 562 | ty::ConstKind::Alias(_, alias_const) => { | |
| 563 | alias_const.type_of(infcx.tcx).skip_norm_wip() | |
| 564 | } | |
| 563 | 565 | // FIXME(generic_const_exprs): we should construct an alias like |
| 564 | 566 | // `<lhs_ty as Add<rhs_ty>>::Output` when this is an `Expr` representing |
| 565 | 567 | // `lhs + rhs`. |
| ... | ... | @@ -677,10 +679,10 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 677 | 679 | } |
| 678 | 680 | } |
| 679 | 681 | |
| 680 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => { | |
| 682 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => { | |
| 681 | 683 | match const_evaluatable::is_const_evaluatable( |
| 682 | 684 | self.selcx.infcx, |
| 683 | uv, | |
| 685 | alias_const, | |
| 684 | 686 | obligation.param_env, |
| 685 | 687 | obligation.cause.span, |
| 686 | 688 | ) { |
| ... | ... | @@ -688,7 +690,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 688 | 690 | Err(NotConstEvaluatable::MentionsInfer) => { |
| 689 | 691 | pending_obligation.stalled_on.clear(); |
| 690 | 692 | pending_obligation.stalled_on.extend( |
| 691 | uv.walk().filter_map(TyOrConstInferVar::maybe_from_generic_arg), | |
| 693 | alias_const | |
| 694 | .walk() | |
| 695 | .filter_map(TyOrConstInferVar::maybe_from_generic_arg), | |
| 692 | 696 | ); |
| 693 | 697 | ProcessResult::Unchanged |
| 694 | 698 | } |
| ... | ... | @@ -717,15 +721,13 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 717 | 721 | debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2); |
| 718 | 722 | |
| 719 | 723 | match (c1.kind(), c2.kind()) { |
| 720 | ( | |
| 721 | ty::ConstKind::Unevaluated(_, a), | |
| 722 | ty::ConstKind::Unevaluated(_, b), | |
| 723 | ) if a.kind == b.kind | |
| 724 | && matches!( | |
| 725 | a.kind, | |
| 726 | ty::UnevaluatedConstKind::Projection { .. } | |
| 727 | | ty::UnevaluatedConstKind::Inherent { .. } | |
| 728 | ) => | |
| 724 | (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b)) | |
| 725 | if a.kind == b.kind | |
| 726 | && matches!( | |
| 727 | a.kind, | |
| 728 | ty::AliasConstKind::Projection { .. } | |
| 729 | | ty::AliasConstKind::Inherent { .. } | |
| 730 | ) => | |
| 729 | 731 | { |
| 730 | 732 | if let Ok(new_obligations) = infcx |
| 731 | 733 | .at(&obligation.cause, obligation.param_env) |
| ... | ... | @@ -743,8 +745,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 743 | 745 | )); |
| 744 | 746 | } |
| 745 | 747 | } |
| 746 | (_, ty::ConstKind::Unevaluated(_, _)) | |
| 747 | | (ty::ConstKind::Unevaluated(_, _), _) => (), | |
| 748 | (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (), | |
| 748 | 749 | (_, _) => { |
| 749 | 750 | if let Ok(new_obligations) = infcx |
| 750 | 751 | .at(&obligation.cause, obligation.param_env) |
| ... | ... | @@ -764,7 +765,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 764 | 765 | let stalled_on = &mut pending_obligation.stalled_on; |
| 765 | 766 | |
| 766 | 767 | let mut evaluate = |c: Const<'tcx>| { |
| 767 | if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() { | |
| 768 | if let ty::ConstKind::Alias(_, alias_const) = c.kind() { | |
| 768 | 769 | match super::try_evaluate_const( |
| 769 | 770 | self.selcx.infcx, |
| 770 | 771 | c, |
| ... | ... | @@ -773,7 +774,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 773 | 774 | Ok(val) => Ok(val), |
| 774 | 775 | e @ Err(EvaluateConstErr::HasGenericsOrInfers) => { |
| 775 | 776 | stalled_on.extend( |
| 776 | unevaluated | |
| 777 | alias_const | |
| 777 | 778 | .args |
| 778 | 779 | .iter() |
| 779 | 780 | .filter_map(TyOrConstInferVar::maybe_from_generic_arg), |
compiler/rustc_trait_selection/src/traits/mod.rs+30-28| ... | ... | @@ -369,8 +369,8 @@ pub fn normalize_param_env_or_error<'tcx>( |
| 369 | 369 | // should actually be okay since without `feature(generic_const_exprs)` the only |
| 370 | 370 | // const arguments that have a non-empty param env are array repeat counts. These |
| 371 | 371 | // do not appear in the type system though. |
| 372 | if let ty::ConstKind::Unevaluated(_, uv) = c.kind() | |
| 373 | && matches!(uv.kind, ty::UnevaluatedConstKind::Anon { .. }) | |
| 372 | if let ty::ConstKind::Alias(_, alias_const) = c.kind() | |
| 373 | && matches!(alias_const.kind, ty::AliasConstKind::Anon { .. }) | |
| 374 | 374 | { |
| 375 | 375 | let infcx = self.0.infer_ctxt().build(TypingMode::non_body_analysis()); |
| 376 | 376 | let c = evaluate_const(&infcx, c, ty::ParamEnv::empty()); |
| ... | ... | @@ -401,10 +401,10 @@ pub fn normalize_param_env_or_error<'tcx>( |
| 401 | 401 | // we cannot prove `T: Trait<u8>`. |
| 402 | 402 | // |
| 403 | 403 | // The same thing is true for const generics- attempting to prove |
| 404 | // `T: Trait<ConstKind::Unevaluated(...)>` with the same thing as a where clauses | |
| 404 | // `T: Trait<ConstKind::Alias(...)>` with the same thing as a where clauses | |
| 405 | 405 | // will fail. After normalization we may be attempting to prove `T: Trait<4>` with |
| 406 | // the unnormalized where clause `T: Trait<ConstKind::Unevaluated(...)>`. In order | |
| 407 | // for the obligation to hold `4` must be equal to `ConstKind::Unevaluated(...)` | |
| 406 | // the unnormalized where clause `T: Trait<ConstKind::Alias(...)>`. In order | |
| 407 | // for the obligation to hold `4` must be equal to `ConstKind::Alias(...)` | |
| 408 | 408 | // but as we do not have lazy norm implemented, equating the two consts fails outright. |
| 409 | 409 | // |
| 410 | 410 | // 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>( |
| 547 | 547 | #[derive(Debug)] |
| 548 | 548 | pub enum EvaluateConstErr { |
| 549 | 549 | /// The constant being evaluated was either a generic parameter or inference variable, *or*, |
| 550 | /// some unevaluated constant with either generic parameters or inference variables in its | |
| 550 | /// some alias const with either generic parameters or inference variables in its | |
| 551 | 551 | /// generic arguments. |
| 552 | 552 | HasGenericsOrInfers, |
| 553 | 553 | /// The type this constant evaluated to is not valid for use in const generics. This should |
| ... | ... | @@ -560,7 +560,7 @@ pub enum EvaluateConstErr { |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | // FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine |
| 563 | // FIXME(generic_const_exprs): Consider accepting a `ty::UnevaluatedConst` when we are not rolling our own | |
| 563 | // FIXME(generic_const_exprs): Consider accepting a `ty::AliasConst` when we are not rolling our own | |
| 564 | 564 | // normalization scheme |
| 565 | 565 | /// Evaluates a type system constant returning a `ConstKind::Error` in cases where CTFE failed and |
| 566 | 566 | /// 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>( |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | // FIXME(BoxyUwU): Private this once we `generic_const_exprs` isn't doing its own normalization routine |
| 586 | // FIXME(generic_const_exprs): Consider accepting a `ty::UnevaluatedConst` when we are not rolling our own | |
| 586 | // FIXME(generic_const_exprs): Consider accepting a `ty::AliasConst` when we are not rolling our own | |
| 587 | 587 | // normalization scheme |
| 588 | 588 | /// Evaluates a type system constant making sure to not allow constants that depend on generic parameters |
| 589 | 589 | /// or inference variables to succeed in evaluating. |
| ... | ... | @@ -608,11 +608,9 @@ pub fn try_evaluate_const<'tcx>( |
| 608 | 608 | | ty::ConstKind::Bound(_, _) |
| 609 | 609 | | ty::ConstKind::Placeholder(_) |
| 610 | 610 | | ty::ConstKind::Expr(_) => Err(EvaluateConstErr::HasGenericsOrInfers), |
| 611 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 612 | let opt_anon_const_kind = match uv.kind { | |
| 613 | ty::UnevaluatedConstKind::Anon { def_id } => { | |
| 614 | Some((def_id, tcx.anon_const_kind(def_id))) | |
| 615 | } | |
| 611 | ty::ConstKind::Alias(_, alias_const) => { | |
| 612 | let opt_anon_const_kind = match alias_const.kind { | |
| 613 | ty::AliasConstKind::Anon { def_id } => Some((def_id, tcx.anon_const_kind(def_id))), | |
| 616 | 614 | _ => None, |
| 617 | 615 | }; |
| 618 | 616 | |
| ... | ... | @@ -632,14 +630,14 @@ pub fn try_evaluate_const<'tcx>( |
| 632 | 630 | // completely fall apart under `generic_const_exprs` and makes this whole function Really hard to reason |
| 633 | 631 | // about if you have to consider gce whatsoever. |
| 634 | 632 | Some((def_id, ty::AnonConstKind::GCE)) => { |
| 635 | if uv.has_non_region_infer() || uv.has_non_region_param() { | |
| 633 | if alias_const.has_non_region_infer() || alias_const.has_non_region_param() { | |
| 636 | 634 | // `feature(generic_const_exprs)` causes anon consts to inherit all parent generics. This can cause |
| 637 | 635 | // inference variables and generic parameters to show up in `ty::Const` even though the anon const |
| 638 | 636 | // does not actually make use of them. We handle this case specially and attempt to evaluate anyway. |
| 639 | 637 | match tcx.thir_abstract_const(def_id) { |
| 640 | 638 | Ok(Some(ct)) => { |
| 641 | 639 | let ct = tcx.expand_abstract_consts( |
| 642 | ct.instantiate(tcx, uv.args).skip_norm_wip(), | |
| 640 | ct.instantiate(tcx, alias_const.args).skip_norm_wip(), | |
| 643 | 641 | ); |
| 644 | 642 | if let Err(e) = ct.error_reported() { |
| 645 | 643 | return Err(EvaluateConstErr::EvaluationFailure(e)); |
| ... | ... | @@ -648,8 +646,10 @@ pub fn try_evaluate_const<'tcx>( |
| 648 | 646 | // the generic arguments provided for it, then we should *not* attempt to evaluate it. |
| 649 | 647 | return Err(EvaluateConstErr::HasGenericsOrInfers); |
| 650 | 648 | } else { |
| 651 | let args = | |
| 652 | replace_param_and_infer_args_with_placeholder(tcx, uv.args); | |
| 649 | let args = replace_param_and_infer_args_with_placeholder( | |
| 650 | tcx, | |
| 651 | alias_const.args, | |
| 652 | ); | |
| 653 | 653 | let typing_env = infcx |
| 654 | 654 | .typing_env(tcx.erase_and_anonymize_regions(param_env)) |
| 655 | 655 | .with_post_analysis_normalized(tcx); |
| ... | ... | @@ -666,11 +666,11 @@ pub fn try_evaluate_const<'tcx>( |
| 666 | 666 | let typing_env = infcx |
| 667 | 667 | .typing_env(tcx.erase_and_anonymize_regions(param_env)) |
| 668 | 668 | .with_post_analysis_normalized(tcx); |
| 669 | (uv.args, typing_env) | |
| 669 | (alias_const.args, typing_env) | |
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | Some((def_id, ty::AnonConstKind::RepeatExprCount)) => { |
| 673 | if uv.has_non_region_infer() { | |
| 673 | if alias_const.has_non_region_infer() { | |
| 674 | 674 | // Diagnostics will sometimes replace the identity args of anon consts in |
| 675 | 675 | // array repeat expr counts with inference variables so we have to handle this |
| 676 | 676 | // even though it is not something we should ever actually encounter. |
| ... | ... | @@ -706,9 +706,9 @@ pub fn try_evaluate_const<'tcx>( |
| 706 | 706 | // logic does not go through type system normalization. If it did this would |
| 707 | 707 | // be a backwards compatibility problem as we do not enforce "syntactic" non- |
| 708 | 708 | // usage of generic parameters like we do here. |
| 709 | if uv.args.has_non_region_param() | |
| 710 | || uv.args.has_non_region_infer() | |
| 711 | || uv.args.has_non_region_placeholders() | |
| 709 | if alias_const.args.has_non_region_param() | |
| 710 | || alias_const.args.has_non_region_infer() | |
| 711 | || alias_const.args.has_non_region_placeholders() | |
| 712 | 712 | { |
| 713 | 713 | return Err(EvaluateConstErr::HasGenericsOrInfers); |
| 714 | 714 | } |
| ... | ... | @@ -717,19 +717,21 @@ pub fn try_evaluate_const<'tcx>( |
| 717 | 717 | // to prevent query cycle. |
| 718 | 718 | let typing_env = ty::TypingEnv::fully_monomorphized(); |
| 719 | 719 | |
| 720 | (uv.args, typing_env) | |
| 720 | (alias_const.args, typing_env) | |
| 721 | 721 | } |
| 722 | 722 | }; |
| 723 | 723 | |
| 724 | let uv = ty::UnevaluatedConst::new(tcx, uv.kind, args); | |
| 725 | let erased_uv = tcx.erase_and_anonymize_regions(uv); | |
| 724 | let alias_const = ty::AliasConst::new(tcx, alias_const.kind, args); | |
| 725 | let erased_alias_const = tcx.erase_and_anonymize_regions(alias_const); | |
| 726 | 726 | |
| 727 | 727 | use rustc_middle::mir::interpret::ErrorHandled; |
| 728 | 728 | // FIXME: `def_span` will point at the definition of this const; ideally, we'd point at |
| 729 | 729 | // where it gets used as a const generic. |
| 730 | let span = uv.kind.def_span(tcx); | |
| 731 | match tcx.const_eval_resolve_for_typeck(typing_env, erased_uv, span) { | |
| 732 | Ok(Ok(val)) => Ok(ty::Const::new_value(tcx, val, uv.type_of(tcx).skip_norm_wip())), | |
| 730 | let span = alias_const.kind.def_span(tcx); | |
| 731 | match tcx.const_eval_resolve_for_typeck(typing_env, erased_alias_const, span) { | |
| 732 | Ok(Ok(val)) => { | |
| 733 | Ok(ty::Const::new_value(tcx, val, alias_const.type_of(tcx).skip_norm_wip())) | |
| 734 | } | |
| 733 | 735 | Ok(Err(_)) => { |
| 734 | 736 | let e = tcx.dcx().delayed_bug( |
| 735 | 737 | "Type system constant with non valtree'able type evaluated but no error emitted", |
compiler/rustc_trait_selection/src/traits/normalize.rs+12-12| ... | ... | @@ -469,14 +469,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 469 | 469 | |
| 470 | 470 | if tcx.features().generic_const_exprs() |
| 471 | 471 | // Normalize type_const items even with feature `generic_const_exprs`. |
| 472 | && !matches!(ct.kind(), ty::ConstKind::Unevaluated(_, uv) if uv.kind.is_type_const(tcx)) | |
| 472 | && !matches!(ct.kind(), ty::ConstKind::Alias(_, alias_const) if alias_const.kind.is_type_const(tcx)) | |
| 473 | 473 | || !needs_normalization(self.selcx.infcx, &ct) |
| 474 | 474 | { |
| 475 | 475 | return ct; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | let uv = match ct.kind() { | |
| 479 | ty::ConstKind::Unevaluated(_, uv) => uv, | |
| 478 | let alias_const = match ct.kind() { | |
| 479 | ty::ConstKind::Alias(_, alias_const) => alias_const, | |
| 480 | 480 | _ => return ct.super_fold_with(self), |
| 481 | 481 | }; |
| 482 | 482 | |
| ... | ... | @@ -484,20 +484,20 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 484 | 484 | // unless a `min_generic_const_args` feature gate error has already |
| 485 | 485 | // been emitted earlier in compilation. |
| 486 | 486 | // |
| 487 | // That's because we can only end up with an Unevaluated ty::Const for a const item | |
| 487 | // That's because we can only end up with an Alias ty::Const for a const item | |
| 488 | 488 | // if it was marked with `type const`. Using this attribute without the mgca |
| 489 | 489 | // feature gate causes a parse error. |
| 490 | let ct = match uv.kind { | |
| 491 | ty::UnevaluatedConstKind::Projection { .. } => { | |
| 492 | self.normalize_trait_projection(uv.into()).expect_const() | |
| 490 | let ct = match alias_const.kind { | |
| 491 | ty::AliasConstKind::Projection { .. } => { | |
| 492 | self.normalize_trait_projection(alias_const.into()).expect_const() | |
| 493 | 493 | } |
| 494 | ty::UnevaluatedConstKind::Inherent { .. } => { | |
| 495 | self.normalize_inherent_projection(uv.into()).expect_const() | |
| 494 | ty::AliasConstKind::Inherent { .. } => { | |
| 495 | self.normalize_inherent_projection(alias_const.into()).expect_const() | |
| 496 | 496 | } |
| 497 | ty::UnevaluatedConstKind::Free { .. } => { | |
| 498 | self.normalize_free_alias(uv.into()).expect_const() | |
| 497 | ty::AliasConstKind::Free { .. } => { | |
| 498 | self.normalize_free_alias(alias_const.into()).expect_const() | |
| 499 | 499 | } |
| 500 | ty::UnevaluatedConstKind::Anon { .. } => { | |
| 500 | ty::AliasConstKind::Anon { .. } => { | |
| 501 | 501 | let ct = ct.super_fold_with(self); |
| 502 | 502 | super::with_replaced_escaping_bound_vars( |
| 503 | 503 | self.selcx.infcx, |
compiler/rustc_trait_selection/src/traits/query/normalize.rs+12-14| ... | ... | @@ -272,21 +272,19 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { |
| 272 | 272 | return Ok(constant); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | let uv = match constant.kind() { | |
| 276 | ty::ConstKind::Unevaluated(_, uv) => uv, | |
| 275 | let alias_const = match constant.kind() { | |
| 276 | ty::ConstKind::Alias(_, alias_const) => alias_const, | |
| 277 | 277 | _ => return constant.try_super_fold_with(self), |
| 278 | 278 | }; |
| 279 | 279 | |
| 280 | let constant = match uv.kind { | |
| 281 | ty::UnevaluatedConstKind::Anon { .. } => { | |
| 282 | crate::traits::with_replaced_escaping_bound_vars( | |
| 283 | self.infcx, | |
| 284 | &mut self.universes, | |
| 285 | constant, | |
| 286 | |constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env), | |
| 287 | ) | |
| 288 | } | |
| 289 | _ => self.try_fold_free_or_assoc(uv.into())?.expect_const(), | |
| 280 | let constant = match alias_const.kind { | |
| 281 | ty::AliasConstKind::Anon { .. } => crate::traits::with_replaced_escaping_bound_vars( | |
| 282 | self.infcx, | |
| 283 | &mut self.universes, | |
| 284 | constant, | |
| 285 | |constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env), | |
| 286 | ), | |
| 287 | _ => self.try_fold_free_or_assoc(alias_const.into())?.expect_const(), | |
| 290 | 288 | }; |
| 291 | 289 | debug!(?constant, ?self.param_env); |
| 292 | 290 | constant.try_super_fold_with(self) |
| ... | ... | @@ -373,10 +371,10 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> { |
| 373 | 371 | result.normalized_term |
| 374 | 372 | }; |
| 375 | 373 | // `tcx.normalize_canonicalized_projection` may normalize to a type that |
| 376 | // still has unevaluated consts, so keep normalizing here if that's the case. | |
| 374 | // still has alias consts, so keep normalizing here if that's the case. | |
| 377 | 375 | // Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer |
| 378 | 376 | // of type/const and we need to continue folding it to reveal the TAIT behind it |
| 379 | // or further normalize nested unevaluated consts. | |
| 377 | // or further normalize nested alias consts. | |
| 380 | 378 | if res != term.to_term(tcx, ty::IsRigid::No) |
| 381 | 379 | && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) |
| 382 | 380 | || matches!( |
compiler/rustc_trait_selection/src/traits/select/mod.rs+14-15| ... | ... | @@ -852,10 +852,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 852 | 852 | } |
| 853 | 853 | } |
| 854 | 854 | |
| 855 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => { | |
| 855 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => { | |
| 856 | 856 | match const_evaluatable::is_const_evaluatable( |
| 857 | 857 | self.infcx, |
| 858 | uv, | |
| 858 | alias_const, | |
| 859 | 859 | obligation.param_env, |
| 860 | 860 | obligation.cause.span, |
| 861 | 861 | ) { |
| ... | ... | @@ -882,15 +882,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 882 | 882 | ); |
| 883 | 883 | |
| 884 | 884 | match (c1.kind(), c2.kind()) { |
| 885 | ( | |
| 886 | ty::ConstKind::Unevaluated(_, a), | |
| 887 | ty::ConstKind::Unevaluated(_, b), | |
| 888 | ) if a.kind == b.kind | |
| 889 | && matches!( | |
| 890 | a.kind, | |
| 891 | ty::UnevaluatedConstKind::Projection { .. } | |
| 892 | | ty::UnevaluatedConstKind::Inherent { .. } | |
| 893 | ) => | |
| 885 | (ty::ConstKind::Alias(_, a), ty::ConstKind::Alias(_, b)) | |
| 886 | if a.kind == b.kind | |
| 887 | && matches!( | |
| 888 | a.kind, | |
| 889 | ty::AliasConstKind::Projection { .. } | |
| 890 | | ty::AliasConstKind::Inherent { .. } | |
| 891 | ) => | |
| 894 | 892 | { |
| 895 | 893 | if let Ok(InferOk { obligations, value: () }) = self |
| 896 | 894 | .infcx |
| ... | ... | @@ -909,8 +907,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 909 | 907 | ); |
| 910 | 908 | } |
| 911 | 909 | } |
| 912 | (_, ty::ConstKind::Unevaluated(_, _)) | |
| 913 | | (ty::ConstKind::Unevaluated(_, _), _) => (), | |
| 910 | (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (), | |
| 914 | 911 | (_, _) => { |
| 915 | 912 | if let Ok(InferOk { obligations, value: () }) = self |
| 916 | 913 | .infcx |
| ... | ... | @@ -929,7 +926,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 929 | 926 | } |
| 930 | 927 | |
| 931 | 928 | let evaluate = |c: ty::Const<'tcx>| { |
| 932 | if let ty::ConstKind::Unevaluated(_, _) = c.kind() { | |
| 929 | if let ty::ConstKind::Alias(_, _) = c.kind() { | |
| 933 | 930 | match crate::traits::try_evaluate_const( |
| 934 | 931 | self.infcx, |
| 935 | 932 | c, |
| ... | ... | @@ -989,7 +986,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 989 | 986 | } |
| 990 | 987 | ty::ConstKind::Error(_) => return Ok(EvaluatedToOk), |
| 991 | 988 | ty::ConstKind::Value(cv) => cv.ty, |
| 992 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(self.tcx()).skip_norm_wip(), | |
| 989 | ty::ConstKind::Alias(_, alias_const) => { | |
| 990 | alias_const.type_of(self.tcx()).skip_norm_wip() | |
| 991 | } | |
| 993 | 992 | // FIXME(generic_const_exprs): See comment in `fulfill.rs` |
| 994 | 993 | ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk), |
| 995 | 994 | ty::ConstKind::Placeholder(_) => { |
compiler/rustc_trait_selection/src/traits/wf.rs+11-10| ... | ... | @@ -1064,10 +1064,11 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { |
| 1064 | 1064 | let tcx = self.tcx(); |
| 1065 | 1065 | |
| 1066 | 1066 | match c.kind() { |
| 1067 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 1067 | ty::ConstKind::Alias(_, alias_const) => { | |
| 1068 | 1068 | if !c.has_escaping_bound_vars() { |
| 1069 | 1069 | // Skip type consts as mGCA doesn't support evaluatable clauses |
| 1070 | if !uv.kind.is_type_const(tcx) && !tcx.features().generic_const_args() { | |
| 1070 | if !alias_const.kind.is_type_const(tcx) && !tcx.features().generic_const_args() | |
| 1071 | { | |
| 1071 | 1072 | let predicate = ty::Binder::dummy(ty::PredicateKind::Clause( |
| 1072 | 1073 | ty::ClauseKind::ConstEvaluatable(c), |
| 1073 | 1074 | )); |
| ... | ... | @@ -1081,15 +1082,15 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { |
| 1081 | 1082 | )); |
| 1082 | 1083 | } |
| 1083 | 1084 | |
| 1084 | match uv.kind { | |
| 1085 | ty::UnevaluatedConstKind::Inherent { .. } => { | |
| 1086 | self.add_wf_preds_for_inherent_projection(uv.into()); | |
| 1085 | match alias_const.kind { | |
| 1086 | ty::AliasConstKind::Inherent { .. } => { | |
| 1087 | self.add_wf_preds_for_inherent_projection(alias_const.into()); | |
| 1087 | 1088 | return; // Subtree is handled by above function |
| 1088 | 1089 | } |
| 1089 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 1090 | | ty::UnevaluatedConstKind::Free { def_id } | |
| 1091 | | ty::UnevaluatedConstKind::Anon { def_id } => { | |
| 1092 | let obligations = self.nominal_obligations(def_id, uv.args); | |
| 1090 | ty::AliasConstKind::Projection { def_id } | |
| 1091 | | ty::AliasConstKind::Free { def_id } | |
| 1092 | | ty::AliasConstKind::Anon { def_id } => { | |
| 1093 | let obligations = self.nominal_obligations(def_id, alias_const.args); | |
| 1093 | 1094 | self.out.extend(obligations); |
| 1094 | 1095 | } |
| 1095 | 1096 | } |
| ... | ... | @@ -1111,7 +1112,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { |
| 1111 | 1112 | ty::ConstKind::Expr(_) => { |
| 1112 | 1113 | // FIXME(generic_const_exprs): this doesn't verify that given `Expr(N + 1)` the |
| 1113 | 1114 | // trait bound `typeof(N): Add<typeof(1)>` holds. This is currently unnecessary |
| 1114 | // as `ConstKind::Expr` is only produced via normalization of `ConstKind::Unevaluated` | |
| 1115 | // as `ConstKind::Expr` is only produced via normalization of `ConstKind::Alias` | |
| 1115 | 1116 | // which means that the `DefId` would have been typeck'd elsewhere. However in |
| 1116 | 1117 | // the future we may allow directly lowering to `ConstKind::Expr` in which case |
| 1117 | 1118 | // we would not be proving bounds we should. |
compiler/rustc_ty_utils/src/consts.rs+3-6| ... | ... | @@ -70,12 +70,9 @@ fn recurse_build<'tcx>( |
| 70 | 70 | } |
| 71 | 71 | &ExprKind::ZstLiteral { user_ty: _ } => ty::Const::zero_sized(tcx, node.ty), |
| 72 | 72 | &ExprKind::NamedConst { def_id, args, user_ty: _ } => { |
| 73 | let uneval = ty::UnevaluatedConst::new( | |
| 74 | tcx, | |
| 75 | ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id), | |
| 76 | args, | |
| 77 | ); | |
| 78 | ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval) | |
| 73 | let uneval = | |
| 74 | ty::AliasConst::new(tcx, ty::AliasConstKind::new_from_def_id(tcx, def_id), args); | |
| 75 | ty::Const::new_alias(tcx, ty::IsRigid::No, uneval) | |
| 79 | 76 | } |
| 80 | 77 | ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param), |
| 81 | 78 |
compiler/rustc_ty_utils/src/layout.rs+1-1| ... | ... | @@ -177,7 +177,7 @@ fn extract_const_value<'tcx>( |
| 177 | 177 | } |
| 178 | 178 | Err(error(cx, LayoutError::TooGeneric(ty))) |
| 179 | 179 | } |
| 180 | ty::ConstKind::Unevaluated(_, _) => { | |
| 180 | ty::ConstKind::Alias(_, _) => { | |
| 181 | 181 | let err = if ct.has_param() { |
| 182 | 182 | LayoutError::TooGeneric(ty) |
| 183 | 183 | } else { |
compiler/rustc_type_ir/src/const_kind.rs+35-37| ... | ... | @@ -9,7 +9,7 @@ use rustc_type_ir_macros::{ |
| 9 | 9 | GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | use crate::{self as ty, BoundVarIndexKind, Interner, UnevaluatedConst}; | |
| 12 | use crate::{self as ty, AliasConst, BoundVarIndexKind, Interner}; | |
| 13 | 13 | |
| 14 | 14 | /// Represents a constant in Rust. |
| 15 | 15 | #[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] |
| ... | ... | @@ -34,7 +34,7 @@ pub enum ConstKind<I: Interner> { |
| 34 | 34 | /// An unnormalized const item such as an anon const or assoc const or free const item. |
| 35 | 35 | /// Right now anything other than anon consts does not actually work properly but this |
| 36 | 36 | /// should |
| 37 | Unevaluated(ty::IsRigid, ty::UnevaluatedConst<I>), | |
| 37 | Alias(ty::IsRigid, ty::AliasConst<I>), | |
| 38 | 38 | |
| 39 | 39 | /// Used to hold computed value. |
| 40 | 40 | Value(I::ValueConst), |
| ... | ... | @@ -43,7 +43,7 @@ pub enum ConstKind<I: Interner> { |
| 43 | 43 | /// propagated to avoid useless error messages. |
| 44 | 44 | Error(I::ErrorGuaranteed), |
| 45 | 45 | |
| 46 | /// Unevaluated non-const-item, used by `feature(generic_const_exprs)` to represent | |
| 46 | /// A non-const-item expression awaiting evaluation, used by `feature(generic_const_exprs)` to represent | |
| 47 | 47 | /// const arguments such as `N + 1` or `foo(N)` |
| 48 | 48 | Expr(I::ExprConst), |
| 49 | 49 | } |
| ... | ... | @@ -59,7 +59,9 @@ impl<I: Interner> fmt::Debug for ConstKind<I> { |
| 59 | 59 | Infer(var) => write!(f, "{var:?}"), |
| 60 | 60 | Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var), |
| 61 | 61 | Placeholder(placeholder) => write!(f, "{placeholder:?}"), |
| 62 | Unevaluated(is_rigid, uv) => write!(f, "Unevaluated({is_rigid:?}, {uv:?})"), | |
| 62 | Alias(is_rigid, alias_const) => { | |
| 63 | write!(f, "AliasConst({is_rigid:?}, {alias_const:?})") | |
| 64 | } | |
| 63 | 65 | Value(val) => write!(f, "{val:?}"), |
| 64 | 66 | Error(_) => write!(f, "{{const error}}"), |
| 65 | 67 | Expr(expr) => write!(f, "{expr:?}"), |
| ... | ... | @@ -67,46 +69,42 @@ impl<I: Interner> fmt::Debug for ConstKind<I> { |
| 67 | 69 | } |
| 68 | 70 | } |
| 69 | 71 | |
| 70 | impl<I: Interner> UnevaluatedConst<I> { | |
| 72 | impl<I: Interner> AliasConst<I> { | |
| 71 | 73 | #[inline] |
| 72 | pub fn new( | |
| 73 | interner: I, | |
| 74 | kind: UnevaluatedConstKind<I>, | |
| 75 | args: I::GenericArgs, | |
| 76 | ) -> UnevaluatedConst<I> { | |
| 74 | pub fn new(interner: I, kind: AliasConstKind<I>, args: I::GenericArgs) -> AliasConst<I> { | |
| 77 | 75 | if cfg!(debug_assertions) { |
| 78 | 76 | let def_id = match kind { |
| 79 | ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(), | |
| 80 | ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(), | |
| 81 | ty::UnevaluatedConstKind::Free { def_id } => def_id.into(), | |
| 82 | ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(), | |
| 77 | ty::AliasConstKind::Projection { def_id } => def_id.into(), | |
| 78 | ty::AliasConstKind::Inherent { def_id } => def_id.into(), | |
| 79 | ty::AliasConstKind::Free { def_id } => def_id.into(), | |
| 80 | ty::AliasConstKind::Anon { def_id } => def_id.into(), | |
| 83 | 81 | }; |
| 84 | 82 | interner.debug_assert_args_compatible(def_id, args); |
| 85 | 83 | } |
| 86 | UnevaluatedConst { kind, args, _use_alias_new_instead: () } | |
| 84 | AliasConst { kind, args, _use_alias_new_instead: () } | |
| 87 | 85 | } |
| 88 | 86 | |
| 89 | 87 | pub fn type_of(self, interner: I) -> ty::Unnormalized<I, I::Ty> { |
| 90 | 88 | let def_id = match self.kind { |
| 91 | ty::UnevaluatedConstKind::Projection { def_id } => def_id.into(), | |
| 92 | ty::UnevaluatedConstKind::Inherent { def_id } => def_id.into(), | |
| 93 | ty::UnevaluatedConstKind::Free { def_id } => def_id.into(), | |
| 94 | ty::UnevaluatedConstKind::Anon { def_id } => def_id.into(), | |
| 89 | ty::AliasConstKind::Projection { def_id } => def_id.into(), | |
| 90 | ty::AliasConstKind::Inherent { def_id } => def_id.into(), | |
| 91 | ty::AliasConstKind::Free { def_id } => def_id.into(), | |
| 92 | ty::AliasConstKind::Anon { def_id } => def_id.into(), | |
| 95 | 93 | }; |
| 96 | 94 | interner.type_of(def_id).instantiate(interner, self.args) |
| 97 | 95 | } |
| 98 | 96 | } |
| 99 | 97 | |
| 100 | /// UnevaluatedConstKind is extremely similar to AliasTyKind, and likely should be reasoned about | |
| 98 | /// AliasConstKind is extremely similar to AliasTyKind, and likely should be reasoned about | |
| 101 | 99 | /// and handled in very similar ways. The documentation for AliasTyKind/etc. may be helpful when |
| 102 | /// learning about UnevaluatedConstKind. | |
| 100 | /// learning about AliasConstKind. | |
| 103 | 101 | #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] |
| 104 | 102 | #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] |
| 105 | 103 | #[cfg_attr( |
| 106 | 104 | feature = "nightly", |
| 107 | 105 | derive(Encodable_NoContext, Decodable_NoContext, StableHash_NoContext) |
| 108 | 106 | )] |
| 109 | pub enum UnevaluatedConstKind<I: Interner> { | |
| 107 | pub enum AliasConstKind<I: Interner> { | |
| 110 | 108 | /// A projection `<Type as Trait>::AssocConst` |
| 111 | 109 | Projection { def_id: I::TraitAssocConstId }, |
| 112 | 110 | /// An associated constant in an inherent `impl` |
| ... | ... | @@ -114,38 +112,38 @@ pub enum UnevaluatedConstKind<I: Interner> { |
| 114 | 112 | /// A free constant, outside an impl block. |
| 115 | 113 | Free { def_id: I::FreeConstAliasId }, |
| 116 | 114 | /// Anonymous constant, e.g. the `1 + 2` in `[u8; 1 + 2]`. |
| 117 | Anon { def_id: I::UnevaluatedConstId }, | |
| 115 | Anon { def_id: I::AnonConstId }, | |
| 118 | 116 | } |
| 119 | 117 | |
| 120 | impl<I: Interner> UnevaluatedConstKind<I> { | |
| 118 | impl<I: Interner> AliasConstKind<I> { | |
| 121 | 119 | pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self { |
| 122 | interner.unevaluated_const_kind_from_def_id(def_id) | |
| 120 | interner.alias_const_kind_from_def_id(def_id) | |
| 123 | 121 | } |
| 124 | 122 | |
| 125 | 123 | pub fn is_type_const(self, interner: I) -> bool { |
| 126 | 124 | match self { |
| 127 | UnevaluatedConstKind::Projection { def_id } => interner.is_type_const(def_id.into()), | |
| 128 | UnevaluatedConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()), | |
| 129 | UnevaluatedConstKind::Free { def_id } => interner.is_type_const(def_id.into()), | |
| 130 | UnevaluatedConstKind::Anon { def_id } => interner.is_type_const(def_id.into()), | |
| 125 | AliasConstKind::Projection { def_id } => interner.is_type_const(def_id.into()), | |
| 126 | AliasConstKind::Inherent { def_id } => interner.is_type_const(def_id.into()), | |
| 127 | AliasConstKind::Free { def_id } => interner.is_type_const(def_id.into()), | |
| 128 | AliasConstKind::Anon { def_id } => interner.is_type_const(def_id.into()), | |
| 131 | 129 | } |
| 132 | 130 | } |
| 133 | 131 | |
| 134 | 132 | pub fn def_span(self, interner: I) -> I::Span { |
| 135 | 133 | match self { |
| 136 | UnevaluatedConstKind::Projection { def_id } => interner.def_span(def_id.into()), | |
| 137 | UnevaluatedConstKind::Inherent { def_id } => interner.def_span(def_id.into()), | |
| 138 | UnevaluatedConstKind::Free { def_id } => interner.def_span(def_id.into()), | |
| 139 | UnevaluatedConstKind::Anon { def_id } => interner.def_span(def_id.into()), | |
| 134 | AliasConstKind::Projection { def_id } => interner.def_span(def_id.into()), | |
| 135 | AliasConstKind::Inherent { def_id } => interner.def_span(def_id.into()), | |
| 136 | AliasConstKind::Free { def_id } => interner.def_span(def_id.into()), | |
| 137 | AliasConstKind::Anon { def_id } => interner.def_span(def_id.into()), | |
| 140 | 138 | } |
| 141 | 139 | } |
| 142 | 140 | |
| 143 | 141 | pub fn opt_def_id(self) -> Option<I::DefId> { |
| 144 | 142 | match self { |
| 145 | UnevaluatedConstKind::Projection { def_id } => Some(def_id.into()), | |
| 146 | UnevaluatedConstKind::Inherent { def_id } => Some(def_id.into()), | |
| 147 | UnevaluatedConstKind::Free { def_id } => Some(def_id.into()), | |
| 148 | UnevaluatedConstKind::Anon { def_id } => Some(def_id.into()), | |
| 143 | AliasConstKind::Projection { def_id } => Some(def_id.into()), | |
| 144 | AliasConstKind::Inherent { def_id } => Some(def_id.into()), | |
| 145 | AliasConstKind::Free { def_id } => Some(def_id.into()), | |
| 146 | AliasConstKind::Anon { def_id } => Some(def_id.into()), | |
| 149 | 147 | } |
| 150 | 148 | } |
| 151 | 149 | } |
compiler/rustc_type_ir/src/fast_reject.rs+2-4| ... | ... | @@ -478,7 +478,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_ |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | ty::ConstKind::Expr(_) |
| 481 | | ty::ConstKind::Unevaluated(_, _) | |
| 481 | | ty::ConstKind::Alias(_, _) | |
| 482 | 482 | | ty::ConstKind::Error(_) |
| 483 | 483 | | ty::ConstKind::Infer(_) |
| 484 | 484 | | ty::ConstKind::Bound(..) => { |
| ... | ... | @@ -509,9 +509,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_ |
| 509 | 509 | |
| 510 | 510 | // As we don't necessarily eagerly evaluate constants, |
| 511 | 511 | // they might unify with any value. |
| 512 | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Error(_) => { | |
| 513 | true | |
| 514 | } | |
| 512 | ty::ConstKind::Expr(_) | ty::ConstKind::Alias(_, _) | ty::ConstKind::Error(_) => true, | |
| 515 | 513 | |
| 516 | 514 | ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) => true, |
| 517 | 515 | } |
compiler/rustc_type_ir/src/flags.rs+6-6| ... | ... | @@ -79,10 +79,10 @@ bitflags::bitflags! { |
| 79 | 79 | const HAS_TY_OPAQUE = 1 << 12; |
| 80 | 80 | /// Does this have `Inherent`? |
| 81 | 81 | const HAS_TY_INHERENT = 1 << 13; |
| 82 | /// Does this have `ConstKind::Unevaluated`? | |
| 82 | /// Does this have `ConstKind::Alias`? | |
| 83 | 83 | const HAS_CT_PROJECTION = 1 << 14; |
| 84 | 84 | |
| 85 | /// Does this have `Alias` or `ConstKind::Unevaluated`? | |
| 85 | /// Does this have `Alias` or `ConstKind::Alias`? | |
| 86 | 86 | /// |
| 87 | 87 | /// Rephrased, could this term be normalized further? |
| 88 | 88 | const HAS_ALIAS = TypeFlags::HAS_TY_PROJECTION.bits() |
| ... | ... | @@ -432,8 +432,8 @@ impl<I: Interner> FlagComputation<I> { |
| 432 | 432 | self.add_term(term); |
| 433 | 433 | } |
| 434 | 434 | ty::PredicateKind::DynCompatible(_def_id) => {} |
| 435 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => { | |
| 436 | self.add_const(uv); | |
| 435 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(alias_const)) => { | |
| 436 | self.add_const(alias_const); | |
| 437 | 437 | } |
| 438 | 438 | ty::PredicateKind::ConstEquate(expected, found) => { |
| 439 | 439 | self.add_const(expected); |
| ... | ... | @@ -477,9 +477,9 @@ impl<I: Interner> FlagComputation<I> { |
| 477 | 477 | |
| 478 | 478 | fn add_const_kind(&mut self, c: &ty::ConstKind<I>) { |
| 479 | 479 | match *c { |
| 480 | ty::ConstKind::Unevaluated(is_rigid, uv) => { | |
| 480 | ty::ConstKind::Alias(is_rigid, alias_const) => { | |
| 481 | 481 | self.add_is_rigid(is_rigid); |
| 482 | self.add_args(uv.args.as_slice()); | |
| 482 | self.add_args(alias_const.args.as_slice()); | |
| 483 | 483 | self.add_flags(TypeFlags::HAS_CT_PROJECTION); |
| 484 | 484 | } |
| 485 | 485 | ty::ConstKind::Infer(infer) => match infer { |
compiler/rustc_type_ir/src/fold.rs+3-3| ... | ... | @@ -601,9 +601,9 @@ impl<I: Interner> TypeFolder<I> for RigidnessFolder<I> { |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | match c.kind() { |
| 604 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => { | |
| 605 | let uv = uv.fold_with(self); | |
| 606 | I::Const::new_unevaluated(self.cx, ty::IsRigid::No, uv) | |
| 604 | ty::ConstKind::Alias(ty::IsRigid::Yes, alias_const) => { | |
| 605 | let alias_const = alias_const.fold_with(self); | |
| 606 | I::Const::new_alias(self.cx, ty::IsRigid::No, alias_const) | |
| 607 | 607 | } |
| 608 | 608 | _ => c.super_fold_with(self), |
| 609 | 609 | } |
compiler/rustc_type_ir/src/inherent.rs+3-3| ... | ... | @@ -280,7 +280,7 @@ pub trait Const<I: Interner<Const = Self>>: |
| 280 | 280 | |
| 281 | 281 | fn new_placeholder(interner: I, param: ty::PlaceholderConst<I>) -> Self; |
| 282 | 282 | |
| 283 | fn new_unevaluated(interner: I, is_rigid: ty::IsRigid, uv: ty::UnevaluatedConst<I>) -> Self; | |
| 283 | fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_const: ty::AliasConst<I>) -> Self; | |
| 284 | 284 | |
| 285 | 285 | fn new_expr(interner: I, expr: I::ExprConst) -> Self; |
| 286 | 286 | |
| ... | ... | @@ -411,7 +411,7 @@ pub trait Term<I: Interner<Term = Self>>: |
| 411 | 411 | _ => None, |
| 412 | 412 | }, |
| 413 | 413 | ty::TermKind::Const(ct) => match ct.kind() { |
| 414 | ty::ConstKind::Unevaluated(_, uv) => Some(uv.into()), | |
| 414 | ty::ConstKind::Alias(_, alias_const) => Some(alias_const.into()), | |
| 415 | 415 | _ => None, |
| 416 | 416 | }, |
| 417 | 417 | } |
| ... | ... | @@ -424,7 +424,7 @@ pub trait Term<I: Interner<Term = Self>>: |
| 424 | 424 | _ => false, |
| 425 | 425 | }, |
| 426 | 426 | ty::TermKind::Const(ct) => match ct.kind() { |
| 427 | ty::ConstKind::Unevaluated(is_rigid, _) => is_rigid == ty::IsRigid::No, | |
| 427 | ty::ConstKind::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No, | |
| 428 | 428 | _ => false, |
| 429 | 429 | }, |
| 430 | 430 | } |
compiler/rustc_type_ir/src/interner.rs+6-16| ... | ... | @@ -56,13 +56,12 @@ pub trait Interner: |
| 56 | 56 | type CoroutineId: SpecificDefId<Self>; |
| 57 | 57 | type AdtId: SpecificDefId<Self>; |
| 58 | 58 | type ImplId: SpecificDefId<Self>; |
| 59 | type UnevaluatedConstId: SpecificDefId<Self>; | |
| 59 | type AnonConstId: SpecificDefId<Self>; | |
| 60 | 60 | type TraitAssocTyId: SpecificDefId<Self> |
| 61 | 61 | + Into<Self::TraitAssocTermId> |
| 62 | 62 | + TryFrom<Self::TraitAssocTermId>; |
| 63 | 63 | type TraitAssocConstId: SpecificDefId<Self> |
| 64 | 64 | + Into<Self::TraitAssocTermId> |
| 65 | + Into<Self::UnevaluatedConstId> | |
| 66 | 65 | + TryFrom<Self::TraitAssocTermId>; |
| 67 | 66 | type TraitAssocTermId: SpecificDefId<Self>; |
| 68 | 67 | type OpaqueTyId: SpecificDefId<Self, Self::LocalOpaqueTyId>; |
| ... | ... | @@ -75,19 +74,13 @@ pub trait Interner: |
| 75 | 74 | + Into<Self::DefId> |
| 76 | 75 | + TypeFoldable<Self>; |
| 77 | 76 | type FreeTyAliasId: SpecificDefId<Self> + Into<Self::FreeTermAliasId>; |
| 78 | type FreeConstAliasId: SpecificDefId<Self> | |
| 79 | + Into<Self::UnevaluatedConstId> | |
| 80 | + Into<Self::FreeTermAliasId>; | |
| 77 | type FreeConstAliasId: SpecificDefId<Self> + Into<Self::FreeTermAliasId>; | |
| 81 | 78 | type FreeTermAliasId: SpecificDefId<Self>; |
| 82 | 79 | type ImplOrTraitAssocTyId: SpecificDefId<Self> + Into<Self::ImplOrTraitAssocTermId>; |
| 83 | type ImplOrTraitAssocConstId: SpecificDefId<Self> | |
| 84 | + Into<Self::UnevaluatedConstId> | |
| 85 | + Into<Self::ImplOrTraitAssocTermId>; | |
| 80 | type ImplOrTraitAssocConstId: SpecificDefId<Self> + Into<Self::ImplOrTraitAssocTermId>; | |
| 86 | 81 | type ImplOrTraitAssocTermId: SpecificDefId<Self>; |
| 87 | 82 | type InherentAssocTyId: SpecificDefId<Self> + Into<Self::InherentAssocTermId>; |
| 88 | type InherentAssocConstId: SpecificDefId<Self> | |
| 89 | + Into<Self::UnevaluatedConstId> | |
| 90 | + Into<Self::InherentAssocTermId>; | |
| 83 | type InherentAssocConstId: SpecificDefId<Self> + Into<Self::InherentAssocTermId>; | |
| 91 | 84 | type InherentAssocTermId: SpecificDefId<Self>; |
| 92 | 85 | type Span: Span<Self>; |
| 93 | 86 | |
| ... | ... | @@ -244,10 +237,7 @@ pub trait Interner: |
| 244 | 237 | type AdtDef: AdtDef<Self>; |
| 245 | 238 | fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef; |
| 246 | 239 | |
| 247 | fn unevaluated_const_kind_from_def_id( | |
| 248 | self, | |
| 249 | def_id: Self::DefId, | |
| 250 | ) -> ty::UnevaluatedConstKind<Self>; | |
| 240 | fn alias_const_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasConstKind<Self>; | |
| 251 | 241 | |
| 252 | 242 | // FIXME: remove in favor of explicit construction |
| 253 | 243 | fn alias_term_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTermKind<Self>; |
| ... | ... | @@ -519,7 +509,7 @@ declare_lift_into! { |
| 519 | 509 | TraitId, |
| 520 | 510 | Ty, |
| 521 | 511 | Tys, |
| 522 | UnevaluatedConstId, | |
| 512 | AnonConstId, | |
| 523 | 513 | } |
| 524 | 514 | |
| 525 | 515 | /// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter` |
compiler/rustc_type_ir/src/ir_print.rs+3-3| ... | ... | @@ -1,12 +1,12 @@ |
| 1 | 1 | use std::fmt; |
| 2 | 2 | |
| 3 | #[cfg(feature = "nightly")] | |
| 4 | use crate::{AliasConst, ClosureKind}; | |
| 3 | 5 | use crate::{ |
| 4 | 6 | AliasTerm, AliasTy, Binder, CoercePredicate, ExistentialProjection, ExistentialTraitRef, FnSig, |
| 5 | 7 | HostEffectPredicate, Interner, NormalizesTo, OutlivesPredicate, PatternKind, Placeholder, |
| 6 | 8 | ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef, |
| 7 | 9 | }; |
| 8 | #[cfg(feature = "nightly")] | |
| 9 | use crate::{ClosureKind, UnevaluatedConst}; | |
| 10 | 10 | |
| 11 | 11 | pub trait IrPrint<T> { |
| 12 | 12 | fn print(t: &T, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; |
| ... | ... | @@ -100,7 +100,7 @@ mod into_diag_arg_impls { |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | impl<I: Interner> IntoDiagArg for UnevaluatedConst<I> { | |
| 103 | impl<I: Interner> IntoDiagArg for AliasConst<I> { | |
| 104 | 104 | fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> DiagArgValue { |
| 105 | 105 | format!("{self:?}").into_diag_arg(path) |
| 106 | 106 | } |
compiler/rustc_type_ir/src/relate.rs+10-13| ... | ... | @@ -231,17 +231,17 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> { |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | impl<I: Interner> Relate<I> for ty::UnevaluatedConst<I> { | |
| 234 | impl<I: Interner> Relate<I> for ty::AliasConst<I> { | |
| 235 | 235 | fn relate<R: TypeRelation<I>>( |
| 236 | 236 | relation: &mut R, |
| 237 | a: ty::UnevaluatedConst<I>, | |
| 238 | b: ty::UnevaluatedConst<I>, | |
| 239 | ) -> RelateResult<I, ty::UnevaluatedConst<I>> { | |
| 237 | a: ty::AliasConst<I>, | |
| 238 | b: ty::AliasConst<I>, | |
| 239 | ) -> RelateResult<I, ty::AliasConst<I>> { | |
| 240 | 240 | let cx = relation.cx(); |
| 241 | 241 | if a.kind != b.kind { |
| 242 | 242 | Err(TypeError::ConstMismatch(ExpectedFound::new( |
| 243 | Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), a), | |
| 244 | Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), b), | |
| 243 | Const::new_alias(cx, ty::IsRigid::yes_if_next_solver(cx), a), | |
| 244 | Const::new_alias(cx, ty::IsRigid::yes_if_next_solver(cx), b), | |
| 245 | 245 | ))) |
| 246 | 246 | } else { |
| 247 | 247 | // FIXME(mgca): remove this |
| ... | ... | @@ -249,7 +249,7 @@ impl<I: Interner> Relate<I> for ty::UnevaluatedConst<I> { |
| 249 | 249 | |
| 250 | 250 | let args = relate_args_invariantly(relation, a.args, b.args)?; |
| 251 | 251 | |
| 252 | Ok(ty::UnevaluatedConst::new(cx, a.kind, args)) | |
| 252 | Ok(ty::AliasConst::new(cx, a.kind, args)) | |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | } |
| ... | ... | @@ -550,7 +550,7 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>( |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /// Relates `a` and `b` structurally, calling the relation for all nested values. |
| 553 | /// Any semantic equality, e.g. of unevaluated consts, and inference variables have | |
| 553 | /// Any semantic equality, e.g. of alias consts, and inference variables have | |
| 554 | 554 | /// to be handled by the caller. |
| 555 | 555 | /// |
| 556 | 556 | /// FIXME: This is not totally structural, which probably should be fixed. |
| ... | ... | @@ -618,14 +618,11 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>( |
| 618 | 618 | // While this is slightly incorrect, it shouldn't matter for `min_const_generics` |
| 619 | 619 | // and is the better alternative to waiting until `generic_const_exprs` can |
| 620 | 620 | // be stabilized. |
| 621 | ( | |
| 622 | ty::ConstKind::Unevaluated(is_rigid_a, au), | |
| 623 | ty::ConstKind::Unevaluated(is_rigid_b, bu), | |
| 624 | ) => { | |
| 621 | (ty::ConstKind::Alias(is_rigid_a, au), ty::ConstKind::Alias(is_rigid_b, bu)) => { | |
| 625 | 622 | // Users shouldn't know about this so the mismatch should be caught |
| 626 | 623 | // during development rather than presented as type error. |
| 627 | 624 | debug_assert_eq!(is_rigid_a, is_rigid_b, "{a:?} != {b:?}"); |
| 628 | return Ok(Const::new_unevaluated(cx, is_rigid_a, relation.relate(au, bu)?)); | |
| 625 | return Ok(Const::new_alias(cx, is_rigid_a, relation.relate(au, bu)?)); | |
| 629 | 626 | } |
| 630 | 627 | (ty::ConstKind::Expr(ae), ty::ConstKind::Expr(be)) => { |
| 631 | 628 | let expr = relation.relate(ae, be)?; |
compiler/rustc_type_ir/src/relate/combine.rs+4-5| ... | ... | @@ -239,14 +239,13 @@ where |
| 239 | 239 | Ok(a) |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | ( | |
| 243 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _), | |
| 244 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _), | |
| 245 | ) if (infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver()) => { | |
| 242 | (ty::ConstKind::Alias(ty::IsRigid::Yes, _), ty::ConstKind::Alias(ty::IsRigid::Yes, _)) | |
| 243 | if (infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver()) => | |
| 244 | { | |
| 246 | 245 | structurally_relate_consts(relation, a, b) |
| 247 | 246 | } |
| 248 | 247 | |
| 249 | (ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..)) | |
| 248 | (ty::ConstKind::Alias(..), _) | (_, ty::ConstKind::Alias(..)) | |
| 250 | 249 | if infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver() => |
| 251 | 250 | { |
| 252 | 251 | match relation.structurally_relate_aliases() { |
compiler/rustc_type_ir/src/term_kind.rs+27-43| ... | ... | @@ -60,9 +60,9 @@ pub enum AliasTermKind<I: Interner> { |
| 60 | 60 | /// Can always be normalized away. |
| 61 | 61 | FreeTy { def_id: I::FreeTyAliasId }, |
| 62 | 62 | |
| 63 | /// An unevaluated anonymous constants. | |
| 64 | AnonConst { def_id: I::UnevaluatedConstId }, | |
| 65 | /// An unevaluated const coming from an associated const. | |
| 63 | /// An anonymous constant. | |
| 64 | AnonConst { def_id: I::AnonConstId }, | |
| 65 | /// A const alias coming from an associated const. | |
| 66 | 66 | ProjectionConst { def_id: I::TraitAssocConstId }, |
| 67 | 67 | /// A top level const item not part of a trait or impl. |
| 68 | 68 | FreeConst { def_id: I::FreeConstAliasId }, |
| ... | ... | @@ -79,8 +79,8 @@ impl<I: Interner> AliasTermKind<I> { |
| 79 | 79 | AliasTermKind::InherentConst { .. } => "inherent associated const", |
| 80 | 80 | AliasTermKind::OpaqueTy { .. } => "opaque type", |
| 81 | 81 | AliasTermKind::FreeTy { .. } => "type alias", |
| 82 | AliasTermKind::FreeConst { .. } => "unevaluated constant", | |
| 83 | AliasTermKind::AnonConst { .. } => "unevaluated constant", | |
| 82 | AliasTermKind::FreeConst { .. } => "const alias", | |
| 83 | AliasTermKind::AnonConst { .. } => "anonymous constant", | |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| ... | ... | @@ -122,17 +122,13 @@ impl<I: Interner> From<ty::AliasTyKind<I>> for AliasTermKind<I> { |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | impl<I: Interner> From<ty::UnevaluatedConstKind<I>> for AliasTermKind<I> { | |
| 126 | fn from(value: ty::UnevaluatedConstKind<I>) -> Self { | |
| 125 | impl<I: Interner> From<ty::AliasConstKind<I>> for AliasTermKind<I> { | |
| 126 | fn from(value: ty::AliasConstKind<I>) -> Self { | |
| 127 | 127 | match value { |
| 128 | ty::UnevaluatedConstKind::Projection { def_id } => { | |
| 129 | AliasTermKind::ProjectionConst { def_id } | |
| 130 | } | |
| 131 | ty::UnevaluatedConstKind::Inherent { def_id } => { | |
| 132 | AliasTermKind::InherentConst { def_id } | |
| 133 | } | |
| 134 | ty::UnevaluatedConstKind::Free { def_id } => AliasTermKind::FreeConst { def_id }, | |
| 135 | ty::UnevaluatedConstKind::Anon { def_id } => AliasTermKind::AnonConst { def_id }, | |
| 128 | ty::AliasConstKind::Projection { def_id } => AliasTermKind::ProjectionConst { def_id }, | |
| 129 | ty::AliasConstKind::Inherent { def_id } => AliasTermKind::InherentConst { def_id }, | |
| 130 | ty::AliasConstKind::Free { def_id } => AliasTermKind::FreeConst { def_id }, | |
| 131 | ty::AliasConstKind::Anon { def_id } => AliasTermKind::AnonConst { def_id }, | |
| 136 | 132 | } |
| 137 | 133 | } |
| 138 | 134 | } |
| ... | ... | @@ -189,24 +185,20 @@ impl<I: Interner> AliasTerm<I> { |
| 189 | 185 | ty::AliasTy { kind, args: self.args, _use_alias_new_instead: () } |
| 190 | 186 | } |
| 191 | 187 | |
| 192 | pub fn expect_ct(self) -> ty::UnevaluatedConst<I> { | |
| 188 | pub fn expect_ct(self) -> ty::AliasConst<I> { | |
| 193 | 189 | let kind = match self.kind { |
| 194 | AliasTermKind::InherentConst { def_id } => { | |
| 195 | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 196 | } | |
| 197 | AliasTermKind::FreeConst { def_id } => ty::UnevaluatedConstKind::Free { def_id }, | |
| 198 | AliasTermKind::AnonConst { def_id } => ty::UnevaluatedConstKind::Anon { def_id }, | |
| 199 | AliasTermKind::ProjectionConst { def_id } => { | |
| 200 | ty::UnevaluatedConstKind::Projection { def_id } | |
| 201 | } | |
| 190 | AliasTermKind::InherentConst { def_id } => ty::AliasConstKind::Inherent { def_id }, | |
| 191 | AliasTermKind::FreeConst { def_id } => ty::AliasConstKind::Free { def_id }, | |
| 192 | AliasTermKind::AnonConst { def_id } => ty::AliasConstKind::Anon { def_id }, | |
| 193 | AliasTermKind::ProjectionConst { def_id } => ty::AliasConstKind::Projection { def_id }, | |
| 202 | 194 | kind @ (AliasTermKind::ProjectionTy { .. } |
| 203 | 195 | | AliasTermKind::InherentTy { .. } |
| 204 | 196 | | AliasTermKind::OpaqueTy { .. } |
| 205 | 197 | | AliasTermKind::FreeTy { .. }) => { |
| 206 | panic!("Cannot turn `{}` into `UnevaluatedConst`", kind.descr()) | |
| 198 | panic!("Cannot turn `{}` into `AliasConst`", kind.descr()) | |
| 207 | 199 | } |
| 208 | 200 | }; |
| 209 | ty::UnevaluatedConst { kind, args: self.args, _use_alias_new_instead: () } | |
| 201 | ty::AliasConst { kind, args: self.args, _use_alias_new_instead: () } | |
| 210 | 202 | } |
| 211 | 203 | |
| 212 | 204 | pub fn to_term(self, interner: I, is_rigid: ty::IsRigid) -> I::Term { |
| ... | ... | @@ -214,26 +206,18 @@ impl<I: Interner> AliasTerm<I> { |
| 214 | 206 | Ty::new_alias(interner, is_rigid, ty::AliasTy::new_from_args(interner, kind, self.args)) |
| 215 | 207 | .into() |
| 216 | 208 | }; |
| 217 | let unevaluated_const = |kind| { | |
| 218 | I::Const::new_unevaluated( | |
| 219 | interner, | |
| 220 | is_rigid, | |
| 221 | ty::UnevaluatedConst::new(interner, kind, self.args), | |
| 222 | ) | |
| 223 | .into() | |
| 209 | let alias_const = |kind| { | |
| 210 | I::Const::new_alias(interner, is_rigid, ty::AliasConst::new(interner, kind, self.args)) | |
| 211 | .into() | |
| 224 | 212 | }; |
| 225 | 213 | match self.kind { |
| 226 | AliasTermKind::FreeConst { def_id } => { | |
| 227 | unevaluated_const(ty::UnevaluatedConstKind::Free { def_id }) | |
| 228 | } | |
| 214 | AliasTermKind::FreeConst { def_id } => alias_const(ty::AliasConstKind::Free { def_id }), | |
| 229 | 215 | AliasTermKind::InherentConst { def_id } => { |
| 230 | unevaluated_const(ty::UnevaluatedConstKind::Inherent { def_id }) | |
| 231 | } | |
| 232 | AliasTermKind::AnonConst { def_id } => { | |
| 233 | unevaluated_const(ty::UnevaluatedConstKind::Anon { def_id }) | |
| 216 | alias_const(ty::AliasConstKind::Inherent { def_id }) | |
| 234 | 217 | } |
| 218 | AliasTermKind::AnonConst { def_id } => alias_const(ty::AliasConstKind::Anon { def_id }), | |
| 235 | 219 | AliasTermKind::ProjectionConst { def_id } => { |
| 236 | unevaluated_const(ty::UnevaluatedConstKind::Projection { def_id }) | |
| 220 | alias_const(ty::AliasConstKind::Projection { def_id }) | |
| 237 | 221 | } |
| 238 | 222 | AliasTermKind::ProjectionTy { def_id } => alias_ty(ty::Projection { def_id }), |
| 239 | 223 | AliasTermKind::InherentTy { def_id } => alias_ty(ty::Inherent { def_id }), |
| ... | ... | @@ -367,8 +351,8 @@ impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> { |
| 367 | 351 | } |
| 368 | 352 | } |
| 369 | 353 | |
| 370 | impl<I: Interner> From<ty::UnevaluatedConst<I>> for AliasTerm<I> { | |
| 371 | fn from(ty: ty::UnevaluatedConst<I>) -> Self { | |
| 354 | impl<I: Interner> From<ty::AliasConst<I>> for AliasTerm<I> { | |
| 355 | fn from(ty: ty::AliasConst<I>) -> Self { | |
| 372 | 356 | AliasTerm { args: ty.args, kind: AliasTermKind::from(ty.kind), _use_alias_new_instead: () } |
| 373 | 357 | } |
| 374 | 358 | } |
compiler/rustc_type_ir/src/ty/alias.rs+2-2| ... | ... | @@ -5,7 +5,7 @@ use rustc_type_ir_macros::{ |
| 5 | 5 | GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, |
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | use crate::{AliasTermKind, AliasTyKind, Interner, UnevaluatedConstKind}; | |
| 8 | use crate::{AliasConstKind, AliasTermKind, AliasTyKind, Interner}; | |
| 9 | 9 | |
| 10 | 10 | /// Represents an alias of a type, constant, or other term-like item. |
| 11 | 11 | /// |
| ... | ... | @@ -55,4 +55,4 @@ pub type ProjectionAliasTy<I> = Alias<I, <I as Interner>::TraitAssocTyId>; |
| 55 | 55 | pub type InherentAliasTy<I> = Alias<I, <I as Interner>::InherentAssocTyId>; |
| 56 | 56 | pub type OpaqueAliasTy<I> = Alias<I, <I as Interner>::OpaqueTyId>; |
| 57 | 57 | pub type FreeAliasTy<I> = Alias<I, <I as Interner>::FreeTyAliasId>; |
| 58 | pub type UnevaluatedConst<I> = Alias<I, UnevaluatedConstKind<I>>; | |
| 58 | pub type AliasConst<I> = Alias<I, AliasConstKind<I>>; |
compiler/rustc_type_ir/src/walk.rs+1-1| ... | ... | @@ -160,7 +160,7 @@ fn push_inner<I: Interner>(stack: &mut TypeWalkerStack<I>, parent: I::GenericArg |
| 160 | 160 | ty::ConstKind::Value(cv) => stack.push(cv.ty().into()), |
| 161 | 161 | |
| 162 | 162 | ty::ConstKind::Expr(expr) => stack.extend(expr.args().iter().rev()), |
| 163 | ty::ConstKind::Unevaluated(_, ct) => { | |
| 163 | ty::ConstKind::Alias(_, ct) => { | |
| 164 | 164 | stack.extend(ct.args.iter().rev()); |
| 165 | 165 | } |
| 166 | 166 | }, |
src/librustdoc/clean/utils.rs+5-5| ... | ... | @@ -350,8 +350,8 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { |
| 350 | 350 | |
| 351 | 351 | pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String { |
| 352 | 352 | match n.kind() { |
| 353 | ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, .. }) => match kind { | |
| 354 | ty::UnevaluatedConstKind::Projection { def_id } => { | |
| 353 | ty::ConstKind::Alias(_, ty::AliasConst { kind, .. }) => match kind { | |
| 354 | ty::AliasConstKind::Projection { def_id } => { | |
| 355 | 355 | if let Some(local_def_id) = def_id.as_local() |
| 356 | 356 | && let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id) |
| 357 | 357 | { |
| ... | ... | @@ -360,9 +360,9 @@ pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String { |
| 360 | 360 | n.to_string() |
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | ty::UnevaluatedConstKind::Inherent { def_id } | |
| 364 | | ty::UnevaluatedConstKind::Free { def_id } | |
| 365 | | ty::UnevaluatedConstKind::Anon { def_id } => { | |
| 363 | ty::AliasConstKind::Inherent { def_id } | |
| 364 | | ty::AliasConstKind::Free { def_id } | |
| 365 | | ty::AliasConstKind::Anon { def_id } => { | |
| 366 | 366 | if let Some(local_def_id) = def_id.as_local() |
| 367 | 367 | && let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id) |
| 368 | 368 | { |
tests/mir-opt/issue_99325.main.built.after.32bit.mir+1-1| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | | User Type Annotations |
| 4 | 4 | | 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [AliasConst(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 6 | 6 | | |
| 7 | 7 | fn main() -> () { |
| 8 | 8 | let mut _0: (); |
tests/mir-opt/issue_99325.main.built.after.64bit.mir+1-1| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | | User Type Annotations |
| 4 | 4 | | 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [AliasConst(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 6 | 6 | | |
| 7 | 7 | fn main() -> () { |
| 8 | 8 | let mut _0: (); |
tests/ui/const-generics/mgca/cyclic-type-const-151251.rs+1-1| ... | ... | @@ -5,6 +5,6 @@ |
| 5 | 5 | #![expect(incomplete_features)] |
| 6 | 6 | |
| 7 | 7 | type const A: u8 = A; |
| 8 | //~^ ERROR overflow normalizing the unevaluated constant `A` | |
| 8 | //~^ ERROR overflow normalizing the const alias `A` | |
| 9 | 9 | |
| 10 | 10 | fn main() {} |
tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr+1-1| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | error[E0275]: overflow normalizing the unevaluated constant `A` | |
| 1 | error[E0275]: overflow normalizing the const alias `A` | |
| 2 | 2 | --> $DIR/cyclic-type-const-151251.rs:7:1 |
| 3 | 3 | | |
| 4 | 4 | LL | type const A: u8 = A; |
tests/ui/const-generics/mgca/type_const-recursive.rs+1-1| ... | ... | @@ -3,6 +3,6 @@ |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | type const A: u8 = A; |
| 6 | //~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275] | |
| 6 | //~^ ERROR: overflow normalizing the const alias `A` [E0275] | |
| 7 | 7 | |
| 8 | 8 | fn main() {} |
tests/ui/const-generics/mgca/type_const-recursive.stderr+1-1| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | error[E0275]: overflow normalizing the unevaluated constant `A` | |
| 1 | error[E0275]: overflow normalizing the const alias `A` | |
| 2 | 2 | --> $DIR/type_const-recursive.rs:5:1 |
| 3 | 3 | | |
| 4 | 4 | LL | type const A: u8 = A; |
tests/ui/offset-of/inside-array-length.stderr+1-1| ... | ... | @@ -37,7 +37,7 @@ LL | fn foo<'a, T: 'a>(_: [(); std::mem::offset_of!((T,), 0)]) {} |
| 37 | 37 | = note: ...which requires caching mir of `foo::{constant#0}` for CTFE... |
| 38 | 38 | = note: ...which requires elaborating drops for `foo::{constant#0}`... |
| 39 | 39 | = note: ...which requires borrow-checking `foo::{constant#0}`... |
| 40 | = note: ...which requires normalizing `Binder { value: ConstEvaluatable(Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:7 ~ inside_array_length[07d6]::foo::{constant#0}) }, args: ['^c_1, T/#1], .. })), bound_vars: [] }`... | |
| 40 | = note: ...which requires normalizing `Binder { value: ConstEvaluatable(AliasConst(No, Alias { kind: Anon { def_id: DefId(0:7 ~ inside_array_length[07d6]::foo::{constant#0}) }, args: ['^c_1, T/#1], .. })), bound_vars: [] }`... | |
| 41 | 41 | = note: ...which again requires evaluating type-level constant, completing the cycle |
| 42 | 42 | = note: cycle used when normalizing `inside_array_length::::foo::{constant#0}` |
| 43 | 43 | = note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html> |