rust/src/librustdoc
bors 8c3a94a1c7 Auto merge of #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 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-19 08:44:51 +00:00
..
clean Remove some unintended changes to imports 2024-07-17 20:31:37 -07:00
doctest Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
formats Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk" 2024-06-06 10:06:28 +00:00
html Wrap too long item name and improve the item list display a bit 2024-07-18 20:48:20 +02:00
json Add rustdoc-json support for use<> 2024-07-12 05:24:51 -04:00
passes Rollup merge of #127301 - estebank:fix-suggestions, r=Urgau 2024-07-04 18:16:24 +02:00
theme rustdoc: merge theme css into rustdoc.css 2023-09-15 07:40:17 -07:00
askama.toml Remove unneeded minus sign in jinja tags 2023-03-06 11:38:15 +01:00
Cargo.toml rustdoc: add usable lint for pulldown-cmark-0.11 parsing changes 2024-07-01 07:21:02 -07:00
config.rs Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
core.rs Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
docfs.rs remove redundant imports 2023-12-10 10:56:22 +08:00
doctest.rs Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
error.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
externalfiles.rs Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
fold.rs Implement unsafe_extern_blocks feature in rustdoc 2024-06-20 22:12:35 +02:00
lib.rs Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
lint.rs Auto merge of #127097 - compiler-errors:async-closure-lint, r=oli-obk 2024-07-11 06:59:10 +00:00
markdown.rs Move Markdown-specific doctest code into submodule 2024-06-07 17:48:47 +02:00
README.md rust-lang.github.io/rustc-dev-guide -> rustc-dev-guide.rust-lang.org 2020-03-10 17:08:18 -03:00
scrape_examples.rs Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
theme.rs Use a dedicated type instead of a reference for the diagnostic context 2024-06-18 15:42:11 +00:00
visit.rs Implement unsafe_extern_blocks feature in rustdoc 2024-06-20 22:12:35 +02:00
visit_ast.rs Don't require visit_body to take a lifetime that must outlive the function call 2024-05-29 10:04:08 +00:00
visit_lib.rs Correctly handle --document-hidden-items 2023-07-14 17:25:09 +02:00

For more information about how librustdoc works, see the rustc dev guide.