Skip to content

Commit a262e3e

Browse files
committed
add tests for precedence
1 parent bb8be4f commit a262e3e

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
5+
fn bar<const N: usize, const K: usize>(a: [u32; 2 + N], b: [u32; K]) {
6+
let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
7+
//~^ ERROR unconstrained generic constant
8+
//~| ERROR unconstrained generic constant
9+
//~| ERROR unconstrained generic constant
10+
//~| ERROR mismatched types
11+
}
12+
13+
fn foo<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * {M + K}] {}
14+
//~^ ERROR mismatched types
15+
16+
17+
fn bar2<const N: usize, const K: usize>(a: [u32; 2 + N], b: [u32; K]) {
18+
let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
19+
//~^ ERROR unconstrained generic constant
20+
//~| ERROR unconstrained generic constant
21+
//~| ERROR unconstrained generic constant
22+
//~| ERROR mismatched types
23+
}
24+
25+
fn foo2<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * M * K] {}
26+
//~^ ERROR mismatched types
27+
28+
29+
fn bar3<const N: usize, const K: usize, const L: usize>(a: [u32; 2 + N], b: [u32; K + L]) {
30+
let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
31+
//~^ ERROR unconstrained generic constant
32+
//~| ERROR unconstrained generic constant
33+
//~| ERROR unconstrained generic constant
34+
//~| ERROR mismatched types
35+
}
36+
37+
fn foo3<const M: usize, const K: usize, const L: usize>(a: [u32; M], b: [u32; K + L])
38+
-> [u32; 3 * M * {K + L}] {}
39+
//~^ ERROR mismatched types
40+
41+
fn main() {}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
error: unconstrained generic constant
2+
--> $DIR/mismatched-const-types-precedence.rs:6:33
3+
|
4+
LL | let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N + K } }]:`
8+
note: required by a bound in `foo`
9+
--> $DIR/mismatched-const-types-precedence.rs:13:75
10+
|
11+
LL | fn foo<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * {M + K}] {}
12+
| ^^^^^^^^^^^ required by this bound in `foo`
13+
14+
error: unconstrained generic constant
15+
--> $DIR/mismatched-const-types-precedence.rs:6:10
16+
|
17+
LL | let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
18+
| ^^^^^^^^^^^^^^^^^^^^
19+
|
20+
= help: try adding a `where` bound using this expression: `where [(); { 3 * 2 + N + K }]:`
21+
22+
error[E0308]: mismatched types
23+
--> $DIR/mismatched-const-types-precedence.rs:6:33
24+
|
25+
LL | let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N + K`, found `{ 3 * { 2 + N + K } }`
27+
|
28+
= note: expected type `3 * 2 + N + K`
29+
found type `{ 3 * { 2 + N + K } }`
30+
31+
error: unconstrained generic constant
32+
--> $DIR/mismatched-const-types-precedence.rs:6:33
33+
|
34+
LL | let _: [u32; 3 * 2 + N + K] = foo::<{ 2 + N }, K>(a, b);
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
36+
|
37+
= help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N + K } }]:`
38+
note: required by a bound in `foo`
39+
--> $DIR/mismatched-const-types-precedence.rs:13:75
40+
|
41+
LL | fn foo<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * {M + K}] {}
42+
| ^^^^^^^^^^^ required by this bound in `foo`
43+
44+
error[E0308]: mismatched types
45+
--> $DIR/mismatched-const-types-precedence.rs:13:69
46+
|
47+
LL | fn foo<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * {M + K}] {}
48+
| --- ^^^^^^^^^^^^^^^^^^ expected array `[u32; _]`, found `()`
49+
| |
50+
| implicitly returns `()` as its body has no tail or `return` expression
51+
52+
error: unconstrained generic constant
53+
--> $DIR/mismatched-const-types-precedence.rs:18:33
54+
|
55+
LL | let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
56+
| ^^^^^^^^^^^^^^^^^^^^
57+
|
58+
= help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K }]:`
59+
note: required by a bound in `foo2`
60+
--> $DIR/mismatched-const-types-precedence.rs:25:76
61+
|
62+
LL | fn foo2<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * M * K] {}
63+
| ^^^^^^^^^ required by this bound in `foo2`
64+
65+
error: unconstrained generic constant
66+
--> $DIR/mismatched-const-types-precedence.rs:18:10
67+
|
68+
LL | let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
69+
| ^^^^^^^^^^^^^^^^^^^^
70+
|
71+
= help: try adding a `where` bound using this expression: `where [(); { 3 * 2 + N * K }]:`
72+
73+
error[E0308]: mismatched types
74+
--> $DIR/mismatched-const-types-precedence.rs:18:33
75+
|
76+
LL | let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N * K`, found `{ 3 * { 2 + N } * K }`
78+
|
79+
= note: expected type `3 * 2 + N * K`
80+
found type `{ 3 * { 2 + N } * K }`
81+
82+
error: unconstrained generic constant
83+
--> $DIR/mismatched-const-types-precedence.rs:18:33
84+
|
85+
LL | let _: [u32; 3 * 2 + N * K] = foo2::<{ 2 + N }, K>(a, b);
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K }]:`
89+
note: required by a bound in `foo2`
90+
--> $DIR/mismatched-const-types-precedence.rs:25:76
91+
|
92+
LL | fn foo2<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * M * K] {}
93+
| ^^^^^^^^^ required by this bound in `foo2`
94+
95+
error[E0308]: mismatched types
96+
--> $DIR/mismatched-const-types-precedence.rs:25:70
97+
|
98+
LL | fn foo2<const M: usize, const K: usize>(a: [u32; M], b: [u32; K]) -> [u32; 3 * M * K] {}
99+
| ---- ^^^^^^^^^^^^^^^^ expected array `[u32; _]`, found `()`
100+
| |
101+
| implicitly returns `()` as its body has no tail or `return` expression
102+
103+
error: unconstrained generic constant
104+
--> $DIR/mismatched-const-types-precedence.rs:30:37
105+
|
106+
LL | let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
107+
| ^^^^^^^^^^^^^^^^^^^^^^^
108+
|
109+
= help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K + L }]:`
110+
note: required by a bound in `foo3`
111+
--> $DIR/mismatched-const-types-precedence.rs:38:12
112+
|
113+
LL | fn foo3<const M: usize, const K: usize, const L: usize>(a: [u32; M], b: [u32; K + L])
114+
| ---- required by a bound in this
115+
LL | -> [u32; 3 * M * {K + L}] {}
116+
| ^^^^^^^^^^^^^^^ required by this bound in `foo3`
117+
118+
error: unconstrained generic constant
119+
--> $DIR/mismatched-const-types-precedence.rs:30:10
120+
|
121+
LL | let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
122+
| ^^^^^^^^^^^^^^^^^^^^^^^^
123+
|
124+
= help: try adding a `where` bound using this expression: `where [(); { 3 * 2 + N * K + L }]:`
125+
126+
error[E0308]: mismatched types
127+
--> $DIR/mismatched-const-types-precedence.rs:30:37
128+
|
129+
LL | let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
130+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3 * 2 + N * K + L`, found `{ 3 * { 2 + N } * K + L }`
131+
|
132+
= note: expected type `3 * 2 + N * K + L`
133+
found type `{ 3 * { 2 + N } * K + L }`
134+
135+
error: unconstrained generic constant
136+
--> $DIR/mismatched-const-types-precedence.rs:30:37
137+
|
138+
LL | let _: [u32; 3 * 2 + N * K + L] = foo3::<{ 2 + N }, K, L>(a, b);
139+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140+
|
141+
= help: try adding a `where` bound using this expression: `where [(); { 3 * { 2 + N } * K + L }]:`
142+
note: required by a bound in `foo3`
143+
--> $DIR/mismatched-const-types-precedence.rs:38:12
144+
|
145+
LL | fn foo3<const M: usize, const K: usize, const L: usize>(a: [u32; M], b: [u32; K + L])
146+
| ---- required by a bound in this
147+
LL | -> [u32; 3 * M * {K + L}] {}
148+
| ^^^^^^^^^^^^^^^ required by this bound in `foo3`
149+
150+
error[E0308]: mismatched types
151+
--> $DIR/mismatched-const-types-precedence.rs:38:6
152+
|
153+
LL | fn foo3<const M: usize, const K: usize, const L: usize>(a: [u32; M], b: [u32; K + L])
154+
| ---- implicitly returns `()` as its body has no tail or `return` expression
155+
LL | -> [u32; 3 * M * {K + L}] {}
156+
| ^^^^^^^^^^^^^^^^^^^^^^ expected array `[u32; _]`, found `()`
157+
158+
error: aborting due to 15 previous errors
159+
160+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)