about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/consts.rs
AgeCommit message (Collapse)AuthorLines
2025-09-30Split Bound into Canonical and Boundjackh726-1/+13
2025-07-31Make const bound handling more like types/regions.Nicholas Nethercote-5/+9
Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`, and `Const` and... `BoundVar`. An annoying inconsistency. This commit repurposes the existing `BoundConst`, which was barely used, so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks a `kind` field but it's still nice to have because it makes the const code more similar to the ty/region code everywhere. The commit also removes `impl From<BoundVar> for BoundTy`, which has a single use and doesn't seem worth it. These changes fix the "FIXME: We really should have a separate `BoundConst` for consts".
2025-06-24Introduce trivial WF functions, use it in fast pathMichael Goulet-0/+13
2025-06-13Uplift BoundVarReplacerMichael Goulet-0/+4
2025-05-22Review CommentsBoxy-2/+7
2025-05-21Introduce `tcx.anon_const_kind` queryBoxy-1/+9
2025-04-12Move FlagComputation, PatternKind, and TypeWalker to rustc_type_irjackh726-0/+15
2025-03-15Fold visit into tyMichael Goulet-1/+1
2025-02-13intern valtreesLukas Markeffsky-3/+3
2025-01-30add commentsLukas Markeffsky-0/+6
2025-01-30check the types in `ty::Value` to value conversionLukas Markeffsky-7/+0
and remove `ty::Const::try_to_scalar` because it becomes redundant
2025-01-30introduce `ty::Value`Lukas Markeffsky-27/+11
Co-authored-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
2024-12-02Move `Const::{from_anon_const,try_from_lit}` to hir_ty_loweringNoah Lev-82/+2
These operations are much more about lowering the HIR than about `Const`s themselves. They fit better in hir_ty_lowering with `lower_const_arg` (formerly `Const::from_const_arg`) and the rest. To accomplish this, `const_evaluatable_predicates_of` had to be changed to not use `from_anon_const` anymore. Instead of visiting the HIR and lowering anon consts on the fly, it now visits the `rustc_middle::ty` data structures instead and directly looks for `UnevaluatedConst`s. This approach was proposed in: https://github.com/rust-lang/rust/pull/131081#discussion_r1821189257
2024-11-24Simplify array length mismatch error reportingMichael Goulet-4/+0
2024-11-23no more Reveal :(lcnr-1/+1
2024-11-19Introduce `min_generic_const_args` and directly represent pathsNoah Lev-95/+9
Co-authored-by: Boxy UwU <rust@boxyuwu.dev> Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-11/+16
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-12Consolidate type system const evaluation under `traits::evaluate_const`Boxy-57/+2
mew
2024-10-22Rollup merge of #131049 - compiler-errors:more-validation, r=spastorinoMatthias Krüger-0/+1
Validate args are correct for `UnevaluatedConst`, `ExistentialTraitRef`/`ExistentialProjection` For the `Existential*` ones, we have to do some adjustment to the args list to deal with the missing `Self` type, so we introduce a `debug_assert_existential_args_compatible` function to the interner as well.
2024-10-19Rename normalize to normalize_internal, remove unnecessary usagesMichael Goulet-1/+1
2024-10-19Get rid of const eval_* and try_eval_* helpersMichael Goulet-100/+32
2024-10-01make InterpResult a dedicated type to avoid accidentally discarding the errorRalf Jung-1/+1
2024-09-30Debug assert that unevaluated consts have the right substsMichael Goulet-0/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-8/+5
2024-09-20Only expect mono consts in CFIMichael Goulet-0/+4
2024-09-12Re-enable `ConstArgKind::Path` lowering by defaultNoah Lev-13/+5
...and remove the `const_arg_path` feature gate as a result. It was only a stopgap measure to fix the regression that the new lowering introduced (which should now be fixed by this PR).
2024-09-11clippy::useless_conversionMichael Goulet-1/+1
2024-08-19Retroactively feature gate `ConstArgKind::Path`Boxy-10/+22
2024-08-16Special-case alias ty in `try_from_lit`Jaic1-0/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+5
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-19Auto merge of #125915 - camelid:const-arg-refactor, r=BoxyUwUbors-41/+85
Represent type-level consts with new-and-improved `hir::ConstArg` ### Summary This is a step toward `min_generic_const_exprs`. We now represent all const generic arguments using an enum that differentiates between const *paths* (temporarily just bare const params) and arbitrary anon consts that may perform computations. This will enable us to cleanly implement the `min_generic_const_args` plan of allowing the use of generics in paths used as const args, while disallowing their use in arbitrary anon consts. Here is a summary of the salient aspects of this change: - Add `current_def_id_parent` to `LoweringContext` This is needed to track anon const parents properly once we implement `ConstArgKind::Path` (which requires moving anon const def-creation outside of `DefCollector`). - Create `hir::ConstArgKind` enum with `Path` and `Anon` variants. Use it in the existing `hir::ConstArg` struct, replacing the previous `hir::AnonConst` field. - Use `ConstArg` for all instances of const args. Specifically, use it instead of `AnonConst` for assoc item constraints, array lengths, and const param defaults. - Some `ast::AnonConst`s now have their `DefId`s created in rustc_ast_lowering rather than `DefCollector`. This is because in some cases they will end up becoming a `ConstArgKind::Path` instead, which has no `DefId`. We have to solve this in a hacky way where we guess whether the `AnonConst` could end up as a path const since we can't know for sure until after name resolution (`N` could refer to a free const or a nullary struct). If it has no chance as being a const param, then we create a `DefId` in `DefCollector` -- otherwise we decide during ast_lowering. This will have to be updated once all path consts use `ConstArgKind::Path`. - We explicitly use `ConstArgHasType` for array lengths, rather than implicitly relying on anon const type feeding -- this is due to the addition of `ConstArgKind::Path`. - Some tests have their outputs changed, but the changes are for the most part minor (including removing duplicate or almost-duplicate errors). One test now ICEs, but it is for an incomplete, unstable feature and is now tracked at https://github.com/rust-lang/rust/issues/127009. ### Followup items post-merge - Use `ConstArgKind::Path` for all const paths, not just const params. - Fix (no github dont close this issue) #127009 - If a path in generic args doesn't resolve as a type, try to resolve as a const instead (do this in rustc_resolve). Then remove the special-casing from `rustc_ast_lowering`, so that all params will automatically be lowered as `ConstArgKind::Path`. - (?) Consider making `const_evaluatable_unchecked` a hard error, or at least trying it in crater r? `@BoxyUwU`
2024-07-18const_to_pat: cleanup leftovers from when we had to deal with non-structural ↵Ralf Jung-14/+38
constants
2024-07-18valtree construction: keep track of which type was valtree-incompatibleRalf Jung-2/+1
2024-07-16Add `ConstArgKind::Path` and make `ConstArg` its own HIR nodeNoah Lev-10/+9
This is a very large commit since a lot needs to be changed in order to make the tests pass. The salient changes are: - `ConstArgKind` gets a new `Path` variant, and all const params are now represented using it. Non-param paths still use `ConstArgKind::Anon` to prevent this change from getting too large, but they will soon use the `Path` variant too. - `ConstArg` gets a distinct `hir_id` field and its own variant in `hir::Node`. This affected many parts of the compiler that expected the parent of an `AnonConst` to be the containing context (e.g., an array repeat expression). They have been changed to check the "grandparent" where necessary. - Some `ast::AnonConst`s now have their `DefId`s created in rustc_ast_lowering rather than `DefCollector`. This is because in some cases they will end up becoming a `ConstArgKind::Path` instead, which has no `DefId`. We have to solve this in a hacky way where we guess whether the `AnonConst` could end up as a path const since we can't know for sure until after name resolution (`N` could refer to a free const or a nullary struct). If it has no chance as being a const param, then we create a `DefId` in `DefCollector` -- otherwise we decide during ast_lowering. This will have to be updated once all path consts use `ConstArgKind::Path`. - We explicitly use `ConstArgHasType` for array lengths, rather than implicitly relying on anon const type feeding -- this is due to the addition of `ConstArgKind::Path`. - Some tests have their outputs changed, but the changes are for the most part minor (including removing duplicate or almost-duplicate errors). One test now ICEs, but it is for an incomplete, unstable feature and is now tracked at #127009.
2024-07-16Use `ConstArg` for const param defaultsNoah Lev-4/+4
Now everything that actually affects the type system (i.e., excluding const blocks, enum variant discriminants, etc.) *should* be using `ConstArg`.
2024-07-16Setup ty::Const functions for `ConstArg`Noah Lev-36/+81
2024-06-18Uplift the new trait solverMichael Goulet-1/+5
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-3/+3
2024-06-06Uplift TypeRelation and RelateMichael Goulet-0/+8
2024-06-05Add `Ty` to `ConstKind::Value`Boxy-25/+22
2024-06-05Basic removal of `Ty` from places (boring)Boxy-96/+48
2024-06-04Downsize `ty::Expr`Boxy-2/+2
2024-05-26Uplift EarlyBinderMichael Goulet-0/+9
2024-05-26Give EarlyBinder a tcx parameterMichael Goulet-1/+4
We are gonna need it to uplift EarlyBinder
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_middle`.Nicholas Nethercote-0/+1
2024-05-20Rework var resolution in InferCtxtLike, uplift EagerResolverMichael Goulet-0/+8
2024-05-13Remove to_termMichael Goulet-4/+0
2024-05-13Uplift AliasTyMichael Goulet-3/+15
2024-05-10Lift `TraitRef` into `rustc_type_ir`Michael Goulet-9/+7
2024-04-29Remove `extern crate rustc_data_structures` from numerous crates.Nicholas Nethercote-2/+2