rust-lang / rust-lang/rust

Validate HIR ty lowering's produced generic parameters

Open
#150,620 0 comments 0 reactions 2 assignees View on GitHub

@camelid is already working on this.

Since Jan 2, 2026.

A-HIR-ty-lowering A-technical-debt C-cleanup E-needs-design F-min_generic_const_args T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

In #150519 we added some checks to HIR ty lowering that when lowering to a generic parameter, we aren't inside of an anon const for const generics which shouldn't be able to use generic parameters.

There are a two main bits of follow up work here:

  1. The current impl is fairly brittle, it requires special casing all places that we're aware of as potentially introducing uses of generic parameters that shouldn't be allowed. We've previously got this wrong (#150519). I don't know how likely it is that we've correctly checked all positions
  2. It only applies to anon consts from const generics. In theory it would be nice if we checked all generic parameters we find against the generics_of of the item we're inside of and asserted they are actually supposed to be nameable

I expect things to be quite perf sensitive here, and also it seems hard to get a good API here. cc @camelid

I've tagged this as F-min_generic_const_args as we rely quite heavily on this check for mGCA as we don't do any validation at name resolution time. But this logic is used on stable and it would be good to have these assertions on stable too

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.