MGCA: fix type error handling for array and tuple lowering logic

This commit is contained in:
human9000
2026-03-03 17:08:26 +05:00
parent 1b7d722f42
commit ee1d0cfbe6
3 changed files with 49 additions and 8 deletions
@@ -2416,11 +2416,15 @@ fn lower_const_arg_array(
) -> Const<'tcx> {
let tcx = self.tcx();
let ty::Array(elem_ty, _) = ty.kind() else {
let e = tcx
.dcx()
.span_err(array_expr.span, format!("expected `{}`, found const array", ty));
return Const::new_error(tcx, e);
let elem_ty = match ty.kind() {
ty::Array(elem_ty, _) => elem_ty,
ty::Error(e) => return Const::new_error(tcx, *e),
_ => {
let e = tcx
.dcx()
.span_err(array_expr.span, format!("expected `{}`, found const array", ty));
return Const::new_error(tcx, e);
}
};
let elems = array_expr
@@ -2539,9 +2543,13 @@ fn lower_const_arg_tup(
) -> Const<'tcx> {
let tcx = self.tcx();
let ty::Tuple(tys) = ty.kind() else {
let e = tcx.dcx().span_err(span, format!("expected `{}`, found const tuple", ty));
return Const::new_error(tcx, e);
let tys = match ty.kind() {
ty::Tuple(tys) => tys,
ty::Error(e) => return Const::new_error(tcx, *e),
_ => {
let e = tcx.dcx().span_err(span, format!("expected `{}`, found const tuple", ty));
return Const::new_error(tcx, e);
}
};
let exprs = exprs
@@ -0,0 +1,13 @@
// This test ensures proper diagnostics emission during HIR ty lowering
// See https://github.com/rust-lang/rust/issues/153254
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
type const T0: _ = ();
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for constants [E0121]
type const T1 = [0];
//~^ ERROR: missing type for `const` item
fn main() {}
@@ -0,0 +1,20 @@
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
--> $DIR/syntactic-type-mismatch.rs:7:16
|
LL | type const T0: _ = ();
| ^ not allowed in type signatures
error: missing type for `const` item
--> $DIR/syntactic-type-mismatch.rs:10:14
|
LL | type const T1 = [0];
| ^
|
help: provide a type for the item
|
LL | type const T1: <type> = [0];
| ++++++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0121`.