Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2791,8 +2791,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Res::Def(DefKind::Static { .. }, _) => {
span_bug!(span, "use of bare `static` ConstArgKind::Path's not yet supported")
}
Res::Def(DefKind::AssocFn, _) => {
let guar =
self.dcx().span_err(span, "function items cannot be used as const arguments");
Const::new_error(tcx, guar)
}
// FIXME(const_generics): create real const to allow fn items as const paths
Res::Def(DefKind::Fn | DefKind::AssocFn, did) => {
Res::Def(DefKind::Fn, did) => {
Comment on lines +2794 to +2800

@Shourya742 Shourya742 Jun 16, 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.

Previous both free function and associated function, where lowering to zero_sized fn def which would later emit diagnostics, but to lower the assoc it required the parent trait. This now emits an error, instead of lowering.

View changes since the review

self.dcx().span_delayed_bug(span, "function items cannot be used as const args");
let args = self.lower_generic_args_of_path_segment(
span,
Expand Down
5 changes: 0 additions & 5 deletions tests/crashes/138088.rs

This file was deleted.

10 changes: 10 additions & 0 deletions tests/ui/const-generics/mgca/trait-assoc-fn-as-const-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(min_generic_const_args)]

// Regression test for #138088. assoc functions cannot be lowered as const
// args, and this should emit a regular diagnostic instead of ICEing.
trait Bar {
fn x(&self) -> [i32; Bar::x];
//~^ ERROR function items cannot be used as const arguments
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: function items cannot be used as const arguments
--> $DIR/trait-assoc-fn-as-const-arg.rs:6:26
|
LL | fn x(&self) -> [i32; Bar::x];
| ^^^^^^

error: aborting due to 1 previous error

Loading