Skip to content
Merged
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
9 changes: 4 additions & 5 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2415,11 +2415,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
};

let ty::Array(elem_ty, _) = ty.kind() else {
return Const::new_error_with_message(
tcx,
array_expr.span,
"const array must have an array type",
);
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! regression test for <https://github.com/rust-lang/rust/issues/151024>
#![feature(min_generic_const_args)]
#![feature(adt_const_params)]
#![expect(incomplete_features)]

trait Trait1<const N: usize> {}
trait Trait2<const N: [u8; 3]> {}

fn foo<T>()
where
T: Trait1<{ [] }>, //~ ERROR: expected `usize`, found const array
{
}

fn bar<T>()
where
T: Trait2<3>, //~ ERROR: mismatched types
{
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: expected `usize`, found const array
--> $DIR/array-expr-type-mismatch-in-where-bound.rs:11:17
|
LL | T: Trait1<{ [] }>,
| ^^

error[E0308]: mismatched types
--> $DIR/array-expr-type-mismatch-in-where-bound.rs:17:15
|
LL | T: Trait2<3>,
| ^ expected `[u8; 3]`, found integer

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Loading