refactor: move tuples type info ui test to coretest

This commit is contained in:
BD103
2026-01-13 12:19:37 -05:00
parent e027ecdbb5
commit 71f8ea99fe
2 changed files with 33 additions and 36 deletions
+33
View File
@@ -21,3 +21,36 @@ fn test_arrays() {
_ => unreachable!(),
}
}
#[test]
fn test_tuples() {
fn assert_tuple_arity<T: 'static, const N: usize>() {
match const { Type::of::<T>() }.kind {
TypeKind::Tuple(tup) => {
assert_eq!(tup.fields.len(), N);
}
_ => unreachable!(),
}
}
assert_tuple_arity::<(), 0>();
assert_tuple_arity::<(u8,), 1>();
assert_tuple_arity::<(u8, u8), 2>();
const {
match Type::of::<(u8, u8)>().kind {
TypeKind::Tuple(tup) => {
let [a, b] = tup.fields else { unreachable!() };
assert!(a.offset == 0);
assert!(b.offset == 1);
match (a.ty.info().kind, b.ty.info().kind) {
(TypeKind::Leaf, TypeKind::Leaf) => {}
_ => unreachable!(),
}
}
_ => unreachable!(),
}
}
}
-36
View File
@@ -1,36 +0,0 @@
#![feature(type_info)]
//@ run-pass
use std::mem::type_info::{Type, TypeKind};
fn assert_tuple_arity<T: 'static, const N: usize>() {
const {
match &Type::of::<T>().kind {
TypeKind::Tuple(tup) => {
assert!(tup.fields.len() == N);
}
_ => unreachable!(),
}
}
}
fn main() {
assert_tuple_arity::<(), 0>();
assert_tuple_arity::<(u8,), 1>();
assert_tuple_arity::<(u8, u8), 2>();
const {
match &Type::of::<(u8, u8)>().kind {
TypeKind::Tuple(tup) => {
let [a, b] = tup.fields else { unreachable!() };
assert!(a.offset == 0);
assert!(b.offset == 1);
match (&a.ty.info().kind, &b.ty.info().kind) {
(TypeKind::Leaf, TypeKind::Leaf) => {}
_ => unreachable!(),
}
}
_ => unreachable!(),
}
}
}