about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-02-12 06:07:39 +0100
committerGitHub <noreply@github.com>2025-02-12 06:07:39 +0100
commitfebb367a04566e045e3fe7da51745065442034bd (patch)
tree7323404acb557d33203eb246b65080a4bc25ebe7 /compiler/rustc_hir_analysis/src
parent72fd5719aa22bd33514cc15e632c25ca1529f95d (diff)
parentf0cb746480830d585768c03f8447c0e5f9817b52 (diff)
downloadrust-febb367a04566e045e3fe7da51745065442034bd.tar.gz
rust-febb367a04566e045e3fe7da51745065442034bd.zip
Rollup merge of #136884 - compiler-errors:fn-zst, r=BoxyUwU
Lower fn items as ZST valtrees and delay a bug

Lower it as a ZST instead of a const error, which we can handle mostly fine. Delay a bug so we don't accidentally support it tho.

r? BoxyUwU

Fixes #136855
Fixes #136853
Fixes #136854
Fixes #136337

Only added one test bc that's really the crux of the issue (fn item in array length position).
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
index ffddf6f73aa..e58cb2ff592 100644
--- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
+++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
@@ -2154,11 +2154,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
                 span_bug!(span, "use of bare `static` ConstArgKind::Path's not yet supported")
             }
             // FIXME(const_generics): create real const to allow fn items as const paths
-            Res::Def(DefKind::Fn | DefKind::AssocFn, _) => ty::Const::new_error_with_message(
-                tcx,
-                span,
-                "fn items cannot be used as const args",
-            ),
+            Res::Def(DefKind::Fn | DefKind::AssocFn, did) => {
+                self.dcx().span_delayed_bug(span, "function items cannot be used as const args");
+                let args = self.lower_generic_args_of_path_segment(
+                    span,
+                    did,
+                    path.segments.last().unwrap(),
+                );
+                ty::Const::new_value(tcx, ty::ValTree::zst(), Ty::new_fn_def(tcx, did, args))
+            }
 
             // Exhaustive match to be clear about what exactly we're considering to be
             // an invalid Res for a const path.