Repository: dtolnay/cxx (language: rust)

Issue:
Include <cstdint> when generating enums
When I generated code with a shared enum, I got this error from MSVC:

    'uint8_t': must be a simple type or resolve to one

Generated code needs `#include <cstdint>` when these types are used. The obvious workaround is to include it in my own header.


Discussion / hints:

Fix patch:
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 33ed31cfe..2d527ddb1 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -90,6 +90,7 @@ pub struct Enum {
     pub brace_token: Brace,
     pub variants: Vec<Variant>,
     pub repr: Atom,
+    pub repr_type: Type,
 }
 
 pub struct ExternFn {
diff --git a/syntax/parse.rs b/syntax/parse.rs
index b55758420..57520d9ce 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -7,7 +7,7 @@ use crate::syntax::{
     Namespace, Pair, Receiver, Ref, ResolvableName, Signature, Slice, Struct, Ty1, Type, TypeAlias,
     Var, Variant,
 };
-use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
+use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
 use quote::{format_ident, quote, quote_spanned};
 use syn::parse::{ParseStream, Parser};
 use syn::punctuated::Punctuated;
@@ -178,6 +178,9 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Result<
         }
     }
 
+    let ident = Ident::new(repr.as_ref(), Span::call_site());
+    let repr_type = Type::Ident(ResolvableName::new(ident));
+
     Ok(Api::Enum(Enum {
         doc,
         enum_token,
@@ -185,6 +188,7 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Result<
         brace_token,
         variants,
         repr,
+        repr_type,
     }))
 }
 
diff --git a/syntax/types.rs b/syntax/types.rs
index 90a8221fc..92c9a75ab 100644
--- a/syntax/types.rs
+++ b/syntax/types.rs
@@ -94,6 +94,7 @@ impl<'a> Types<'a> {
                     add_resolution(&strct.name);
                 }
                 Api::Enum(enm) => {
+                    all.insert(&enm.repr_type);
                     let ident = &enm.name.rust;
                     if !type_names.insert(ident)
                         && (!cxx.contains(ident)


Test patch: