You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by "Jens Geyer (Jira)" <ji...@apache.org> on 2026/10/14 00:04:00 UTC

[jira] [Created] (THRIFT-6406) Rust generator does not escape keywords since Rust 2018/2024 and service method names

Jens Geyer created THRIFT-6406:
----------------------------------

             Summary: Rust generator does not escape keywords since Rust 2018/2024 and service method names
                 Key: THRIFT-6406
                 URL: https://issues.apache.org/jira/browse/THRIFT-6406
             Project: Thrift
          Issue Type: Bug
          Components: Rust - Compiler
    Affects Versions: 0.25.0
            Reporter: Jens Geyer


The Rust generator escapes identifiers that clash with Rust keywords by looking them up in {{RUST_RESERVED_WORDS}} in {{compiler/cpp/src/thrift/generate/t_rs_generator.cc}}. Two gaps make the generated code fail to compile:
# The list predates Rust 2018. It lacks {{async}}, {{await}}, {{dyn}} and {{try}}, which are keywords or reserved since edition 2018, and {{gen}}, which is reserved since edition 2024.
# Service method names do not go through the escaping at all. Even a method named {{type}} or {{match}} comes out unescaped, while an argument named {{type}} becomes {{type_}}.

IDL:
{code}
struct S {
  1: i32 gen
  2: i32 dyn
  3: i32 try
  4: i32 await
  5: i32 type
}
service Svc {
  i32 gen(1: i32 dyn)
  void try()
  void type(1: i32 type)
  void match()
}
{code}

{{thrift --gen rs}} at master a81db74f8 writes the fields {{pub gen}}, {{pub dyn}}, {{pub try}}, {{pub await}} and {{pub type_}}, and the client methods {{fn gen(&mut self, dyn: i32)}}, {{fn try(&mut self)}}, {{fn type(&mut self, type_: i32)}} and {{fn match(&mut self)}}. A field named {{async}} is accepted with the warning {{"async" is deprecated. It is called "oneway" now.}} and comes out as {{pub async}}.

rustc 1.85.1, one identifier per file:
||Identifier||Edition 2021||Edition 2024||
|field {{gen}}|compiles|expected identifier, found reserved keyword {{gen}}|
|field {{try}}|expected identifier, found reserved keyword {{try}}|same|
|field {{await}}|expected identifier, found keyword {{await}}|same|
|field {{dyn}}|expected identifier, found keyword {{dyn}}|same|
|field {{async}}|expected identifier, found keyword {{async}}|same|
|method {{type}}|expected identifier, found keyword {{type}}|same|
|method {{match}}|expected identifier, found keyword {{match}}|same|

So such IDL already gives uncompilable code for crates on edition 2018 or 2021. On edition 2024, which THRIFT-6162 ([PR #4003|https://github.com/apache/thrift/pull/4003]) brings to the crates in this repository, {{gen}} joins them; a review on that PR pointed out the {{gen}} case.

Escaping changes the generated names, for example to {{try_}} like the existing {{type_}}. Only edition-2015 code can use the unescaped names today.

Related: THRIFT-5124.

_Drafted with AI assistance (Claude Opus 5.5); reviewed and posted by Jens Geyer._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)