Skip to content

Allow self in const generics#157949

Draft
bb1yd wants to merge 2 commits into
rust-lang:mainfrom
bb1yd:allow-self-in-const-generics
Draft

Allow self in const generics#157949
bb1yd wants to merge 2 commits into
rust-lang:mainfrom
bb1yd:allow-self-in-const-generics

Conversation

@bb1yd

@bb1yd bb1yd commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #149203

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 16, 2026
@@ -1535,7 +1535,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

RibKind::ConstParamTy => {

@fmease fmease Jun 16, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IINM you're now accepting this code despite N depending on T which shouldn't be allowed w/o enabling GCPT.

impl<T> Wrap<T> {
    fn f<const N: Self>() {}
}

struct Wrap<T>(T);

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to check if Self depends on generics?

@fmease fmease Jun 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not super well-versed in name resolution, so I don't know if there's a good way to do this in rustc_resolve that still nicely leverages the existing rib structure. Boxy probably has an idea.

Calling type_of here on the LocalDefId found in the SelfTyAlias is probably too prone to cycles or hangs; looking at hir_node corresp. to the LocalDefId might be an option but that might not integrate with the visitor.

Naively speaking, I would do it in HIR ty lowering by inspecting the type as returned by type_of and by reusing+generalizing check_assoc_const_binding_type but that's probably also not super ideal. I haven't read a lot of the new mGCA code in HIR ty lowering, maybe there's already a function for that (that's similar to check_assoc_const_binding_type?)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self not allowed in type of const generics even when it's concrete

4 participants