Skip to content

Commit dfd532f

Browse files
authored
Unrolled build for #158479
Rollup merge of #158479 - Shourya742:2026-06-27-emit-error-during-ast-lower-using-static-const, r=BoxyUwU Reject static item as direct const generic arg closes: #136139 This PR fixes the ICE and not add support for static in MGCA
2 parents 76c35a1 + b4c60f0 commit dfd532f

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2933,7 +2933,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
29332933
.unwrap_or_else(|guar| Const::new_error(tcx, guar))
29342934
}
29352935
Res::Def(DefKind::Static { .. }, _) => {
2936-
span_bug!(span, "use of bare `static` ConstArgKind::Path's not yet supported")
2936+
let guar = self
2937+
.dcx()
2938+
.span_err(path.span, "static items cannot be used as const arguments");
2939+
return Const::new_error(tcx, guar);
29372940
}
29382941
// FIXME(const_generics): create real const to allow fn items as const paths
29392942
Res::Def(DefKind::Fn | DefKind::AssocFn, did) => {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for #132986.
2+
// FIXME(min_generic_const_args): using statics as direct const arguments should error instead of
3+
// ICEing until const eval can evaluate statics to valtrees for const generics.
4+
5+
#![feature(min_generic_const_args, macroless_generic_const_args)]
6+
#![allow(incomplete_features)]
7+
8+
static A: u32 = 0;
9+
10+
struct Foo<const N: u32>;
11+
12+
const _: Foo<{ A }> = Foo;
13+
//~^ ERROR static items cannot be used as const arguments
14+
15+
const _: Foo<A> = Foo;
16+
//~^ ERROR static items cannot be used as const arguments
17+
18+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: static items cannot be used as const arguments
2+
--> $DIR/static-const-arg.rs:12:16
3+
|
4+
LL | const _: Foo<{ A }> = Foo;
5+
| ^
6+
7+
error: static items cannot be used as const arguments
8+
--> $DIR/static-const-arg.rs:15:14
9+
|
10+
LL | const _: Foo<A> = Foo;
11+
| ^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)