From b8274bd8e17d5c353788a74e44cb04c0ce736d63 Mon Sep 17 00:00:00 2001 From: Lucas Franceschino Date: Thu, 15 Feb 2024 12:08:57 +0100 Subject: [PATCH] fix(engine/print-rust): `impl ...` local_idents The following Rust code: ```rust fn f(x: impl Foo + Bar) {} ``` Is translated as: ```rust fn f(x: NAME) {} ``` where `NAME` is actually `impl Foo + Bar`. This commit recognizes such `NAME` local idents and rename them in the Rust printer. --- engine/lib/print_rust.ml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/lib/print_rust.ml b/engine/lib/print_rust.ml index feb7961c1..ddd7dce25 100644 --- a/engine/lib/print_rust.ml +++ b/engine/lib/print_rust.ml @@ -101,7 +101,19 @@ module Raw = struct let pglobal_ident = pglobal_ident' "" let plocal_ident span (e : Local_ident.t) : AnnotatedString.t = - pure span e.name + let name = + match String.chop_prefix ~prefix:"impl " e.name with + | Some name -> + "impl_" + ^ String.map + ~f:(function + | 'a' .. 'z' as letter -> letter + | 'A' .. 'Z' as letter -> letter + | _ -> '_') + name + | _ -> e.name + in + pure span name let dmutability span : _ -> AnnotatedString.t = pure span << function Mutable _ -> "mut " | _ -> ""