Skip to content

Commit 26417a8

Browse files
committed
Add ConstParamTy tests
1 parent bdb5502 commit 26417a8

5 files changed

+198
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![allow(incomplete_features)]
2+
#![feature(adt_const_params)]
3+
4+
fn check(_: impl std::marker::ConstParamTy) {}
5+
6+
fn main() {
7+
check(main); //~ error: `fn() {main}` can't be used as a const parameter type
8+
check(|| {}); //~ error: `[closure@fake-test-src-base/const-generics/adt_const_params/const_param_ty_bad.rs:8:11: 8:13]` can't be used as a const parameter type
9+
check(main as fn()); //~ error: `fn()` can't be used as a const parameter type
10+
check(&mut ()); //~ error: `&mut ()` can't be used as a const parameter type
11+
check(&mut () as *mut ()); //~ error: `*mut ()` can't be used as a const parameter type
12+
check(&() as *const ()); //~ error: `*const ()` can't be used as a const parameter type
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
error[E0277]: `fn() {main}` can't be used as a const parameter type
2+
--> $DIR/const_param_ty_bad.rs:7:11
3+
|
4+
LL | check(main);
5+
| ----- ^^^^ the trait `ConstParamTy` is not implemented for fn item `fn() {main}`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: required by a bound in `check`
10+
--> $DIR/const_param_ty_bad.rs:4:18
11+
|
12+
LL | fn check(_: impl std::marker::ConstParamTy) {}
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
14+
15+
error[E0277]: `[closure@$DIR/const_param_ty_bad.rs:8:11: 8:13]` can't be used as a const parameter type
16+
--> $DIR/const_param_ty_bad.rs:8:11
17+
|
18+
LL | check(|| {});
19+
| ----- ^^^^^ the trait `ConstParamTy` is not implemented for closure `[closure@$DIR/const_param_ty_bad.rs:8:11: 8:13]`
20+
| |
21+
| required by a bound introduced by this call
22+
|
23+
note: required by a bound in `check`
24+
--> $DIR/const_param_ty_bad.rs:4:18
25+
|
26+
LL | fn check(_: impl std::marker::ConstParamTy) {}
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
28+
29+
error[E0277]: `fn()` can't be used as a const parameter type
30+
--> $DIR/const_param_ty_bad.rs:9:11
31+
|
32+
LL | check(main as fn());
33+
| ----- ^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `fn()`
34+
| |
35+
| required by a bound introduced by this call
36+
|
37+
note: required by a bound in `check`
38+
--> $DIR/const_param_ty_bad.rs:4:18
39+
|
40+
LL | fn check(_: impl std::marker::ConstParamTy) {}
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
42+
43+
error[E0277]: `&mut ()` can't be used as a const parameter type
44+
--> $DIR/const_param_ty_bad.rs:10:11
45+
|
46+
LL | check(&mut ());
47+
| ----- ^^^^^^^ the trait `ConstParamTy` is not implemented for `&mut ()`
48+
| |
49+
| required by a bound introduced by this call
50+
|
51+
note: required by a bound in `check`
52+
--> $DIR/const_param_ty_bad.rs:4:18
53+
|
54+
LL | fn check(_: impl std::marker::ConstParamTy) {}
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
56+
57+
error[E0277]: `*mut ()` can't be used as a const parameter type
58+
--> $DIR/const_param_ty_bad.rs:11:11
59+
|
60+
LL | check(&mut () as *mut ());
61+
| ----- ^^^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*mut ()`
62+
| |
63+
| required by a bound introduced by this call
64+
|
65+
note: required by a bound in `check`
66+
--> $DIR/const_param_ty_bad.rs:4:18
67+
|
68+
LL | fn check(_: impl std::marker::ConstParamTy) {}
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
70+
71+
error[E0277]: `*const ()` can't be used as a const parameter type
72+
--> $DIR/const_param_ty_bad.rs:12:11
73+
|
74+
LL | check(&() as *const ());
75+
| ----- ^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*const ()`
76+
| |
77+
| required by a bound introduced by this call
78+
|
79+
note: required by a bound in `check`
80+
--> $DIR/const_param_ty_bad.rs:4:18
81+
|
82+
LL | fn check(_: impl std::marker::ConstParamTy) {}
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
84+
85+
error: aborting due to 6 previous errors
86+
87+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![allow(incomplete_features)]
2+
#![feature(adt_const_params)]
3+
4+
#[derive(PartialEq, Eq)]
5+
struct NotParam;
6+
7+
fn check<T: std::marker::ConstParamTy + ?Sized>() {}
8+
9+
fn main() {
10+
check::<&NotParam>(); //~ error: `NotParam` can't be used as a const parameter type
11+
check::<[NotParam]>(); //~ error: `NotParam` can't be used as a const parameter type
12+
check::<[NotParam; 17]>(); //~ error: `NotParam` can't be used as a const parameter type
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error[E0277]: `NotParam` can't be used as a const parameter type
2+
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:10:13
3+
|
4+
LL | check::<&NotParam>();
5+
| ^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`
6+
|
7+
= note: required for `&NotParam` to implement `ConstParamTy`
8+
note: required by a bound in `check`
9+
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
10+
|
11+
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
13+
14+
error[E0277]: `NotParam` can't be used as a const parameter type
15+
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:11:13
16+
|
17+
LL | check::<[NotParam]>();
18+
| ^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`
19+
|
20+
= note: required for `[NotParam]` to implement `ConstParamTy`
21+
note: required by a bound in `check`
22+
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
23+
|
24+
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
26+
27+
error[E0277]: `NotParam` can't be used as a const parameter type
28+
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:12:13
29+
|
30+
LL | check::<[NotParam; 17]>();
31+
| ^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`
32+
|
33+
= note: required for `[NotParam; 17]` to implement `ConstParamTy`
34+
note: required by a bound in `check`
35+
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
36+
|
37+
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
39+
40+
error: aborting due to 3 previous errors
41+
42+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// check-pass
2+
#![allow(incomplete_features)]
3+
#![feature(adt_const_params)]
4+
use std::marker::ConstParamTy;
5+
6+
#[derive(PartialEq, Eq)]
7+
struct S<T> {
8+
field: u8,
9+
gen: T,
10+
}
11+
12+
impl<T: ConstParamTy> ConstParamTy for S<T> {}
13+
14+
fn check<T: ConstParamTy + ?Sized>() {}
15+
16+
fn main() {
17+
check::<u8>();
18+
check::<u16>();
19+
check::<u32>();
20+
check::<u64>();
21+
check::<u128>();
22+
23+
check::<i8>();
24+
check::<i16>();
25+
check::<i32>();
26+
check::<i64>();
27+
check::<i128>();
28+
29+
check::<char>();
30+
check::<bool>();
31+
check::<str>();
32+
33+
check::<&u8>();
34+
check::<&str>();
35+
check::<[usize]>();
36+
check::<[u16; 0]>();
37+
check::<[u8; 42]>();
38+
39+
check::<S<u8>>();
40+
check::<S<[&[bool]; 8]>>();
41+
42+
// FIXME: test tuples
43+
}

0 commit comments

Comments
 (0)