Skip to content

Commit c5f0de2

Browse files
committed
Add UI tests for #[splat] with const generics, complex types, and where clauses
1 parent 0136c63 commit c5f0de2

3 files changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ run-pass
2+
//! Test using `#[splat]` on tuple arguments of const functions with generics.
3+
//! This fills the FIXME in splat-generics-everywhere.rs:
4+
//! "add const fn generics tests"
5+
6+
#![allow(incomplete_features)]
7+
#![feature(splat)]
8+
9+
// Generic type in first position
10+
const fn const_generic_first<T: Copy>(#[splat] _: (T, u32)) {}
11+
12+
// Generic type in second position
13+
const fn const_generic_second<T: Copy>(#[splat] _: (u32, T)) {}
14+
15+
// Multiple generic types
16+
const fn const_generic_both<T: Copy, U: Copy>(#[splat] _: (T, U)) {}
17+
18+
// Generic with extra non-splatted arg
19+
const fn const_generic_extra<T: Copy>(#[splat] _: (T, u32), _extra: i32) {}
20+
21+
fn main() {
22+
const_generic_first(1i8, 2u32);
23+
const_generic_first(true, 2u32);
24+
const_generic_first(1u64, 2u32);
25+
26+
const_generic_second(1u32, 2i8);
27+
const_generic_second(1u32, true);
28+
const_generic_second(1u32, 2u64);
29+
30+
const_generic_both(1u32, 2i8);
31+
const_generic_both(true, 2u64);
32+
const_generic_both(1i8, false);
33+
34+
const_generic_extra(1i8, 2u32, 42i32);
35+
const_generic_extra(true, 2u32, 42i32);
36+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ run-pass
2+
//! Test using `#[splat]` on tuples with complex generic types inside the splatted tuple.
3+
//! This fills the FIXME in splat-generics-everywhere.rs:
4+
//! "also add generics inside the splatted tuple"
5+
6+
#![allow(incomplete_features)]
7+
#![feature(splat)]
8+
9+
// Vec<T> and Option<U> inside splatted tuple
10+
fn nested_generic<T, U>(#[splat] _: (Vec<T>, Option<U>)) {}
11+
12+
// Box<T> inside splatted tuple
13+
fn box_generic<T>(#[splat] _: (Box<T>, u32)) {}
14+
15+
// Multiple complex generics
16+
fn multi_generic<T, U, V>(#[splat] _: (Vec<T>, Option<U>, Box<V>)) {}
17+
18+
fn main() {
19+
nested_generic(vec![1u32, 2u32], Some(2i8));
20+
nested_generic(vec![1, 2, 3], None::<i8>);
21+
nested_generic::<u32, &str>(vec![], Some("hello"));
22+
23+
box_generic(Box::new(1u32), 42u32);
24+
box_generic(Box::new("hello"), 1u32);
25+
26+
multi_generic(vec![1u32], Some(2i8), Box::new(3.0f64));
27+
multi_generic::<u32, i8, &str>(vec![], None::<i8>, Box::new("hello"));
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ run-pass
2+
//! Test using `#[splat]` on tuple arguments with where clause bounds.
3+
4+
#![allow(incomplete_features)]
5+
#![feature(splat)]
6+
#![feature(tuple_trait)]
7+
8+
fn where_splat<T>(#[splat] _t: T) where T: std::marker::Tuple {}
9+
10+
fn where_splat_with_extra<T>(#[splat] _t: T, _extra: u32) where T: std::marker::Tuple {}
11+
12+
fn main() {
13+
// empty tuple
14+
where_splat();
15+
16+
// single element
17+
where_splat(1u32);
18+
where_splat(1);
19+
20+
// two elements
21+
where_splat(1u32, 2i8);
22+
where_splat(1, 2);
23+
24+
// three elements
25+
where_splat(1u32, 2i8, 3.0f64);
26+
where_splat(1, 2, 3.0);
27+
28+
// with extra non-splatted arg
29+
where_splat_with_extra(1u32, 2i8, 42u32);
30+
where_splat_with_extra(1, 2, 42);
31+
}

0 commit comments

Comments
 (0)