mGCA: Enforce WF element types for array valtrees#152492
mGCA: Enforce WF element types for array valtrees#152492biscuitrescue wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
changes to the core type system cc @lcnr |
This comment has been minimized.
This comment has been minimized.
96a0183 to
1d39a91
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| @@ -0,0 +1,15 @@ | |||
| #![feature(adt_const_params, min_generic_const_args)] | |||
| //~^ WARN feature `min_generic_const_args` is incomplete | |||
There was a problem hiding this comment.
you can also do #![expect(incomplete_features)] instead of the warning here. I personally would go for that route because I don't think the warning should be mentioned in the .stderr file.
|
I would also recommend adding test files that check what happens when an array expression contains tuple argument. Kinda like this: #![feature(adt_const_params, min_generic_const_args, unsized_const_params)]
#![allow(incomplete_features)]
use std::marker::ConstParamTy;
#[derive(Eq, PartialEq, ConstParamTy)]
struct A;
fn takes_tuple<const N: [(u32, u32); 1]>() {}
fn takes_nested_tuple<const N: [(u32, (u32, u32)); 1]>() {}
fn main() {
takes_tuple::<{ [A] }>();
//~^ ERROR the constant `A` is not of type `(u32, u32)`
takes_nested_tuple::<{ [A] }>();
//~^ ERROR the constant `A` is not of type `(u32, (u32, u32))`
}One other thing to test would probably be something you add into ^This is if you don't put the const block around the whole tuple. But I think now that you added WF element type check for array valtrees, this should emit an error if there's an invalid array inside tuple? |
|
Thankyou for the feedback. I'll add the test-cases and update the PR shortly. As for the question, I'll have to test this to see its behaviour. I believe it should, because the WF check walks through the valtree structure recursively so that when it checks the tuple, it should also check the array elements inside it. |
|
The WellFormed elems check does catch type errors recursively so invalid array elements inside tuples are also caught. |
Fixes #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
Solution
Added a
ty::Arrayarm to checking WellFormedness (similar to the existingty::Tuplearm from #150713) which createsConstArgHasTypeobligations for each array element, ensuring they match the array's declared element type.I attempted to combine the
TupleandArrayarms 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