Skip to content

Commit 4310ba2

Browse files
author
Alexander Regueiro
committed
Added test suite.
1 parent cad1b18 commit 4310ba2

36 files changed

+3138
-11
lines changed

src/test/run-pass/issues/issue-25700-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ fn record_type<Id: AstId>(i: Id::Untyped) -> u8 {
1818
}
1919

2020
pub fn main() {
21-
assert_eq!(record_type::<u32>(3), 42);
21+
assert_eq!(record_type::<u32>(3), 42);
2222
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// Traits:
2+
3+
pub trait Alpha {
4+
fn alpha(self) -> usize;
5+
}
6+
7+
pub trait Beta {
8+
type Gamma;
9+
fn gamma(self) -> Self::Gamma;
10+
}
11+
12+
pub trait Delta {
13+
fn delta(self) -> usize;
14+
}
15+
16+
pub trait Epsilon<'a> {
17+
type Zeta;
18+
fn zeta(&'a self) -> Self::Zeta;
19+
20+
fn epsilon(&'a self) -> usize;
21+
}
22+
23+
pub trait Eta {
24+
fn eta(self) -> usize;
25+
}
26+
27+
// Assertions:
28+
29+
pub fn assert_alpha<T: Alpha>(x: T) -> usize { x.alpha() }
30+
pub fn assert_static<T: 'static>(_: T) -> usize { 24 }
31+
pub fn assert_delta<T: Delta>(x: T) -> usize { x.delta() }
32+
pub fn assert_epsilon_specific<'a, T: 'a + Epsilon<'a>>(x: &'a T) -> usize { x.epsilon() }
33+
pub fn assert_epsilon_forall<T: for<'a> Epsilon<'a>>() {}
34+
pub fn assert_forall_epsilon_zeta_satisfies_eta<T>(x: T) -> usize
35+
where
36+
T: for<'a> Epsilon<'a>,
37+
for<'a> <T as Epsilon<'a>>::Zeta: Eta,
38+
{
39+
x.epsilon() + x.zeta().eta()
40+
}
41+
42+
// Implementations and types:
43+
44+
#[derive(Copy, Clone)]
45+
pub struct BetaType;
46+
47+
#[derive(Copy, Clone)]
48+
pub struct GammaType;
49+
50+
#[derive(Copy, Clone)]
51+
pub struct ZetaType;
52+
53+
impl Beta for BetaType {
54+
type Gamma = GammaType;
55+
fn gamma(self) -> Self::Gamma { GammaType }
56+
}
57+
58+
impl<'a> Beta for &'a BetaType {
59+
type Gamma = GammaType;
60+
fn gamma(self) -> Self::Gamma { GammaType }
61+
}
62+
63+
impl Beta for GammaType {
64+
type Gamma = Self;
65+
fn gamma(self) -> Self::Gamma { self }
66+
}
67+
68+
impl Alpha for GammaType {
69+
fn alpha(self) -> usize { 42 }
70+
}
71+
72+
impl Delta for GammaType {
73+
fn delta(self) -> usize { 1337 }
74+
}
75+
76+
impl<'a> Epsilon<'a> for GammaType {
77+
type Zeta = ZetaType;
78+
fn zeta(&'a self) -> Self::Zeta { ZetaType }
79+
80+
fn epsilon(&'a self) -> usize { 7331 }
81+
}
82+
83+
impl Eta for ZetaType {
84+
fn eta(self) -> usize { 7 }
85+
}
86+
87+
// Desugared forms to check against:
88+
89+
pub fn desugared_bound<B>(beta: B) -> usize
90+
where
91+
B: Beta,
92+
B::Gamma: Alpha
93+
{
94+
let gamma: B::Gamma = beta.gamma();
95+
assert_alpha::<B::Gamma>(gamma)
96+
}
97+
98+
pub fn desugared_bound_region<B>(beta: B) -> usize
99+
where
100+
B: Beta,
101+
B::Gamma: 'static,
102+
{
103+
assert_static::<B::Gamma>(beta.gamma())
104+
}
105+
106+
pub fn desugared_bound_multi<B>(beta: B) -> usize
107+
where
108+
B: Copy + Beta,
109+
B::Gamma: Alpha + 'static + Delta,
110+
{
111+
assert_alpha::<B::Gamma>(beta.gamma()) +
112+
assert_static::<B::Gamma>(beta.gamma()) +
113+
assert_delta::<B::Gamma>(beta.gamma())
114+
}
115+
116+
pub fn desugared_bound_region_specific<'a, B>(gamma: &'a B::Gamma) -> usize
117+
where
118+
B: Beta,
119+
B::Gamma: 'a + Epsilon<'a>,
120+
{
121+
assert_epsilon_specific::<B::Gamma>(gamma)
122+
}
123+
124+
pub fn desugared_bound_region_forall<B>(beta: B) -> usize
125+
where
126+
B: Beta,
127+
B::Gamma: Copy + for<'a> Epsilon<'a>,
128+
{
129+
assert_epsilon_forall::<B::Gamma>();
130+
let g1: B::Gamma = beta.gamma();
131+
let g2: B::Gamma = g1;
132+
assert_epsilon_specific::<B::Gamma>(&g1) +
133+
assert_epsilon_specific::<B::Gamma>(&g2)
134+
}
135+
136+
pub fn desugared_bound_region_forall2<B>(beta: B) -> usize
137+
where
138+
B: Beta,
139+
B::Gamma: Copy + for<'a> Epsilon<'a>,
140+
for<'a> <B::Gamma as Epsilon<'a>>::Zeta: Eta,
141+
{
142+
let gamma = beta.gamma();
143+
assert_forall_epsilon_zeta_satisfies_eta::<B::Gamma>(gamma)
144+
}
145+
146+
pub fn desugared_contraint_region_forall<B>(beta: B) -> usize
147+
where
148+
for<'a> &'a B: Beta,
149+
for<'a> <&'a B as Beta>::Gamma: Alpha,
150+
{
151+
let g1 = beta.gamma();
152+
let g2 = beta.gamma();
153+
assert_alpha(g1) + assert_alpha(g2)
154+
}
155+
156+
pub fn desugared_bound_nested<B>(beta: B) -> usize
157+
where
158+
B: Beta,
159+
B::Gamma: Copy + Alpha + Beta,
160+
<B::Gamma as Beta>::Gamma: Delta,
161+
{
162+
let go = beta.gamma();
163+
let gi = go.gamma();
164+
go.alpha() + gi.delta()
165+
}
166+
167+
pub fn desugared() {
168+
let beta = BetaType;
169+
let gamma = beta.gamma();
170+
171+
assert_eq!(42, desugared_bound(beta));
172+
assert_eq!(24, desugared_bound_region(beta));
173+
assert_eq!(42 + 24 + 1337, desugared_bound_multi(beta));
174+
assert_eq!(7331, desugared_bound_region_specific::<BetaType>(&gamma));
175+
assert_eq!(7331 * 2, desugared_bound_region_forall(beta));
176+
assert_eq!(42 + 1337, desugared_bound_nested(beta));
177+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
// Traits:
2+
3+
pub trait Alpha {
4+
fn alpha(self) -> usize;
5+
}
6+
7+
pub trait Beta {
8+
type Gamma;
9+
fn gamma(&self) -> Self::Gamma;
10+
}
11+
12+
pub trait Delta {
13+
fn delta(self) -> usize;
14+
}
15+
16+
pub trait Epsilon<'a> {
17+
type Zeta;
18+
fn zeta(&'a self) -> Self::Zeta;
19+
20+
fn epsilon(&'a self) -> usize;
21+
}
22+
23+
pub trait Eta {
24+
fn eta(self) -> usize;
25+
}
26+
27+
// Assertions:
28+
29+
pub fn assert_alpha<T: Alpha>(x: T) -> usize { x.alpha() }
30+
pub fn assert_static<T: 'static>(_: T) -> usize { 24 }
31+
pub fn assert_delta<T: Delta>(x: T) -> usize { x.delta() }
32+
pub fn assert_epsilon_specific<'a, T: 'a + Epsilon<'a>>(x: &'a T) -> usize { x.epsilon() }
33+
pub fn assert_epsilon_forall<T: for<'a> Epsilon<'a>>() {}
34+
pub fn assert_forall_epsilon_zeta_satisfies_eta<T>(x: T) -> usize
35+
where
36+
T: for<'a> Epsilon<'a>,
37+
for<'a> <T as Epsilon<'a>>::Zeta: Eta,
38+
{
39+
x.epsilon() + x.zeta().eta()
40+
}
41+
42+
// Implementations and types:
43+
44+
#[derive(Copy, Clone)]
45+
pub struct BetaType;
46+
47+
#[derive(Copy, Clone)]
48+
pub struct GammaType;
49+
50+
#[derive(Copy, Clone)]
51+
pub struct ZetaType;
52+
53+
impl<T> Beta for &(dyn Beta<Gamma = T> + Send) {
54+
type Gamma = T;
55+
fn gamma(&self) -> Self::Gamma { (*self).gamma() }
56+
}
57+
58+
impl Beta for BetaType {
59+
type Gamma = GammaType;
60+
fn gamma(&self) -> Self::Gamma { GammaType }
61+
}
62+
63+
impl<'a> Beta for &'a BetaType {
64+
type Gamma = GammaType;
65+
fn gamma(&self) -> Self::Gamma { GammaType }
66+
}
67+
68+
impl Beta for GammaType {
69+
type Gamma = Self;
70+
fn gamma(&self) -> Self::Gamma { Self }
71+
}
72+
73+
impl Alpha for GammaType {
74+
fn alpha(self) -> usize { 42 }
75+
}
76+
77+
impl Delta for GammaType {
78+
fn delta(self) -> usize { 1337 }
79+
}
80+
81+
impl<'a> Epsilon<'a> for GammaType {
82+
type Zeta = ZetaType;
83+
fn zeta(&'a self) -> Self::Zeta { ZetaType }
84+
85+
fn epsilon(&'a self) -> usize { 7331 }
86+
}
87+
88+
impl Eta for ZetaType {
89+
fn eta(self) -> usize { 7 }
90+
}
91+
92+
// Desugared forms to check against:
93+
94+
pub fn desugared_bound<B: ?Sized>(beta: &B) -> usize
95+
where
96+
B: Beta,
97+
B::Gamma: Alpha
98+
{
99+
let gamma: B::Gamma = beta.gamma();
100+
assert_alpha::<B::Gamma>(gamma)
101+
}
102+
103+
pub fn desugared_bound_region<B: ?Sized>(beta: &B) -> usize
104+
where
105+
B: Beta,
106+
B::Gamma: 'static,
107+
{
108+
assert_static::<B::Gamma>(beta.gamma())
109+
}
110+
111+
pub fn desugared_bound_multi<B: ?Sized>(beta: B) -> usize
112+
where
113+
B: Copy + Beta,
114+
B::Gamma: Alpha + 'static + Delta,
115+
{
116+
assert_alpha::<B::Gamma>(beta.gamma()) +
117+
assert_static::<B::Gamma>(beta.gamma()) +
118+
assert_delta::<B::Gamma>(beta.gamma())
119+
}
120+
121+
pub fn desugared_bound_region_specific<'a, B: ?Sized>(gamma: &'a B::Gamma) -> usize
122+
where
123+
B: Beta,
124+
B::Gamma: 'a + Epsilon<'a>,
125+
{
126+
assert_epsilon_specific::<B::Gamma>(gamma)
127+
}
128+
129+
pub fn desugared_bound_region_forall<B: ?Sized>(beta: &B) -> usize
130+
where
131+
B: Beta,
132+
B::Gamma: Copy + for<'a> Epsilon<'a>,
133+
{
134+
assert_epsilon_forall::<B::Gamma>();
135+
let g1: B::Gamma = beta.gamma();
136+
let g2: B::Gamma = g1;
137+
assert_epsilon_specific::<B::Gamma>(&g1) +
138+
assert_epsilon_specific::<B::Gamma>(&g2)
139+
}
140+
141+
pub fn desugared_bound_region_forall2<B: ?Sized>(beta: &B) -> usize
142+
where
143+
B: Beta,
144+
B::Gamma: Copy + for<'a> Epsilon<'a>,
145+
for<'a> <B::Gamma as Epsilon<'a>>::Zeta: Eta,
146+
{
147+
let gamma = beta.gamma();
148+
assert_forall_epsilon_zeta_satisfies_eta::<B::Gamma>(gamma)
149+
}
150+
151+
pub fn desugared_contraint_region_forall<B: ?Sized>(beta: &B) -> usize
152+
where
153+
for<'a> &'a B: Beta,
154+
for<'a> <&'a B as Beta>::Gamma: Alpha,
155+
{
156+
let g1 = beta.gamma();
157+
let g2 = beta.gamma();
158+
assert_alpha(g1) + assert_alpha(g2)
159+
}
160+
161+
pub fn desugared_bound_nested<B: ?Sized>(beta: &B) -> usize
162+
where
163+
B: Beta,
164+
B::Gamma: Copy + Alpha + Beta,
165+
<B::Gamma as Beta>::Gamma: Delta,
166+
{
167+
let go = beta.gamma();
168+
let gi = go.gamma();
169+
go.alpha() + gi.delta()
170+
}
171+
172+
pub fn desugared() {
173+
let beta = BetaType;
174+
let gamma = beta.gamma();
175+
176+
assert_eq!(42, desugared_bound(&beta));
177+
assert_eq!(24, desugared_bound_region(&beta));
178+
assert_eq!(42 + 24 + 1337, desugared_bound_multi(beta));
179+
assert_eq!(7331, desugared_bound_region_specific::<BetaType>(&gamma));
180+
assert_eq!(7331 * 2, desugared_bound_region_forall(&beta));
181+
assert_eq!(42 + 1337, desugared_bound_nested(&beta));
182+
}

0 commit comments

Comments
 (0)