Skip to content

fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args#155198

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
JayanAXHF:mgca/const-generic-args
Jun 11, 2026
Merged

Conversation

@JayanAXHF

@JayanAXHF JayanAXHF commented Apr 12, 2026

Copy link
Copy Markdown
Member

View all comments

Closes #154915

Basically, we check if there are three segments and if the first one is a DefKind::Enum, and then use the correct segment for Enum::<...>::Variant syntax for both DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)

PS: i'm not sure if the common logic from these two branches could be extracted

r? fmease

@rustbot

rustbot commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 12, 2026
@rust-log-analyzer

This comment has been minimized.

@JayanAXHF JayanAXHF force-pushed the mgca/const-generic-args branch from f0b92a1 to 28594d7 Compare April 13, 2026 13:15
@JayanAXHF

Copy link
Copy Markdown
Member Author

Fixed that @fmease

@fmease fmease left a comment

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.

Thanks for working on this! I got some thoughts, apologies for the many comments; most of them are really minor that can be fixed super quickly.

View changes since this review

Comment thread tests/ui/enum/enum-min-const-generic-args.rs Outdated
Comment thread tests/ui/enum/enum-min-const-generic-args.rs Outdated
Comment thread tests/ui/enum/enum-min-const-generic-args.rs Outdated
Comment thread tests/ui/enum/enum-min-const-generic-args.rs Outdated
.prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);

// Check if this is the Enum::<...>::Variant form
let use_enum_segment = if path.segments.len() == 2

@fmease fmease Apr 13, 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.

The path should be allowed to have more than two segments. Right now, you're only allowing Enum::<...>::Variant but not e.g., very::long::path::to::Enum::<...>::Variant. So it should be >= 2 rather than == 2.

Once you implement that you also need to make sure to reject arguments on all segments before the enum segment since module::<...>::Enum::<...>::Variant should be forbidden.

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 13, 2026
@JayanAXHF

Copy link
Copy Markdown
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2026

@fmease fmease left a comment

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 so sorry for the delay! Some final comments

View changes since this review

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
let _ = self
.prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);

let generics = self.probe_generic_path_segments(

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 glad my suggestion to use probe_generic_path_segments is working out.

However, calling that function isn't sufficient, you still need (manually) prohibit generic args on all path segments that aren't generic using prohibit_generic_args, I know this API is a bit awkward. See the preexisting callers of probe_generic_path_segments for how they do it.

(I guess it could be nice if we'd have one function that does the "probing" and the "prohibiting" at once for convenience but I don't think we can do that yet w/o refactoring some things first, so that has to wait for another time)

@JayanAXHF JayanAXHF May 25, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think we can do that yet w/o refactoring some things first

I believe we can. Currently, how this is done is

                let generic_segments =
                    self.probe_generic_path_segments(path.segments, opt_self_ty, kind, did, span);
                let indices: FxHashSet<_> =
                    generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
                let _ = self.prohibit_generic_args(
                    path.segments.iter().enumerate().filter_map(|(index, seg)| {
                        if !indices.contains(&index) { Some(seg) } else { None }
                    }),
                    GenericsArgsErrExtend::DefVariant(&path.segments),
                );

I believe this could just be turned into a function

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.

Ah, in that case, go for it! Unless you'd to leave it to a follow-up PR; this way we can merge this PR faster :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's go for a follow-up PR. I'll create an issue so i don't forget if that's okay

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 8, 2026
@JayanAXHF

Copy link
Copy Markdown
Member Author

apologies for the delay, will look into this on the weekend

@rustbot

This comment has been minimized.

@JayanAXHF JayanAXHF force-pushed the mgca/const-generic-args branch from c9459f9 to 1e6067d Compare May 25, 2026 13:40
@rustbot

rustbot commented May 25, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@JayanAXHF

Copy link
Copy Markdown
Member Author

Made the changes @fmease

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 25, 2026

@fmease fmease left a comment

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.

Apologies for the delay, two final nits and one other note.

View changes since this review

Comment thread tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs Outdated
Comment thread tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs Outdated
let _ = self
.prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);

let generics = self.probe_generic_path_segments(

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.

Ah, in that case, go for it! Unless you'd to leave it to a follow-up PR; this way we can merge this PR faster :)

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 8, 2026
@JayanAXHF JayanAXHF added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 8, 2026
@rust-log-analyzer

This comment has been minimized.

@fmease fmease removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 8, 2026
@fmease fmease added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 8, 2026
…unit & tuple variant constructions in (direct) const args
@fmease fmease force-pushed the mgca/const-generic-args branch from 9d936c2 to 7fe4408 Compare June 10, 2026 21:43
@fmease

fmease commented Jun 10, 2026

Copy link
Copy Markdown
Member

Thanks for your work and your patience! :)

I've --bless'ed the failing test since that was all it needed. and I took the liberty to squash your commits. @bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7fe4408 has been approved by fmease

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 10, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
… r=fmease

fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args

Closes rust-lang#154915

Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)`

PS: i'm not sure if the common logic from these two branches could be extracted

r? fmease
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
… r=fmease

fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args

Closes rust-lang#154915

Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)`

PS: i'm not sure if the common logic from these two branches could be extracted

r? fmease
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
… r=fmease

fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args

Closes rust-lang#154915

Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)`

PS: i'm not sure if the common logic from these two branches could be extracted

r? fmease
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
… r=fmease

fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args

Closes rust-lang#154915

Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)`

PS: i'm not sure if the common logic from these two branches could be extracted

r? fmease
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
Rollup of 31 pull requests

Successful merges:

 - #141030 (Expand free alias types during variance computation)
 - #154853 (mgca: Register `ConstArgHasType` when normalizing projection consts)
 - #155527 (Replace printables table with `unicode_data.rs` tables)
 - #156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`)
 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157611 (Update `browser-ui-test` version to `0.24.0`)
 - #157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - #157646 (Keep rename-imported main alive in dead-code analysis under `--test`)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - #155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os})
 - #155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args)
 - #155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`)
 - #156497 (fix-155516: Don't suggest wrong unwrap expect)
 - #156583 (Support defaults for static EIIs)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157196 (Only suggest reborrowing a moved value where the reborrow is valid)
 - #157230 (borrowck: avoid ICE describing fields on generic params)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157330 (remove `IsTypeConst` from `hir::TraitItemKind`)
 - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
@rust-bors rust-bors Bot merged commit 644c882 into rust-lang:main Jun 11, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 11, 2026
rust-timer added a commit that referenced this pull request Jun 11, 2026
Rollup merge of #155198 - JayanAXHF:mgca/const-generic-args, r=fmease

fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args

Closes #154915

Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)`

PS: i'm not sure if the common logic from these two branches could be extracted

r? fmease
LaneAsade pushed a commit to LaneAsade/rust that referenced this pull request Jun 11, 2026
Rollup of 31 pull requests

Successful merges:

 - rust-lang#141030 (Expand free alias types during variance computation)
 - rust-lang#154853 (mgca: Register `ConstArgHasType` when normalizing projection consts)
 - rust-lang#155527 (Replace printables table with `unicode_data.rs` tables)
 - rust-lang#156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`)
 - rust-lang#157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - rust-lang#157282 (Fix post-monomorphization error note race in the parallel frontend)
 - rust-lang#157352 (Make the retained dep graph deterministic under the parallel frontend)
 - rust-lang#157601 (Emit error for unused target expression in glob and list delegations)
 - rust-lang#157611 (Update `browser-ui-test` version to `0.24.0`)
 - rust-lang#157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - rust-lang#157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - rust-lang#157646 (Keep rename-imported main alive in dead-code analysis under `--test`)
 - rust-lang#157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - rust-lang#157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - rust-lang#155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os})
 - rust-lang#155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args)
 - rust-lang#155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`)
 - rust-lang#156497 (fix-155516: Don't suggest wrong unwrap expect)
 - rust-lang#156583 (Support defaults for static EIIs)
 - rust-lang#157013 (Ensure inferred let pattern types are well-formed)
 - rust-lang#157196 (Only suggest reborrowing a moved value where the reborrow is valid)
 - rust-lang#157230 (borrowck: avoid ICE describing fields on generic params)
 - rust-lang#157288 (platform support: add SNaN erratum to MIPS targets)
 - rust-lang#157330 (remove `IsTypeConst` from `hir::TraitItemKind`)
 - rust-lang#157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - rust-lang#157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - rust-lang#157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - rust-lang#157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - rust-lang#157691 (Move symbol hiding code to a new file)
 - rust-lang#157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - rust-lang#157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - rust-lang#157699 (Arg splat experiment - hir FnDecl impl)
LaneAsade pushed a commit to LaneAsade/rust that referenced this pull request Jun 11, 2026
Rollup of 31 pull requests

Successful merges:

 - rust-lang#141030 (Expand free alias types during variance computation)
 - rust-lang#154853 (mgca: Register `ConstArgHasType` when normalizing projection consts)
 - rust-lang#155527 (Replace printables table with `unicode_data.rs` tables)
 - rust-lang#156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`)
 - rust-lang#157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - rust-lang#157282 (Fix post-monomorphization error note race in the parallel frontend)
 - rust-lang#157352 (Make the retained dep graph deterministic under the parallel frontend)
 - rust-lang#157601 (Emit error for unused target expression in glob and list delegations)
 - rust-lang#157611 (Update `browser-ui-test` version to `0.24.0`)
 - rust-lang#157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - rust-lang#157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - rust-lang#157646 (Keep rename-imported main alive in dead-code analysis under `--test`)
 - rust-lang#157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - rust-lang#157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - rust-lang#155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os})
 - rust-lang#155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args)
 - rust-lang#155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`)
 - rust-lang#156497 (fix-155516: Don't suggest wrong unwrap expect)
 - rust-lang#156583 (Support defaults for static EIIs)
 - rust-lang#157013 (Ensure inferred let pattern types are well-formed)
 - rust-lang#157196 (Only suggest reborrowing a moved value where the reborrow is valid)
 - rust-lang#157230 (borrowck: avoid ICE describing fields on generic params)
 - rust-lang#157288 (platform support: add SNaN erratum to MIPS targets)
 - rust-lang#157330 (remove `IsTypeConst` from `hir::TraitItemKind`)
 - rust-lang#157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - rust-lang#157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - rust-lang#157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - rust-lang#157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - rust-lang#157691 (Move symbol hiding code to a new file)
 - rust-lang#157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - rust-lang#157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - rust-lang#157699 (Arg splat experiment - hir FnDecl impl)
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@rust-timer build 4858221

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued 4858221 with parent 485ec3f, future comparison URL.
There are currently 3 preceding artifacts in the queue.
It will probably take at least ~3.7 hours until the benchmark run finishes.

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

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

mGCA: Can't specify generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args

6 participants