Skip to content

Commit 937ec0d

Browse files
Add support for associated types in impl + improve tests
1 parent dcedba5 commit 937ec0d

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

rust-engine/src/backends/lean.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,10 @@ set_option linter.unusedVariables false
10351035
) -> DocBuilder<'a, Self, A> {
10361036
let name = self.render_last(ident);
10371037
match kind {
1038-
ImplItemKind::Type { .. } => todo!(),
1038+
ImplItemKind::Type {
1039+
ty,
1040+
parent_bounds: _,
1041+
} => docs![name, reflow!(" := "), ty],
10391042
ImplItemKind::Fn { body, params } => docs![
10401043
docs![
10411044
name,

test-harness/src/snapshots/toolchain__lean-tests into-lean.snap

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,51 @@ class Lean_tests.Traits.Associated_types.Foo (Self : Type) (T : Type) where
209209
class Lean_tests.Traits.Associated_types.Bar (Self : Type) where
210210

211211

212+
structure Lean_tests.Traits.Associated_types.S where
213+
214+
215+
instance Lean_tests.Traits.Associated_types.Impl_2 :
216+
Lean_tests.Traits.Associated_types.Bar i16
217+
where
218+
219+
220+
instance Lean_tests.Traits.Associated_types.Impl_3 (A : Type) :
221+
Lean_tests.Traits.Associated_types.Foo (Rust_primitives.Hax.Tuple2 u32 A) i16
222+
where
223+
224+
212225
class Lean_tests.Traits.Associated_types.T1 (Self : Type) where
213226
T : Type
214227
f : Self -> T -> Result T
215228

216229
class Lean_tests.Traits.Associated_types.T3 (Self : Type) where
217230
T : Type
218-
[_constr_14712917225944295424 :
219-
(Lean_tests.Traits.Associated_types.Foo T Rust_primitives.Hax.Tuple0)]
231+
[_constr_9884638762124940061 : (Lean_tests.Traits.Associated_types.Bar T)]
220232
Tp : Type
221-
[_constr_17020143134338090706 : (Lean_tests.Traits.Associated_types.Foo Tp T)]
233+
[_constr_16271648697586611929 : (Lean_tests.Traits.Associated_types.Foo Tp T)]
222234
f (A : Type) [(Lean_tests.Traits.Associated_types.Bar A)] :
223235
Self -> T -> Tp -> Result usize
224236

237+
instance Lean_tests.Traits.Associated_types.Impl :
238+
Lean_tests.Traits.Associated_types.T1 Lean_tests.Traits.Associated_types.S
239+
where
240+
T := i32
241+
f (self : Lean_tests.Traits.Associated_types.S) (x : i32) := do (2121 : i32)
242+
225243
class Lean_tests.Traits.Associated_types.T2 (Self : Type) where
226244
T : Type
227245
[_constr_11855681382024687155 : (Lean_tests.Traits.Associated_types.T1 T)]
228246
f : Self -> T -> Result usize
229247

248+
instance Lean_tests.Traits.Associated_types.Impl_1 :
249+
Lean_tests.Traits.Associated_types.T2 Lean_tests.Traits.Associated_types.S
250+
where
251+
T := Lean_tests.Traits.Associated_types.S
252+
f (self : Lean_tests.Traits.Associated_types.S)
253+
(x : Lean_tests.Traits.Associated_types.S)
254+
:= do
255+
(21 : usize)
256+
230257
structure Lean_tests.Structs.Miscellaneous.S where
231258
f : i32
232259

tests/lean-tests/src/traits.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,39 @@ mod associated_types {
8181
trait Bar {}
8282

8383
trait T3 {
84-
type T: Foo<()>;
85-
type Tp<T: Bar>: Foo<T>;
84+
type T: Bar;
85+
type Tp<A: Bar>: Foo<Self::T>;
8686
fn f<A: Bar>(&self, x: Self::T, y: Self::Tp<A>) -> usize;
8787
}
88+
89+
struct S {}
90+
impl T1 for S {
91+
type T = i32;
92+
93+
fn f(&self, x: Self::T) -> Self::T {
94+
2121
95+
}
96+
}
97+
impl T2 for S {
98+
type T = S;
99+
100+
fn f(&self, x: Self::T) -> usize {
101+
21
102+
}
103+
}
104+
105+
impl Bar for i16 {}
106+
impl<A> Foo<i16> for (u32, A) {}
107+
108+
// impl T3 for S {
109+
// type T = i16;
110+
111+
// type Tp<A: Bar> = (u32, A);
112+
113+
// fn f<A: Bar>(&self, x: Self::T, y: Self::Tp<A>) -> usize {
114+
// 12
115+
// }
116+
// }
88117
}
89118

90119
mod overlapping_methods {

0 commit comments

Comments
 (0)