Skip to content

Commit 2d5d692

Browse files
Add failing test for projections used as const generic
1 parent b7463e8 commit 2d5d692

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This is currently not possible to use projections as const generics.
2+
// More information about this available here:
3+
// https://github.com/rust-lang/rust/pull/104443#discussion_r1029375633
4+
5+
pub trait Identity {
6+
type Identity;
7+
}
8+
9+
impl<T> Identity for T {
10+
type Identity = Self;
11+
}
12+
13+
pub fn foo<const X: <i32 as Identity>::Identity>() {
14+
//~^ ERROR
15+
assert!(X == 12);
16+
}
17+
18+
fn main() {
19+
foo::<12>();
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: `<i32 as Identity>::Identity` is forbidden as the type of a const generic parameter
2+
--> $DIR/projection-as-arg-const.rs:13:21
3+
|
4+
LL | pub fn foo<const X: <i32 as Identity>::Identity>() {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the only supported types are integers, `bool` and `char`
8+
= help: more complex types are supported with `#![feature(adt_const_params)]`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)