Skip to content

Commit 645cbd3

Browse files
committed
Add UI tests for #[splat] unhappy path and generics cases
1 parent dd3754d commit 645cbd3

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// tests/ui/splat/splat-generics-inside-tuple.rs
2+
3+
//@ run-pass
4+
//! Test using `#[splat]` on tuples with generics inside the splatted tuple.
5+
#![allow(incomplete_features)]
6+
#![feature(splat)]
7+
8+
fn generic_second<T>(#[splat] _s: (u32, T)) {}
9+
10+
fn generic_first<T>(#[splat] _s: (T, u32)) {}
11+
12+
fn generic_both<T, U>(#[splat] _s: (T, U)) {}
13+
14+
fn generic_triple<T, U, V>(#[splat] _s: (T, U, V)) {}
15+
16+
fn main() {
17+
generic_second(1u32, 2i8);
18+
generic_second(1u32, 2.0f64);
19+
generic_second(1u32, "hello");
20+
21+
generic_first(1i8, 2u32);
22+
generic_first(2.0f64, 2u32);
23+
generic_first("hello", 2u32);
24+
25+
generic_both(1u32, 2i8);
26+
generic_both("hello", 2.0f64);
27+
generic_both(true, "world");
28+
29+
generic_triple(1u32, 2.0f64, "hello");
30+
generic_triple(true, 42i32, 3.14f32);
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// tests/ui/splat/splat-invalid-trait-impl.rs
2+
3+
//! Test that `#[splat]` trait impls with mismatched tuple element types are rejected.
4+
#![allow(incomplete_features)]
5+
#![feature(splat)]
6+
7+
trait FooTrait {
8+
fn method(#[splat] _: (u32, i8));
9+
}
10+
11+
struct Foo;
12+
struct Foo1;
13+
struct Foo2;
14+
15+
impl FooTrait for Foo {
16+
fn method(#[splat] _: (u32, f32)) {}
17+
//~^ ERROR
18+
}
19+
20+
impl FooTrait for Foo1 {
21+
fn method(#[splat] _: (f32, i8)) {}
22+
//~^ ERROR
23+
}
24+
25+
impl FooTrait for Foo2 {
26+
fn method(#[splat] _: (f32, f64)) {}
27+
//~^ ERROR
28+
}
29+
fn main() {}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error[E0053]: method `method` has an incompatible type for trait
2+
--> $DIR/splat-invalid-trait-impl.rs:16:27
3+
|
4+
LL | fn method(#[splat] _: (u32, f32)) {}
5+
| ^^^^^^^^^^ expected `i8`, found `f32`
6+
|
7+
note: type in trait
8+
--> $DIR/splat-invalid-trait-impl.rs:8:27
9+
|
10+
LL | fn method(#[splat] _: (u32, i8));
11+
| ^^^^^^^^^
12+
= note: expected signature `fn(#[splat] (_, i8))`
13+
found signature `fn(#[splat] (_, f32))`
14+
help: change the parameter type to match the trait
15+
|
16+
LL - fn method(#[splat] _: (u32, f32)) {}
17+
LL + fn method(#[splat] _: (u32, i8)) {}
18+
|
19+
20+
error[E0053]: method `method` has an incompatible type for trait
21+
--> $DIR/splat-invalid-trait-impl.rs:21:27
22+
|
23+
LL | fn method(#[splat] _: (f32, i8)) {}
24+
| ^^^^^^^^^ expected `u32`, found `f32`
25+
|
26+
note: type in trait
27+
--> $DIR/splat-invalid-trait-impl.rs:8:27
28+
|
29+
LL | fn method(#[splat] _: (u32, i8));
30+
| ^^^^^^^^^
31+
= note: expected signature `fn(#[splat] (u32, _))`
32+
found signature `fn(#[splat] (f32, _))`
33+
help: change the parameter type to match the trait
34+
|
35+
LL - fn method(#[splat] _: (f32, i8)) {}
36+
LL + fn method(#[splat] _: (u32, i8)) {}
37+
|
38+
39+
error[E0053]: method `method` has an incompatible type for trait
40+
--> $DIR/splat-invalid-trait-impl.rs:26:27
41+
|
42+
LL | fn method(#[splat] _: (f32, f64)) {}
43+
| ^^^^^^^^^^ expected `u32`, found `f32`
44+
|
45+
note: type in trait
46+
--> $DIR/splat-invalid-trait-impl.rs:8:27
47+
|
48+
LL | fn method(#[splat] _: (u32, i8));
49+
| ^^^^^^^^^
50+
= note: expected signature `fn(#[splat] (u32, i8))`
51+
found signature `fn(#[splat] (f32, f64))`
52+
help: change the parameter type to match the trait
53+
|
54+
LL - fn method(#[splat] _: (f32, f64)) {}
55+
LL + fn method(#[splat] _: (u32, i8)) {}
56+
|
57+
58+
error: aborting due to 3 previous errors
59+
60+
For more information about this error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)