Skip to content

fix(lean): Add trait-level arguments as explicit arguments to trait items#1803

Merged
abentkamp merged 7 commits intomainfrom
fix-lean-trait-params
Dec 15, 2025
Merged

fix(lean): Add trait-level arguments as explicit arguments to trait items#1803
abentkamp merged 7 commits intomainfrom
fix-lean-trait-params

Conversation

@clementblaudeau
Copy link
Copy Markdown
Contributor

Trait-level arguments are marked as always explicit for each trait item, ensuring a regular treatment at call sites.

Overview

Considering the following rust code :

trait T1<A, B> {
    fn f1<C, D>(&self) -> (); // A and B do not appear
    fn f2<C, D>(&self, x: &A) -> (); // A appears
    fn f3<C, D>(&self, x: &A, y: &B) -> (); // Both appear
}

Previously, the Lean backend would translate it as :

class T1 (Self : Type) (A : Type) (B : Type) where
  f1 (C : Type) (D : Type) : (Self -> RustM Rust_primitives.Hax.Tuple0)
  f2 (C : Type) (D : Type) : (Self -> A -> RustM Rust_primitives.Hax.Tuple0)
  f3 (C : Type) (D : Type) : (Self -> A -> B -> RustM Rust_primitives.Hax.Tuple0)

However, f1 and f3 would not have the same arguments : the trait-level parameters are explicit for f1 and implicit for f3. Now the Lean backend produces :

class T1 (Self : Type) (A : Type) (B : Type) where
  f1 (A B) (C : Type) (D : Type) : (Self -> RustM Rust_primitives.Hax.Tuple0)
  f2 (A B) (C : Type) (D : Type) : (Self -> A -> RustM Rust_primitives.Hax.Tuple0)
  f3 (A B) (C : Type) (D : Type) : (Self -> A -> B -> RustM Rust_primitives.Hax.Tuple0)

This, using leanprover/lean4#7742, ensures that the trait-level params A and B are always explicit.

fixes #1796

@clementblaudeau clementblaudeau requested a review from a team as a code owner December 5, 2025 18:56
@clementblaudeau clementblaudeau changed the base branch from main to lean-const-parameters December 5, 2025 18:56
Base automatically changed from lean-const-parameters to main December 11, 2025 14:05
@abentkamp abentkamp force-pushed the fix-lean-trait-params branch from 8960e7d to e5929df Compare December 15, 2025 12:58
@abentkamp abentkamp added this pull request to the merge queue Dec 15, 2025
Merged via the queue into main with commit 49349e0 Dec 15, 2025
17 of 18 checks passed
@abentkamp abentkamp deleted the fix-lean-trait-params branch December 15, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lean] Incorrect treatment of trait-level parameters

3 participants