-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdb5502
commit 26417a8
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(adt_const_params)] | ||
|
||
fn check(_: impl std::marker::ConstParamTy) {} | ||
|
||
fn main() { | ||
check(main); //~ error: `fn() {main}` can't be used as a const parameter type | ||
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 | ||
check(main as fn()); //~ error: `fn()` can't be used as a const parameter type | ||
check(&mut ()); //~ error: `&mut ()` can't be used as a const parameter type | ||
check(&mut () as *mut ()); //~ error: `*mut ()` can't be used as a const parameter type | ||
check(&() as *const ()); //~ error: `*const ()` can't be used as a const parameter type | ||
} |
87 changes: 87 additions & 0 deletions
87
tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
error[E0277]: `fn() {main}` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_bad.rs:7:11 | ||
| | ||
LL | check(main); | ||
| ----- ^^^^ the trait `ConstParamTy` is not implemented for fn item `fn() {main}` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_bad.rs:4:18 | ||
| | ||
LL | fn check(_: impl std::marker::ConstParamTy) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error[E0277]: `[closure@$DIR/const_param_ty_bad.rs:8:11: 8:13]` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_bad.rs:8:11 | ||
| | ||
LL | check(|| {}); | ||
| ----- ^^^^^ the trait `ConstParamTy` is not implemented for closure `[closure@$DIR/const_param_ty_bad.rs:8:11: 8:13]` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_bad.rs:4:18 | ||
| | ||
LL | fn check(_: impl std::marker::ConstParamTy) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error[E0277]: `fn()` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_bad.rs:9:11 | ||
| | ||
LL | check(main as fn()); | ||
| ----- ^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `fn()` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_bad.rs:4:18 | ||
| | ||
LL | fn check(_: impl std::marker::ConstParamTy) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error[E0277]: `&mut ()` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_bad.rs:10:11 | ||
| | ||
LL | check(&mut ()); | ||
| ----- ^^^^^^^ the trait `ConstParamTy` is not implemented for `&mut ()` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_bad.rs:4:18 | ||
| | ||
LL | fn check(_: impl std::marker::ConstParamTy) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error[E0277]: `*mut ()` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_bad.rs:11:11 | ||
| | ||
LL | check(&mut () as *mut ()); | ||
| ----- ^^^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*mut ()` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_bad.rs:4:18 | ||
| | ||
LL | fn check(_: impl std::marker::ConstParamTy) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error[E0277]: `*const ()` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_bad.rs:12:11 | ||
| | ||
LL | check(&() as *const ()); | ||
| ----- ^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*const ()` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_bad.rs:4:18 | ||
| | ||
LL | fn check(_: impl std::marker::ConstParamTy) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
13 changes: 13 additions & 0 deletions
13
tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(adt_const_params)] | ||
|
||
#[derive(PartialEq, Eq)] | ||
struct NotParam; | ||
|
||
fn check<T: std::marker::ConstParamTy + ?Sized>() {} | ||
|
||
fn main() { | ||
check::<&NotParam>(); //~ error: `NotParam` can't be used as a const parameter type | ||
check::<[NotParam]>(); //~ error: `NotParam` can't be used as a const parameter type | ||
check::<[NotParam; 17]>(); //~ error: `NotParam` can't be used as a const parameter type | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
error[E0277]: `NotParam` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:10:13 | ||
| | ||
LL | check::<&NotParam>(); | ||
| ^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam` | ||
| | ||
= note: required for `&NotParam` to implement `ConstParamTy` | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | ||
| | ||
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error[E0277]: `NotParam` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:11:13 | ||
| | ||
LL | check::<[NotParam]>(); | ||
| ^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam` | ||
| | ||
= note: required for `[NotParam]` to implement `ConstParamTy` | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | ||
| | ||
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error[E0277]: `NotParam` can't be used as a const parameter type | ||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:12:13 | ||
| | ||
LL | check::<[NotParam; 17]>(); | ||
| ^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam` | ||
| | ||
= note: required for `[NotParam; 17]` to implement `ConstParamTy` | ||
note: required by a bound in `check` | ||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | ||
| | ||
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
43 changes: 43 additions & 0 deletions
43
tests/ui/const-generics/adt_const_params/const_param_ty_good.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// check-pass | ||
#![allow(incomplete_features)] | ||
#![feature(adt_const_params)] | ||
use std::marker::ConstParamTy; | ||
|
||
#[derive(PartialEq, Eq)] | ||
struct S<T> { | ||
field: u8, | ||
gen: T, | ||
} | ||
|
||
impl<T: ConstParamTy> ConstParamTy for S<T> {} | ||
|
||
fn check<T: ConstParamTy + ?Sized>() {} | ||
|
||
fn main() { | ||
check::<u8>(); | ||
check::<u16>(); | ||
check::<u32>(); | ||
check::<u64>(); | ||
check::<u128>(); | ||
|
||
check::<i8>(); | ||
check::<i16>(); | ||
check::<i32>(); | ||
check::<i64>(); | ||
check::<i128>(); | ||
|
||
check::<char>(); | ||
check::<bool>(); | ||
check::<str>(); | ||
|
||
check::<&u8>(); | ||
check::<&str>(); | ||
check::<[usize]>(); | ||
check::<[u16; 0]>(); | ||
check::<[u8; 42]>(); | ||
|
||
check::<S<u8>>(); | ||
check::<S<[&[bool]; 8]>>(); | ||
|
||
// FIXME: test tuples | ||
} |