Skip to content

Commit 109cc1d

Browse files
Add tuple trait tests
1 parent d0e4c67 commit 109cc1d

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

src/test/ui/explore-issue-38412.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ LL | t.2;
4343
= note: see issue #38412 <https://github.com/rust-lang/rust/issues/38412> for more information
4444
= help: add `#![feature(unstable_undeclared)]` to the crate attributes to enable
4545

46-
error[E0616]: field `3` of struct `Tuple` is private
46+
error[E0616]: field `3` of struct `pub_and_stability::Tuple` is private
4747
--> $DIR/explore-issue-38412.rs:36:7
4848
|
4949
LL | t.3;
5050
| ^ private field
5151

52-
error[E0616]: field `4` of struct `Tuple` is private
52+
error[E0616]: field `4` of struct `pub_and_stability::Tuple` is private
5353
--> $DIR/explore-issue-38412.rs:37:7
5454
|
5555
LL | t.4;
5656
| ^ private field
5757

58-
error[E0616]: field `5` of struct `Tuple` is private
58+
error[E0616]: field `5` of struct `pub_and_stability::Tuple` is private
5959
--> $DIR/explore-issue-38412.rs:38:7
6060
|
6161
LL | t.5;

src/test/ui/tuple/builtin-fail.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(tuple_trait)]
2+
3+
fn assert_is_tuple<T: std::marker::Tuple + ?Sized>() {}
4+
5+
struct TupleStruct(i32, i32);
6+
7+
fn from_param_env<T>() {
8+
assert_is_tuple::<T>();
9+
//~^ ERROR `T` is not a tuple
10+
}
11+
12+
fn main() {
13+
assert_is_tuple::<i32>();
14+
//~^ ERROR `i32` is not a tuple
15+
assert_is_tuple::<(i32)>();
16+
//~^ ERROR `i32` is not a tuple
17+
assert_is_tuple::<TupleStruct>();
18+
//~^ ERROR `TupleStruct` is not a tuple
19+
}

src/test/ui/tuple/builtin-fail.stderr

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error[E0277]: `T` is not a tuple
2+
--> $DIR/builtin-fail.rs:8:23
3+
|
4+
LL | assert_is_tuple::<T>();
5+
| ^ the trait `Tuple` is not implemented for `T`
6+
|
7+
note: required by a bound in `assert_is_tuple`
8+
--> $DIR/builtin-fail.rs:3:23
9+
|
10+
LL | fn assert_is_tuple<T: std::marker::Tuple + ?Sized>() {}
11+
| ^^^^^^^^^^^^^^^^^^ required by this bound in `assert_is_tuple`
12+
help: consider restricting type parameter `T`
13+
|
14+
LL | fn from_param_env<T: std::marker::Tuple>() {
15+
| ++++++++++++++++++++
16+
17+
error[E0277]: `i32` is not a tuple
18+
--> $DIR/builtin-fail.rs:13:23
19+
|
20+
LL | assert_is_tuple::<i32>();
21+
| ^^^ the trait `Tuple` is not implemented for `i32`
22+
|
23+
note: required by a bound in `assert_is_tuple`
24+
--> $DIR/builtin-fail.rs:3:23
25+
|
26+
LL | fn assert_is_tuple<T: std::marker::Tuple + ?Sized>() {}
27+
| ^^^^^^^^^^^^^^^^^^ required by this bound in `assert_is_tuple`
28+
29+
error[E0277]: `i32` is not a tuple
30+
--> $DIR/builtin-fail.rs:15:24
31+
|
32+
LL | assert_is_tuple::<(i32)>();
33+
| ^^^ the trait `Tuple` is not implemented for `i32`
34+
|
35+
note: required by a bound in `assert_is_tuple`
36+
--> $DIR/builtin-fail.rs:3:23
37+
|
38+
LL | fn assert_is_tuple<T: std::marker::Tuple + ?Sized>() {}
39+
| ^^^^^^^^^^^^^^^^^^ required by this bound in `assert_is_tuple`
40+
41+
error[E0277]: `TupleStruct` is not a tuple
42+
--> $DIR/builtin-fail.rs:17:23
43+
|
44+
LL | assert_is_tuple::<TupleStruct>();
45+
| ^^^^^^^^^^^ the trait `Tuple` is not implemented for `TupleStruct`
46+
|
47+
note: required by a bound in `assert_is_tuple`
48+
--> $DIR/builtin-fail.rs:3:23
49+
|
50+
LL | fn assert_is_tuple<T: std::marker::Tuple + ?Sized>() {}
51+
| ^^^^^^^^^^^^^^^^^^ required by this bound in `assert_is_tuple`
52+
53+
error: aborting due to 4 previous errors
54+
55+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/tuple/builtin.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
3+
#![feature(tuple_trait)]
4+
5+
fn assert_is_tuple<T: std::marker::Tuple + ?Sized>() {}
6+
7+
struct Unsized([u8]);
8+
9+
fn from_param_env<T: std::marker::Tuple + ?Sized>() {
10+
assert_is_tuple::<T>();
11+
}
12+
13+
fn main() {
14+
assert_is_tuple::<()>();
15+
assert_is_tuple::<(i32,)>();
16+
assert_is_tuple::<(Unsized,)>();
17+
from_param_env::<()>();
18+
from_param_env::<(i32,)>();
19+
from_param_env::<(Unsized,)>();
20+
}

0 commit comments

Comments
 (0)