From c329d6fa9069890c7fbd62d7bffdbe5c776ed620 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Fri, 5 Apr 2019 13:30:58 -0600 Subject: Ensure we don't subtract with underflow getting enum names (#5246) * Ensure we don't subtract with underflow getting enum names * Yep - forgot to run this --- src/idl_gen_rust.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/idl_gen_rust.cpp') diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index e8ecbbc4..1b8ff116 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -698,14 +698,14 @@ class RustGenerator : public BaseGenerator { code_ += "pub fn enum_name_{{ENUM_NAME_SNAKE}}(e: {{ENUM_NAME}}) -> " "&'static str {"; - code_ += " let index: usize = e as usize\\"; + code_ += " let index = e as {{BASE_TYPE}}\\"; if (enum_def.vals.vec.front()->value) { auto vals = GetEnumValUse(enum_def, *enum_def.vals.vec.front()); - code_ += " - " + vals + " as usize\\"; + code_ += " - " + vals + " as {{BASE_TYPE}}\\"; } code_ += ";"; - code_ += " ENUM_NAMES_{{ENUM_NAME_CAPS}}[index]"; + code_ += " ENUM_NAMES_{{ENUM_NAME_CAPS}}[index as usize]"; code_ += "}"; code_ += ""; } -- cgit v1.2.3