This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit 8c3a94a
committed
Auto merge of rust-lang#125915 - camelid:const-arg-refactor, r=BoxyUwU
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 rust-lang#127009.
### Followup items post-merge
- Use `ConstArgKind::Path` for all const paths, not just const params.
- Fix (no github dont close this issue) rust-lang#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`File tree
72 files changed
+850
-540
lines changed- compiler
- rustc_ast_lowering/src
- rustc_hir_analysis/src
- collect
- hir_ty_lowering
- rustc_hir_pretty/src
- rustc_hir_typeck/src
- fn_ctxt
- method
- rustc_hir/src
- rustc_infer/src/error_reporting/infer
- rustc_lint/src
- rustc_middle/src
- hir/map
- ty
- rustc_passes/src
- rustc_resolve/src
- rustc_trait_selection/src/traits
- src
- librustdoc/clean
- tools/clippy
- clippy_lints/src
- utils
- clippy_utils/src
- tests/ui
- author
- tests
- crashes
- ui-fulldeps/stable-mir
- ui
- coherence/negative-coherence
- const-generics
- generic_const_exprs
- issues
- consts
- lifetimes
- rfcs/rfc-2632-const-trait-impl
- specialization
- min_specialization
- stats
- traits/non_lifetime_binders
- transmutability
- typeck/issue-114918
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
72 files changed
+850
-540
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
| 190 | + | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
226 | 226 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
234 | 237 | | |
235 | 238 | | |
236 | | - | |
| 239 | + | |
237 | 240 | | |
238 | 241 | | |
239 | 242 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
| |||
377 | 382 | | |
378 | 383 | | |
379 | 384 | | |
380 | | - | |
| 385 | + | |
381 | 386 | | |
382 | 387 | | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
391 | 393 | | |
392 | 394 | | |
393 | 395 | | |
| |||
622 | 624 | | |
623 | 625 | | |
624 | 626 | | |
| 627 | + | |
625 | 628 | | |
626 | 629 | | |
627 | 630 | | |
| |||
672 | 675 | | |
673 | 676 | | |
674 | 677 | | |
675 | | - | |
676 | | - | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
677 | 681 | | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
684 | 688 | | |
685 | | - | |
| 689 | + | |
| 690 | + | |
686 | 691 | | |
687 | 692 | | |
688 | 693 | | |
689 | 694 | | |
690 | | - | |
| 695 | + | |
691 | 696 | | |
692 | 697 | | |
693 | 698 | | |
| |||
966 | 971 | | |
967 | 972 | | |
968 | 973 | | |
| 974 | + | |
969 | 975 | | |
970 | 976 | | |
971 | 977 | | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
990 | 998 | | |
991 | 999 | | |
992 | 1000 | | |
993 | 1001 | | |
994 | 1002 | | |
995 | 1003 | | |
996 | 1004 | | |
997 | | - | |
| 1005 | + | |
998 | 1006 | | |
999 | 1007 | | |
1000 | 1008 | | |
| |||
1066 | 1074 | | |
1067 | 1075 | | |
1068 | 1076 | | |
| 1077 | + | |
1069 | 1078 | | |
1070 | 1079 | | |
1071 | 1080 | | |
| |||
1075 | 1084 | | |
1076 | 1085 | | |
1077 | 1086 | | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | | - | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
1092 | 1102 | | |
1093 | | - | |
1094 | | - | |
| 1103 | + | |
| 1104 | + | |
1095 | 1105 | | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
1099 | 1110 | | |
1100 | 1111 | | |
1101 | 1112 | | |
| |||
1106 | 1117 | | |
1107 | 1118 | | |
1108 | 1119 | | |
1109 | | - | |
| 1120 | + | |
1110 | 1121 | | |
1111 | 1122 | | |
1112 | 1123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
| |||
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
247 | 257 | | |
248 | 258 | | |
249 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| |||
713 | 716 | | |
714 | 717 | | |
715 | 718 | | |
716 | | - | |
| 719 | + | |
717 | 720 | | |
718 | 721 | | |
719 | 722 | | |
| |||
1601 | 1604 | | |
1602 | 1605 | | |
1603 | 1606 | | |
1604 | | - | |
| 1607 | + | |
1605 | 1608 | | |
1606 | 1609 | | |
1607 | 1610 | | |
1608 | 1611 | | |
1609 | 1612 | | |
1610 | 1613 | | |
1611 | 1614 | | |
1612 | | - | |
| 1615 | + | |
1613 | 1616 | | |
1614 | 1617 | | |
1615 | 1618 | | |
| |||
1624 | 1627 | | |
1625 | 1628 | | |
1626 | 1629 | | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
1627 | 1641 | | |
1628 | 1642 | | |
1629 | 1643 | | |
| |||
1648 | 1662 | | |
1649 | 1663 | | |
1650 | 1664 | | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
1654 | | - | |
1655 | | - | |
1656 | | - | |
| 1665 | + | |
1657 | 1666 | | |
1658 | 1667 | | |
1659 | 1668 | | |
| |||
0 commit comments