Skip to content

Document Ambig vs Unambig Type/Consts #2474

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Jun 17, 2025

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Jun 17, 2025

Thanks for the PR. If you have write access, feel free to merge this PR if it does not need reviews. You can request a review using r? rustc-dev-guide or r? <username>.

@rustbot rustbot added the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Jun 17, 2025
@BoxyUwU BoxyUwU requested a review from lcnr June 17, 2025 14:57
@BoxyUwU BoxyUwU force-pushed the ambig_unambig_ty_consts branch from 3972cf8 to c963b4a Compare June 17, 2025 17:09
parse.

```rust
fn func<T, const N: usize,>(arg: T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn func<T, const N: usize,>(arg: T) {
fn func<T, const N: usize>(arg: T) {


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The visit_infer link doesn't match the visit_ty text.

- 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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe clarify here that points 3 and 4 are the cases where there was enough other information around to disambiguate into either a type or a const?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants