mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
refactor: move tuples type info ui test to coretest
This commit is contained in:
@@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user