Skip to content

Commit 0136c63

Browse files
committed
Add UI tests for #[splat] with const, async, and unsafe functions
1 parent fdbfe34 commit 0136c63

7 files changed

Lines changed: 134 additions & 0 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ edition:2024
2+
//! Test that using `#[splat]` incorrectly on async functions gives errors.
3+
4+
#![allow(incomplete_features)]
5+
#![feature(splat)]
6+
7+
async fn async_wrong_type(#[splat] _x: u32) {}
8+
//~^ ERROR cannot use splat attribute; the splatted argument type must be a tuple or unit, not a u32
9+
10+
async fn async_multi_splat(#[splat] (_a, _b): (u32, i8), #[splat] (_c, _d): (u32, i8)) {}
11+
//~^ ERROR multiple `#[splat]`s are not allowed in the same function
12+
13+
fn main() {
14+
async_wrong_type(1u32);
15+
async_multi_splat(1u32, 2i8, 3u32, 4i8);
16+
//~^ ERROR this splatted function takes 3 arguments, but 4 were provided
17+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: multiple `#[splat]`s are not allowed in the same function
2+
--> $DIR/splat-async-fn-tuple-fail.rs:10:28
3+
|
4+
LL | async fn async_multi_splat(#[splat] (_a, _b): (u32, i8), #[splat] (_c, _d): (u32, i8)) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: remove `#[splat]` from all but one argument
8+
9+
error[E0277]: cannot use splat attribute; the splatted argument type must be a tuple or unit, not a u32 (u32)
10+
--> $DIR/splat-async-fn-tuple-fail.rs:7:40
11+
|
12+
LL | async fn async_wrong_type(#[splat] _x: u32) {}
13+
| ^^^
14+
...
15+
LL | async_wrong_type(1u32);
16+
| ^^^^^^^^^^^^^^^^^^^^^^
17+
18+
error[E0057]: this splatted function takes 3 arguments, but 4 were provided
19+
--> $DIR/splat-async-fn-tuple-fail.rs:15:5
20+
|
21+
LL | async_multi_splat(1u32, 2i8, 3u32, 4i8);
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
24+
error: aborting due to 3 previous errors
25+
26+
Some errors have detailed explanations: E0057, E0277.
27+
For more information about an error, try `rustc --explain E0057`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ run-pass
2+
//@ edition:2024
3+
//! Test using `#[splat]` on tuple arguments of async functions.
4+
5+
#![allow(incomplete_features)]
6+
#![feature(splat)]
7+
8+
async fn async_tuple_args(#[splat] (_a, _b): (u32, i8)) {}
9+
10+
async fn async_splat_non_terminal_arg(#[splat] (_a, _b): (u32, i8), _c: f64) {}
11+
12+
fn main() {
13+
let _ = async_tuple_args(1u32, 2i8);
14+
let _ = async_tuple_args(1, 2);
15+
16+
let _ = async_splat_non_terminal_arg(1u32, 2i8, 3.5f64);
17+
let _ = async_splat_non_terminal_arg(1, 2, 3.5);
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ run-pass
2+
//! Test using `#[splat]` on tuple arguments of const functions.
3+
4+
#![allow(incomplete_features)]
5+
#![feature(splat)]
6+
7+
const fn sum(#[splat] (a, b): (u32, u32)) -> u32 {
8+
a + b
9+
}
10+
11+
const RESULT: u32 = sum(1, 2);
12+
13+
fn main() {
14+
assert_eq!(RESULT, 3);
15+
assert_eq!(sum(12, 18) , 30);
16+
assert_eq!(sum(1, 2), 3);
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Test that using `#[splat]` incorrectly on unsafe functions gives errors.
2+
3+
#![allow(incomplete_features)]
4+
#![feature(splat)]
5+
6+
unsafe fn unsafe_wrong_type(#[splat] _x: u32) {}
7+
//~^ ERROR cannot use splat attribute; the splatted argument type must be a tuple or unit, not a u32
8+
9+
unsafe fn unsafe_multi_splat(#[splat] (_a, _b): (u32, i8), #[splat] (_c, _d): (u32, i8)) {}
10+
//~^ ERROR multiple `#[splat]`s are not allowed in the same function
11+
12+
fn main() {
13+
unsafe {
14+
unsafe_wrong_type(1u32);
15+
}
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: multiple `#[splat]`s are not allowed in the same function
2+
--> $DIR/splat-unsafe-fn-tuple-fail.rs:9:30
3+
|
4+
LL | unsafe fn unsafe_multi_splat(#[splat] (_a, _b): (u32, i8), #[splat] (_c, _d): (u32, i8)) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: remove `#[splat]` from all but one argument
8+
9+
error[E0277]: cannot use splat attribute; the splatted argument type must be a tuple or unit, not a u32 (u32)
10+
--> $DIR/splat-unsafe-fn-tuple-fail.rs:6:42
11+
|
12+
LL | unsafe fn unsafe_wrong_type(#[splat] _x: u32) {}
13+
| ^^^
14+
...
15+
LL | unsafe_wrong_type(1u32);
16+
| ^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ run-pass
2+
//! Test using `#[splat]` on tuple arguments of unsafe functions.
3+
4+
#![allow(incomplete_features)]
5+
#![feature(splat)]
6+
7+
unsafe fn unsafe_tuple_args(#[splat] (_a, _b): (u32, i8)) {}
8+
9+
unsafe fn unsafe_splat_non_terminal_arg(#[splat] (_a, _b): (u32, i8), _c: f64) {}
10+
11+
fn main() {
12+
unsafe {
13+
unsafe_tuple_args(1u32, 2i8);
14+
unsafe_tuple_args(1, 2);
15+
16+
unsafe_splat_non_terminal_arg(1u32, 2i8, 3.5f64);
17+
unsafe_splat_non_terminal_arg(1, 2, 3.5);
18+
}
19+
}

0 commit comments

Comments
 (0)