Skip to content

Commit 81ebf17

Browse files
committed
add basic tests
1 parent 0eb3b6d commit 81ebf17

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

tests/test/coherence.rs

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ fn two_impls_for_same_type() {
1313
"overlapping impls of trait `Foo`"
1414
}
1515
}
16+
17+
lowering_error! {
18+
program {
19+
trait Foo { }
20+
struct Bar<const N> { }
21+
impl Foo for Bar<3> { }
22+
impl Foo for Bar<3> { }
23+
}
24+
error_msg {
25+
"overlapping impls of trait `Foo`"
26+
}
27+
}
1628
}
1729

1830
#[test]
@@ -38,6 +50,16 @@ fn concrete_impl_and_blanket_impl() {
3850
impl<T> Foo for T { }
3951
}
4052
}
53+
54+
lowering_success! {
55+
program {
56+
trait Foo { }
57+
struct S {}
58+
struct Bar<const N> { }
59+
impl Foo for Bar<3> { }
60+
impl<const N> Foo for Bar<N> { }
61+
}
62+
}
4163
}
4264

4365
#[test]

tests/test/constants.rs

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//! Tests related to const generics.
2+
3+
use super::*;
4+
5+
#[test]
6+
fn single_impl() {
7+
test! {
8+
program {
9+
struct S<const N> {}
10+
11+
trait Trait {}
12+
13+
impl Trait for S<3> {}
14+
}
15+
16+
goal {
17+
exists<const N> {
18+
S<N>: Trait
19+
}
20+
} yields {
21+
"Unique; substitution [?0 := 3], lifetime constraints []"
22+
}
23+
24+
goal {
25+
forall<const N> {
26+
S<N>: Trait
27+
}
28+
} yields {
29+
"No possible solution"
30+
}
31+
32+
}
33+
}
34+
35+
#[test]
36+
fn multi_impl() {
37+
test! {
38+
program {
39+
struct S<const N> {}
40+
41+
trait Trait {}
42+
43+
impl Trait for S<3> {}
44+
impl Trait for S<5> {}
45+
}
46+
47+
goal {
48+
exists<const N> {
49+
S<N>: Trait
50+
}
51+
} yields {
52+
"Ambiguous; no inference guidance"
53+
}
54+
55+
goal {
56+
forall<const N> {
57+
S<N>: Trait
58+
}
59+
} yields {
60+
"No possible solution"
61+
}
62+
63+
}
64+
}
65+
66+
#[test]
67+
fn generic_impl() {
68+
test! {
69+
program {
70+
struct S<const N> {}
71+
72+
trait Trait {}
73+
74+
impl<const N> Trait for S<N> {}
75+
}
76+
77+
goal {
78+
exists<const N> {
79+
S<N>: Trait
80+
}
81+
} yields {
82+
"Unique; for<?U0> { substitution [?0 := ^0.0], lifetime constraints [] }"
83+
}
84+
85+
goal {
86+
forall<const N> {
87+
S<N>: Trait
88+
}
89+
} yields {
90+
"Unique; substitution [], lifetime constraints []"
91+
}
92+
}
93+
}
94+
95+
#[test]
96+
fn placeholders_eq() {
97+
test! {
98+
program {}
99+
100+
goal {
101+
forall<const C, const D> {
102+
C = D
103+
}
104+
} yields {
105+
"No possible solution"
106+
}
107+
108+
goal {
109+
exists<C> {
110+
forall<D> {
111+
C = D
112+
}
113+
}
114+
} yields {
115+
"No possible solution"
116+
}
117+
118+
goal {
119+
forall<C> {
120+
exists<D> {
121+
C = D
122+
}
123+
}
124+
} yields {
125+
"Unique; substitution [?0 := !1_0], lifetime constraints []"
126+
}
127+
128+
goal {
129+
forall<C1, C2> {
130+
exists<D1, D2> {
131+
C1 = D1, C2 = D2, D1 = D2
132+
}
133+
}
134+
} yields {
135+
"No possible solution"
136+
}
137+
}
138+
}

tests/test/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>) {
307307
mod auto_traits;
308308
mod coherence_goals;
309309
mod coinduction;
310+
mod constants;
310311
mod cycle;
311312
mod existential_types;
312313
mod functions;

0 commit comments

Comments
 (0)