Skip to content

Commit 3c9701b

Browse files
committed
add tests
1 parent 3b92583 commit 3c9701b

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
pub trait Trait {}
5+
struct HasCastInTraitImpl<const N: usize, const M: usize>;
6+
impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
7+
pub struct HasTrait<T: Trait>(T);
8+
9+
fn foo1<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 2}, { N }>> {
10+
//~^ ERROR mismatched types
11+
//~| ERROR unconstrained generic constant
12+
loop {}
13+
}
14+
15+
fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
16+
//~^ ERROR mismatched types
17+
//~| ERROR unconstrained generic constant
18+
loop {}
19+
}
20+
21+
fn foo3<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N - 1}>> {
22+
//~^ ERROR mismatched types
23+
//~| ERROR unconstrained generic constant
24+
loop {}
25+
}
26+
27+
fn foo4<const N: usize>(c : [usize; N]) -> HasTrait<HasCastInTraitImpl<{ N - 1}, { N }>> {
28+
//~^ ERROR mismatched types
29+
//~| ERROR unconstrained generic constant
30+
loop {}
31+
}
32+
33+
fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
34+
//~^ ERROR mismatched types
35+
//~| ERROR unconstrained generic constant
36+
loop {}
37+
}
38+
39+
fn main() {}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
error: unconstrained generic constant
2+
--> $DIR/mismatched-const-errors.rs:9:30
3+
|
4+
LL | fn foo1<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 2}, { N }>> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
8+
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 2}, N>`
9+
--> $DIR/mismatched-const-errors.rs:6:22
10+
|
11+
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
12+
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
note: required by a bound in `HasTrait`
14+
--> $DIR/mismatched-const-errors.rs:7:24
15+
|
16+
LL | pub struct HasTrait<T: Trait>(T);
17+
| ^^^^^ required by this bound in `HasTrait`
18+
19+
error[E0308]: mismatched types
20+
--> $DIR/mismatched-const-errors.rs:9:30
21+
|
22+
LL | fn foo1<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 2}, { N }>> {
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ N + 2 + 1 }`
24+
|
25+
= note: expected type `N`
26+
found type `{ N + 2 + 1 }`
27+
28+
error: unconstrained generic constant
29+
--> $DIR/mismatched-const-errors.rs:15:30
30+
|
31+
LL | fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
35+
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1}, { N + 1 }>`
36+
--> $DIR/mismatched-const-errors.rs:6:22
37+
|
38+
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
39+
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40+
note: required by a bound in `HasTrait`
41+
--> $DIR/mismatched-const-errors.rs:7:24
42+
|
43+
LL | pub struct HasTrait<T: Trait>(T);
44+
| ^^^^^ required by this bound in `HasTrait`
45+
46+
error[E0308]: mismatched types
47+
--> $DIR/mismatched-const-errors.rs:15:30
48+
|
49+
LL | fn foo2<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N + 1 }>> {
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N + 1 }`, found `{ N + 1 + 1 }`
51+
|
52+
= note: expected type `{ N + 1 }`
53+
found type `{ N + 1 + 1 }`
54+
55+
error: unconstrained generic constant
56+
--> $DIR/mismatched-const-errors.rs:21:30
57+
|
58+
LL | fn foo3<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N - 1}>> {
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
|
61+
= help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
62+
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1}, { N - 1}>`
63+
--> $DIR/mismatched-const-errors.rs:6:22
64+
|
65+
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
66+
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
note: required by a bound in `HasTrait`
68+
--> $DIR/mismatched-const-errors.rs:7:24
69+
|
70+
LL | pub struct HasTrait<T: Trait>(T);
71+
| ^^^^^ required by this bound in `HasTrait`
72+
73+
error[E0308]: mismatched types
74+
--> $DIR/mismatched-const-errors.rs:21:30
75+
|
76+
LL | fn foo3<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + 1}, { N - 1}>> {
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N - 1}`, found `{ N + 1 + 1 }`
78+
|
79+
= note: expected type `{ N - 1}`
80+
found type `{ N + 1 + 1 }`
81+
82+
error: unconstrained generic constant
83+
--> $DIR/mismatched-const-errors.rs:28:44
84+
|
85+
LL | fn foo4<const N: usize>(c : [usize; N]) -> HasTrait<HasCastInTraitImpl<{ N - 1}, { N }>> {
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
89+
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N - 1}, N>`
90+
--> $DIR/mismatched-const-errors.rs:6:22
91+
|
92+
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
93+
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
note: required by a bound in `HasTrait`
95+
--> $DIR/mismatched-const-errors.rs:7:24
96+
|
97+
LL | pub struct HasTrait<T: Trait>(T);
98+
| ^^^^^ required by this bound in `HasTrait`
99+
100+
error[E0308]: mismatched types
101+
--> $DIR/mismatched-const-errors.rs:28:44
102+
|
103+
LL | fn foo4<const N: usize>(c : [usize; N]) -> HasTrait<HasCastInTraitImpl<{ N - 1}, { N }>> {
104+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `N`, found `{ N - 1 + 1 }`
105+
|
106+
= note: expected type `N`
107+
found type `{ N - 1 + 1 }`
108+
109+
error: unconstrained generic constant
110+
--> $DIR/mismatched-const-errors.rs:34:30
111+
|
112+
LL | fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
113+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114+
|
115+
= help: try adding a `where` bound using this expression: `where [(); { M + 1 }]:`
116+
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + N }, { 2 * N }>`
117+
--> $DIR/mismatched-const-errors.rs:6:22
118+
|
119+
LL | impl<const M: usize> Trait for HasCastInTraitImpl<M, { M + 1 }> {}
120+
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
121+
note: required by a bound in `HasTrait`
122+
--> $DIR/mismatched-const-errors.rs:7:24
123+
|
124+
LL | pub struct HasTrait<T: Trait>(T);
125+
| ^^^^^ required by this bound in `HasTrait`
126+
127+
error[E0308]: mismatched types
128+
--> $DIR/mismatched-const-errors.rs:34:30
129+
|
130+
LL | fn foo5<const N: usize>() -> HasTrait<HasCastInTraitImpl<{ N + N }, { 2 * N }>> {
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ 2 * N }`, found `{ N + N + 1 }`
132+
|
133+
= note: expected type `{ 2 * N }`
134+
found type `{ N + N + 1 }`
135+
136+
error: aborting due to 10 previous errors
137+
138+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)