Skip to content

Reject static item as direct const generic arg#158479

Open
Shourya742 wants to merge 3 commits into
rust-lang:mainfrom
Shourya742:2026-06-27-emit-error-during-ast-lower-using-static-const
Open

Reject static item as direct const generic arg#158479
Shourya742 wants to merge 3 commits into
rust-lang:mainfrom
Shourya742:2026-06-27-emit-error-during-ast-lower-using-static-const

Conversation

@Shourya742

@Shourya742 Shourya742 commented Jun 27, 2026

Copy link
Copy Markdown
Member

closes: #136139

This PR fixes the ICE and not add support for static in MGCA

@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 Jun 27, 2026
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 17 candidates

@Shourya742

Copy link
Copy Markdown
Member Author

r? @BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned JohnTitor Jun 27, 2026
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-06-27-emit-error-during-ast-lower-using-static-const branch from 67f73a3 to c5de45f Compare June 27, 2026 14:27
@BoxyUwU

BoxyUwU commented Jul 8, 2026

Copy link
Copy Markdown
Member

sry for taking so long to get to this, thanks for looking into this ICE ✨

This probably merge conflicts with #158617, but more usefully it'd theoretically also let us fallback to an anon const instead of erroring if we wish 🤔 though i think for now i'd like to hold off on making the can_lower_to_direct_const_arg too clever (i.e. using name res information) which means that continuing to error feels right.

i think I would prefer for us to not handle special case statics during ast lowering in any way, and instead error during HIR ty lowering when encountering a static 🤔 im not sure I understand why I feel this way 😅 we do already have some semantic checks in HIR ty lowering about what kind of thing we resolved to (e.g. type const or non type const) so I think it just feels like we do our semantic checks there and syntactic checks in ast lowering.

can you emit these errors in HIR ty lowering instead :3

let msg = "complex const arguments must be placed inside of a `const` block";
hir::ConstArgKind::Error(self.dcx().struct_span_err(span, msg).emit())
} else if is_trivial_path || tcx.features().min_generic_const_args() {
let qpath = self.lower_qpath(

@BoxyUwU BoxyUwU Jul 8, 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.

cc @khyperia i don't think we handled this codepath in your PR overhauling ast lowering for mgca. we should probably be checking can_lower_to_direct_const_arg here and then also reusing the lower_expr_to_direct logic here? though it would really just be the path arms right now but still... seems nice for consistency/sharing logic 🤔

unrelated to this PR, just something i realised while reading this

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yus, the logic here happens to be identical even with the syntax flip PR, but, it's a very wishy-washy "happens to be correct" and you're absolutely right that these should share a codepath so they don't accidentally diverge

@BoxyUwU

BoxyUwU commented Jul 8, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot 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 Jul 8, 2026
@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-06-27-emit-error-during-ast-lower-using-static-const branch from c5de45f to fc02351 Compare July 11, 2026 03:45
@rustbot

rustbot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@Shourya742
Shourya742 requested a review from BoxyUwU July 11, 2026 03:45
@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 Jul 11, 2026
@Shourya742

Copy link
Copy Markdown
Member Author

can you emit these errors in HIR ty lowering instead :3

Added

@BoxyUwU

BoxyUwU commented Jul 22, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup

thx gamer :3`

@rust-bors

rust-bors Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit fc02351 has been approved by BoxyUwU

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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 22, 2026
…uring-ast-lower-using-static-const, r=BoxyUwU

Reject static item as direct const generic arg

closes: rust-lang#136139

This PR fixes the ICE and not add support for static in MGCA
rust-bors Bot pushed a commit that referenced this pull request Jul 22, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #159712 (Subtree sync for rustc_codegen_cranelift)
 - #155697 (Stabilize c-variadic function definitions)
 - #159285 (Simplify `apply_effects_in_range`)
 - #159596 (unify the AST repr of type const and const RHS)
 - #159607 (test: update riscv32e-registers.rs for LLVM 24 MC diagnostic changes)
 - #159659 (Move `Limit` out of `rustc_hir`)
 - #159707 (fix error when a dangling ref in a ManuallyDrop is used in a pattern)
 - #158479 (Reject static item as direct const generic arg)
 - #158738 (next_trait_solver: Recover from GCE const exprs)
 - #159451 (Remove config cloning in compiletest)
 - #159646 (Increase depth for float infer var fallback hack)
 - #159705 (bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests)
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #159723 (comment)

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 22, 2026
@rust-bors

rust-bors Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#159723), which was unapproved.

View changes since this unapproval

@khyperia

Copy link
Copy Markdown
Contributor

Ah, that’s probably due to work I did, sorry! (implementing macroless_generic_const_args)

The test should probably either use the direct_const_arg macro, or enable the macroless feature

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the 2026-06-27-emit-error-during-ast-lower-using-static-const branch from fc02351 to b4c60f0 Compare July 23, 2026 11:30
@Shourya742

Copy link
Copy Markdown
Member Author

Ah, that’s probably due to work I did, sorry! (implementing macroless_generic_const_args)

The test should probably either use the direct_const_arg macro, or enable the macroless feature

enabling macroless worked like a charm 🎆 , thanks.

@Shourya742

Shourya742 commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

@BoxyUwU, nugding for this. This is the job that failed: auto - x86_64-gnu-llvm-21-3.

Though I think it should be fine. After rebasing the branch locally, the test started failing, and once I enabled the macroless feature, it passed again. So I think we can go with either option.

@BoxyUwU

BoxyUwU commented Jul 23, 2026

Copy link
Copy Markdown
Member

@bors r+

yeah macroless gca seems fine to me here 👍

@rust-bors

rust-bors Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b4c60f0 has been approved by BoxyUwU

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 Jul 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
…uring-ast-lower-using-static-const, r=BoxyUwU

Reject static item as direct const generic arg

closes: rust-lang#136139

This PR fixes the ICE and not add support for static in MGCA
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
…uring-ast-lower-using-static-const, r=BoxyUwU

Reject static item as direct const generic arg

closes: rust-lang#136139

This PR fixes the ICE and not add support for static in MGCA
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.

Rustc crashes at compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2156:17

7 participants