Skip to content

Commit 568ed59

Browse files
Rollup merge of #153345 - Human9000-bit:mgca-diagnostics-fix, r=fmease
MGCA: fix type error handling for const array and tuple lowering logic It's a simple fix; just needed to handle Ty::Error in `lower_const_arg_array` and `lower_const_arg_tup` Fixes #153254 r? @fmease
2 parents 1d51c4a + ee1d0cf commit 568ed59

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,11 +2416,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24162416
) -> Const<'tcx> {
24172417
let tcx = self.tcx();
24182418

2419-
let ty::Array(elem_ty, _) = ty.kind() else {
2420-
let e = tcx
2421-
.dcx()
2422-
.span_err(array_expr.span, format!("expected `{}`, found const array", ty));
2423-
return Const::new_error(tcx, e);
2419+
let elem_ty = match ty.kind() {
2420+
ty::Array(elem_ty, _) => elem_ty,
2421+
ty::Error(e) => return Const::new_error(tcx, *e),
2422+
_ => {
2423+
let e = tcx
2424+
.dcx()
2425+
.span_err(array_expr.span, format!("expected `{}`, found const array", ty));
2426+
return Const::new_error(tcx, e);
2427+
}
24242428
};
24252429

24262430
let elems = array_expr
@@ -2539,9 +2543,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25392543
) -> Const<'tcx> {
25402544
let tcx = self.tcx();
25412545

2542-
let ty::Tuple(tys) = ty.kind() else {
2543-
let e = tcx.dcx().span_err(span, format!("expected `{}`, found const tuple", ty));
2544-
return Const::new_error(tcx, e);
2546+
let tys = match ty.kind() {
2547+
ty::Tuple(tys) => tys,
2548+
ty::Error(e) => return Const::new_error(tcx, *e),
2549+
_ => {
2550+
let e = tcx.dcx().span_err(span, format!("expected `{}`, found const tuple", ty));
2551+
return Const::new_error(tcx, e);
2552+
}
25452553
};
25462554

25472555
let exprs = exprs
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This test ensures proper diagnostics emission during HIR ty lowering
2+
// See https://github.com/rust-lang/rust/issues/153254
3+
4+
#![feature(min_generic_const_args)]
5+
#![expect(incomplete_features)]
6+
7+
type const T0: _ = ();
8+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for constants [E0121]
9+
10+
type const T1 = [0];
11+
//~^ ERROR: missing type for `const` item
12+
13+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
2+
--> $DIR/syntactic-type-mismatch.rs:7:16
3+
|
4+
LL | type const T0: _ = ();
5+
| ^ not allowed in type signatures
6+
7+
error: missing type for `const` item
8+
--> $DIR/syntactic-type-mismatch.rs:10:14
9+
|
10+
LL | type const T1 = [0];
11+
| ^
12+
|
13+
help: provide a type for the item
14+
|
15+
LL | type const T1: <type> = [0];
16+
| ++++++++
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)