Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject function items as const arguments #136408

Closed

Conversation

charmitro
Copy link
Contributor

This commit addresses an ICE caused by using function items as const arguments in generic contexts. Previously, the compiler would panic when encountering such cases due to unsupported behavior in min_generic_const_args. This fix improves error handling by detecting function items in lower_const_arg and emitting a user-friendly error message instead of crashing.

Changes:

  • Added logic in hir_ty_lowering::lower_const_arg to detect and reject function items as const arguments.
  • Introduced a new UI test (fn-item-as-const-arg.rs) to validate the fix.

Fixes #136337

This commit addresses an ICE caused by using function items as const
arguments in generic contexts. Previously, the compiler would panic when
encountering such cases due to unsupported behavior in
`min_generic_const_args`. This fix improves error handling by detecting
function items in `lower_const_arg` and emitting a user-friendly error
message instead of crashing.

Changes:
- Added logic in `hir_ty_lowering::lower_const_arg` to detect and reject
  function items as const arguments.
- Introduced a new UI test (`fn-item-as-const-arg.rs`) to validate the
  fix.

Signed-off-by: Charalampos Mitrodimas <[email protected]>
@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2025

r? @davidtwco

rustbot has assigned @davidtwco.
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

@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 Feb 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2025

HIR ty lowering was modified

cc @fmease

@charmitro
Copy link
Contributor Author

Closing, this needs much more thought, as per the comment in compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:

// FIXME(const_generics): create real const to allow fn items as const paths

@charmitro charmitro closed this Feb 2, 2025
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. 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.

ICE: fn items cannot be used as const args
3 participants