Skip to content

Fix extract_type_alias and provide inlay hints for const _ placeholders#22211

Open
nicolas-guichard wants to merge 3 commits into
rust-lang:masterfrom
nicolas-guichard:push-qltvotzxsuqw
Open

Fix extract_type_alias and provide inlay hints for const _ placeholders#22211
nicolas-guichard wants to merge 3 commits into
rust-lang:masterfrom
nicolas-guichard:push-qltvotzxsuqw

Conversation

@nicolas-guichard
Copy link
Copy Markdown
Contributor

@nicolas-guichard nicolas-guichard commented Apr 29, 2026

This is basically the extension of #20125 to const generics.

Before:
image

After:
image

Blocked on #22237.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 29, 2026
@nicolas-guichard nicolas-guichard force-pushed the push-qltvotzxsuqw branch 2 times, most recently from aac49b9 to 5980265 Compare April 29, 2026 18:47
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

I have a branch that rewrites how we collect placeholders to be more principled (pass the table and the InferCtxt to TyLoweringContext), so it should be merged before this.

@nicolas-guichard
Copy link
Copy Markdown
Contributor Author

Oh right, thanks!

@nicolas-guichard nicolas-guichard marked this pull request as draft May 1, 2026 12:15
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 1, 2026
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

This extends InferenceResult with a new const_of_const_placeholders map
to record which const a given const or type placeholder gets resolved
to.

This is basically the same as type_of_type_placeholder, but for consts.

Note that while surprising, TypeRef::Placeholder may indeed resolve to
a const because except for arrays the parser doesn't know ahead of type
if a _ will resolve to a type or a const.

In the case of an array, we have an Expr::Underscore:
```
let a: [_; _] = [4, 5, 6];
      //^ TypeRef::Placeholder that resolves to the type i32
         //^ Expr::Underscore that resolves to the const 3
```

But for a struct we have a TypeRef::Placeholder:
```
struct S<T, const N: usize>([T; N]);

let s: S<_, _> = S([1, 2, 3]);
       //^ TypeRef::Placeholder that resolves to the type i32
          //^ TypeRef::Placeholder that resolves to the const 3
```
This fixes SourceAnalyzer::type_of_type to replace const infer vars in
types with their resolved value.
This provides an inlay hint for _ in const generic arguments.
@nicolas-guichard nicolas-guichard marked this pull request as ready for review May 18, 2026 13:48
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants