10000 rustc-dev-guide subtree update by tshepang · Pull Request #142743 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

rustc-dev-guide subtree update #142743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jun 20, 2025
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9aa572d
use consistent title capitalization
tshepang May 22, 2025
a4c8ef9
Adjust some doc for Query System
xizheyin Jun 13, 2025
94d56d1
Merge pull request #2441 from rust-lang/tshepang-remove-title-case
tshepang Jun 14, 2025
9265493
Merge pull request #2465 from xizheyin/rustc-query
tshepang Jun 14, 2025
a70deb6
content has moved to another chapter
tshepang Jun 14, 2025
9926215
Merge pull request #2466 from rust-lang/tshepang-moved
tshepang Jun 14, 2025
0834e48
use sentence case
tshepang Jun 14, 2025
a3f261c
Merge pull request #2467 from rust-lang/tshepang-patch-1
tshepang Jun 14, 2025
820e88a
title case
tshepang Jun 14, 2025
21a1e51
do not inline links
tshepang Jun 14, 2025
d16e1a1
Merge pull request #2468 from rust-lang/query-cleaning
tshepang Jun 14, 2025
808d16c
Use stage 1 for building docs
Darksonn Jun 16, 2025
3edb332
Merge pull request #2471 from Darksonn/patch-1
Noratrieb Jun 16, 2025
1dbf86a
Remove hanging parenthesis from example signature.
cbloodsworth Jun 16, 2025
02334e1
Merge pull request #2472 from cbloodsworth/fix/tytable_parens
BoxyUwU Jun 16, 2025
8bc55da
Profiling with perf: specify the section of bootstrap settings.
lolbinarycat Jun 17, 2025
671817f
Merge pull request #2475 from lolbinarycat/patch-3
Noratrieb Jun 17, 2025
d96b2d4
Stub chapter and consolidate under `/hir/`
BoxyUwU Jun 6, 2025
42888bb
Write chapter on Unambig vs Ambig Types/Consts
BoxyUwU Jun 17, 2025
c1506c0
Add links
BoxyUwU Jun 17, 2025
39e9800
Reviews
BoxyUwU Jun 18, 2025
6c7830e
Merge pull request #2474 from BoxyUwU/ambig_unambig_ty_consts
BoxyUwU Jun 18, 2025
4145596
fix markup
tshepang Jun 18, 2025
79652d9
Merge pull request #2476 from rust-lang/tshepang-patch-1
tshepang Jun 18, 2025
0a185e4
initial instructions for gpu offload
ZuseZ4 Jun 2, 2025
f25cfe8
Merge pull request #2447 from rust-lang/offload-docs
ZuseZ4 Jun 19, 2025
48b36ee
Preparing for merge from rustc
invalid-email-address Jun 19, 2025
d854d56
Merge from rustc
invalid-email-address Jun 19, 2025
6ad42bf
Merge pull request #2477 from rust-lang/rustc-pull
tshepang Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reviews
  • Loading branch information
BoxyUwU committed Jun 18, 2025
commit 39e98006ac3ef94bdb05da9a25d48f8f788c7cd3
24 changes: 12 additions & 12 deletions src/doc/rustc-dev-guide/src/hir/ambig-unambig-ty-and-consts.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Ambig/Unambig Types and Consts

Types and Consts args in the HIR can be in two kinds of positions "ambig" or "unambig". Ambig positions are where
Types and Consts args in the HIR can be in two kinds of positions ambiguous (ambig) or unambiguous (unambig). Ambig positions are where
it would be valid to parse either a type or a const, unambig positions are where only one kind would be valid to
parse.

```rust
fn func<T, const N: usize,>(arg: T) {
fn func<T, const N: usize>(arg: T) {
// ^ Unambig type position
let a: _ = arg;
// ^ Unambig type position
Expand All @@ -21,19 +21,19 @@ fn func<T, const N: usize,>(arg: T) {

```

Most types/consts in ambig positions are able to be disambiguated as either a type or const during either parsing or ast-lowering.
Currently the only exception to this is inferred generic arguments in path segments. In `Foo<_>` it is not clear whether the `_` argument is an
inferred type argument, or an inferred const argument.
Most types/consts in ambig positions are able to be disambiguated as either a type or const during parsing. Single segment paths are always represented as types in the AST but may get resolved to a const parameter during name resolution, then lowered to a const argument during ast-lowering. The only generic arguments which remain ambiguous after lowering are inferred generic arguments (`_`) in path segments. For example, in `Foo<_>` it is not clear whether the `_` argument is an inferred type argument, or an inferred const argument.

In unambig positions, inferred arguments are represented with [`hir::TyKind::Infer`][ty_infer] or [`hir::ConstArgKind::Infer`][const_infer] depending on whether it is a type or const position respectively.
In ambig positions, inferred arguments are represented with `hir::GenericArg::Infer`.

A naive implementation of this structure would result in there being potentially 5 places where an inferred type/const could be found in the HIR if you just looked at the types:
- In unambig type position as a `hir::TyKind::Infer`
- In unambig const arg position as a `hir::ConstArgKind::Infer`
- In an ambig position as a [`GenericArg::Type(TyKind::Infer)`][generic_arg_ty]
- In an ambig position as a [`GenericArg::Const(ConstArgKind::Infer)`][generic_arg_const]
- In an ambig position as a [`GenericArg::Infer`][generic_arg_infer]
A naive implementation of this would result in there being potentially 5 places where you might think an inferred type/const could be found in the HIR from looking at the structure of the HIR:
1. In unambig type position as a `hir::TyKind::Infer`
2. In unambig const arg position as a `hir::ConstArgKind::Infer`
3. In an ambig position as a [`GenericArg::Type(TyKind::Infer)`][generic_arg_ty]
4. In an ambig position as a [`GenericArg::Const(ConstArgKind::Infer)`][generic_arg_const]
5. In an ambig position as a [`GenericArg::Infer`][generic_arg_infer]

Note that places 3 and 4 would never actually be possible to encounter as we always lower to `GenericArg::Infer` in generic arg position.

This has a few failure modes:
- People may write visitors which check for `GenericArg::Infer` but forget to check for `hir::TyKind/ConstArgKind::Infer`, only handling infers in ambig positions by accident.
Expand All @@ -45,7 +45,7 @@ To make writing HIR visitors less error prone when caring about inferred types/c

1. We have different types in the compiler for when a type or const is in an unambig or ambig position, `hir::Ty<AmbigArg>` and `hir::Ty<()>`. [`AmbigArg`][ambig_arg] is an uninhabited type which we use in the `Infer` variant of `TyKind` and `ConstArgKind` to selectively "disable" it if we are in an ambig position.

2. The [`visit_ty`][visit_infer] and [`visit_const_arg`][visit_const_arg] methods on HIR visitors only accept the ambig position versions of types/consts. Unambig types/consts are implicitly converted to ambig types/consts during the visiting process, with the `Infer` variant handled by a dedicated [`visit_infer`][visit_infer] method.
2. The [`visit_ty`][visit_ty] and [`visit_const_arg`][visit_const_arg] methods on HIR visitors only accept the ambig position versions of types/consts. Unambig types/consts are implicitly converted to ambig types/consts during the visiting process, with the `Infer` variant handled by a dedicated [`visit_infer`][visit_infer] method.

This has a number of benefits:
- It's clear that `GenericArg::Type/Const` cannot represent inferred type/const arguments
Expand Down
0