diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index d383cb9d91dd4..3013d720ff4eb 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -1094,6 +1094,23 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { }, )); } + ty::Array(elem_ty, _len) => { + let field_vals = val.to_branch(); + let cause = self.cause(ObligationCauseCode::WellFormed(None)); + + self.out.extend(field_vals.iter().map(|&field_val| { + let predicate = ty::PredicateKind::Clause( + ty::ClauseKind::ConstArgHasType(field_val, *elem_ty), + ); + traits::Obligation::with_depth( + tcx, + cause.clone(), + self.recursion_depth, + self.param_env, + predicate, + ) + })); + } _ => {} } } diff --git a/tests/ui/const-generics/mgca/array-expr-type-missmatch.rs b/tests/ui/const-generics/mgca/array-expr-type-missmatch.rs new file mode 100644 index 0000000000000..8be8ad664f31d --- /dev/null +++ b/tests/ui/const-generics/mgca/array-expr-type-missmatch.rs @@ -0,0 +1,15 @@ +#![expect(incomplete_features)] +#![feature(min_generic_const_args, adt_const_params)] + +use std::marker::ConstParamTy; + +#[derive(Eq, PartialEq, ConstParamTy)] +struct Foo; +struct Bar; + +fn takes_array() {} + +fn main() { + takes_array::<{ [Bar] }>(); + //~^ ERROR: the constant `Bar` is not of type `Foo` +} diff --git a/tests/ui/const-generics/mgca/array-expr-type-missmatch.stderr b/tests/ui/const-generics/mgca/array-expr-type-missmatch.stderr new file mode 100644 index 0000000000000..3d87792700c9c --- /dev/null +++ b/tests/ui/const-generics/mgca/array-expr-type-missmatch.stderr @@ -0,0 +1,8 @@ +error: the constant `Bar` is not of type `Foo` + --> $DIR/array-expr-type-missmatch.rs:13:21 + | +LL | takes_array::<{ [Bar] }>(); + | ^^^^^ expected `Foo`, found `Bar` + +error: aborting due to 1 previous error +