mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 17:18:32 +03:00
b8999f2b20
mGCA: Enforce WF element types for array valtrees Fixes rust-lang/rust#152125 Extends WellFormedness checking for const generics to validate that array element types in ValTrees match the declared element type. ### Problem Before commit, this would have incorrectly compiled ``` rust #![feature(adt_const_params, min_generic_const_args)] use std::marker::ConstParamTy; #[derive(Eq, PartialEq, ConstParamTy)] struct Foo; struct Bar; fn foo<const N: [Foo; 1]>() {} fn main() { foo::<{ [Bar] }>(); } ``` ### Solution Added a `ty::Array` arm to checking WellFormedness (similar to the existing `ty::Tuple` arm from rust-lang/rust#150713) which creates `ConstArgHasType` obligations for each array element, ensuring they match the array's declared element type. I attempted to combine the `Tuple` and `Array` arms into a single arm, but this proved difficult due to pattern matching limitations, and the separate arm is more readable anyway. ### Tests Added UI test which verifies that the type mismatch is now properly caught, and also returns an appropriate test message r? @BoxyUwU