fix(idl_gen_rust): Fix lifetime warning added in Rust 1.89 (#8709)

Rust 1.89 added a new lifetime-related warning:
<https://blog.rust-lang.org/2025/08/07/Rust-1.89.0/#mismatched-lifetime-syntaxes-lint>

The Rust code generator currently emits code which trips this warning. This very small PR
fixes the issue for the relevant generated functions and for the Rust flexbuffers code.

Fixes #8705
This commit is contained in:
Rob Jellinghaus
2025-12-02 19:27:40 -08:00
committed by GitHub
parent 4786322b90
commit a5343d6116
9 changed files with 32 additions and 32 deletions

View File

@@ -2437,7 +2437,7 @@ class RustGenerator : public BaseGenerator {
code_ += "/// `root_as_{{STRUCT_FN}}_unchecked`.";
code_ +=
"pub fn root_as_{{STRUCT_FN}}(buf: &[u8]) "
"-> Result<{{STRUCT_TY}}, flatbuffers::InvalidFlatbuffer> {";
"-> Result<{{STRUCT_TY}}<'_>, flatbuffers::InvalidFlatbuffer> {";
code_ += " flatbuffers::root::<{{STRUCT_TY}}>(buf)";
code_ += "}";
code_ += "#[inline]";
@@ -2449,7 +2449,7 @@ class RustGenerator : public BaseGenerator {
code_ += "/// `size_prefixed_root_as_{{STRUCT_FN}}_unchecked`.";
code_ +=
"pub fn size_prefixed_root_as_{{STRUCT_FN}}"
"(buf: &[u8]) -> Result<{{STRUCT_TY}}, "
"(buf: &[u8]) -> Result<{{STRUCT_TY}}<'_>, "
"flatbuffers::InvalidFlatbuffer> {";
code_ += " flatbuffers::size_prefixed_root::<{{STRUCT_TY}}>(buf)";
code_ += "}";
@@ -2499,7 +2499,7 @@ class RustGenerator : public BaseGenerator {
" `{{STRUCT_TY}}`.";
code_ +=
"pub unsafe fn root_as_{{STRUCT_FN}}_unchecked"
"(buf: &[u8]) -> {{STRUCT_TY}} {";
"(buf: &[u8]) -> {{STRUCT_TY}}<'_> {";
code_ += " unsafe { flatbuffers::root_unchecked::<{{STRUCT_TY}}>(buf) }";
code_ += "}";
code_ += "#[inline]";
@@ -2512,7 +2512,7 @@ class RustGenerator : public BaseGenerator {
" size prefixed `{{STRUCT_TY}}`.";
code_ +=
"pub unsafe fn size_prefixed_root_as_{{STRUCT_FN}}"
"_unchecked(buf: &[u8]) -> {{STRUCT_TY}} {";
"_unchecked(buf: &[u8]) -> {{STRUCT_TY}}<'_> {";
code_ +=
" unsafe { flatbuffers::size_prefixed_root_unchecked::<{{STRUCT_TY}}>"
"(buf) }";