Repository: facet-rs/facet (Rust)

Issue:
Facet derive on enum with repr creates a compilation error
Hi,

This is somewhat related to #378 that got fixed recently (thanks!)

With facet 0.25.1, deriving the Facet trait on an enum with a "typed" repr, because it seems to assume the discriminant is always i64.

For example,

```rust
macro_rules! test_macro_u16 {
    () => {
        242u16
    };
}

const CONST_VALUE_U16: u16 = 142;

#[repr(u16)]
#[derive(facet::Facet)]
enum TestEnum {
    Value1 = 42u16,
    Value2 = CONST_VALUE_U16,
    Value3 = test_macro_u16!(),
}
```` 

fails to compile with:

```
error[E0308]: mismatched types
   --> facet-enum-repr/examples/test-facet.rs:12:14
    |
10  | #[derive(facet::Facet)]
    |          ------------ arguments to this method are incorrect
11  | enum TestEnum {
12  |     Value1 = 42u16,
    |              ^^^^^ expected `i64`, found `u16`
    |
note: method defined here
   --> /var/home/max/.local/share/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/facet-core-0.25.1/src/types/ty/enum_.rs:137:18
    |
137 |     pub const fn discriminant(mut self, discriminant: i64) -> Self {
    |                  ^^^^^^^^^^^^
help: change the type of the numeric literal from `u16` to `i64`
    |
12  -     Value1 = 42u16,
12  +     Value1 = 42i64,
    |

error[E0308]: mismatched types
   --> facet-enum-repr/examples/test-facet.rs:13:14
    |
10  | #[derive(facet::Facet)]
    |          ------------ arguments to this method are incorrect
...
13  |     Value2 = CONST_VALUE_U16,
    |              ^^^^^^^^^^^^^^^ expected `i64`, found `u16`
    |
note: method defined here
   --> /var/home/max/.local/share/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/facet-core-0.25.1/src/types/ty/enum_.rs:137:18
    |
137 |     pub const fn discriminant(mut self, discriminant: i64) -> Self {
    |                  ^^^^^^^^^^^^

error[E0308]: mismatched types
   --> facet-enum-repr/examples/test-facet.rs:3:9
    |
3   |         242u16
    |         ^^^^^^ expected `i64`, found `u16`
...
10  | #[derive(facet::Facet)]
    |          ------------ arguments to this method are incorrect
...
14  |     Value3 = test_macro_u16!(),
    |              ----------------- in this macro invocation
    |
note: method defined here
   --> /var/home/max/.local/share/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/facet-core-0.25.1/src/types/ty/enum_.rs:137:18
    |
137 |     pub const fn discriminant(mut self, discriminant: i64) -> Self {
    |                  ^^^^^^^^^^^^
    = note: this error originates in the macro `test_macro_u16` (in Nightly builds, run with -Z macro-backtrace for more info)
help: change the type of the numeric literal from `u16` to `i64`
    |
3   -         242u16
3   +         242i64
    |

```


Discussion:
Got bitten by this with `facet = "0.27.1"`.
To clarify, the issue may only happen with user-specified discriminants on non-i64 enum `#[repr]` that are not integer literals. That is:

```rust
const ZERO_U8: u8 = 0;
const ZERO_i64: i64 = 0;

// Fine: integer literals
#[derive(Facet)]
#[repr(u8)]
enum IntLiteralNonI64Repr {
  A = 0,
  B = 7,
}

// Also fine: `#[repr(i64)]
#[derive(Facet)]
#[repr(i64)]
enum ExprI64Repr {
  A = ZERO_I64,
  B = ZERO_I64 + 7,
}

// Also fine: No user-specified discriminants
#[derive(Facet)]
#[repr(u8)]
enum NoDiscrimNonI64Repr {
  A,
  B,
}

// *Not* fine: at least one discriminant causes the issue
#[derive(Facet)]
#[repr(u8)]
enum ExprNonI64Repr {
  A = ZERO_U8,
  B,
}

// *Not* fine: rustc expects a `u8` discriminant because of `#[repr(u8)]`
#[derive(Facet)]
#[repr(u8)]
enum ExprI64MismatchRepr {
  A = ZERO_U8 as i64,
  B,
}
```

The function that does not typecheck is [`VariantBuilder::discriminant`](https://github.com/facet-rs/facet/blob/main/facet-core/src/types/ty/enum_.rs#L137), which -- I think -- can't really be made generic without losing its `const`ness.
I'm wondering if could this be solved simply by casting the expression emitted by the derive macro `as i64` ? I.e. [here](https://github.com/facet-rs/facet/blob/main/facet-derive-emit/src/process_enum.rs#L410):

```diff
                match &pv.kind {
                    PVariantKind::Unit => {
                        exprs.push(quote! {
                            ::facet::Variant::builder()
                                #variant_attrs_tokens
-                               .discriminant(#discriminant_ts)
+                               .discriminant((#discriminant_ts) as i64)
                                .data(::facet::StructType::builder().repr(::facet::Repr::c()).unit().build())
                                #maybe_doc
                                .build()
                        });
                    }
                    PVariantKind::Tuple { fields } => {
@@ @@
                            let fields: &'static [::facet::Field] = &const {[
                                #(#field_defs),*
                            ]};
                            ::facet::Variant::builder()
                                #variant_attrs_tokens
-                               .discriminant(#discriminant_ts)
+                               .discriminant((#discriminant_ts) as i64)
                                .data(::facet::StructType::builder().repr(::facet::Repr::c()).tuple().fields(fields).build())
                                #maybe_doc
                                .build()
                        }});
                    }
                    PVariantKind::Struct { fields } => {
@@ @@
                        exprs.push(quote! {{
                            let fields: &'static [::facet::Field] = &const {[
                                #(#field_defs),*
                            ]};
                            ::facet::Variant::builder()
                                #variant_attrs_tokens
-                               .discriminant(#discriminant_ts)
+                               .discriminant((#discriminant_ts) as i64)
                                .data(::facet::StructType::builder().repr(::facet::Repr::c()).struct_().fields(fields).build())
                                #maybe_doc
                                .build()
                        }});
```
It would allow subtle issues that come with `as`-casts but I'd prefer checking against those if nothing else can be done rather than the current behavior.
I have never dealt with derive macros so I'm don't really know if that has broader implications, but if it's that simple I can open a PR.
> I have never dealt with derive macros so I'm don't really know if that has broader implications, but if it's that simple I can open a PR.

@Austreelis  Sounds like a good idea to me!

I've edited the proc macro in this file before and happy to try to answer any questions :-) If not a solution, even a reproducible test case (i.e. marked `#[test]` in the test suite) that isolates the problem would move it forwards.



Patch:
diff --git a/facet-derive-emit/src/process_enum.rs b/facet-derive-emit/src/process_enum.rs
index 5775dc3ad..361e8cfb4 100644
--- a/facet-derive-emit/src/process_enum.rs
+++ b/facet-derive-emit/src/process_enum.rs
@@ -225,7 +225,7 @@ pub(crate) fn process_enum(parsed: Enum) -> TokenStream {
                         exprs.push(quote! {
                             ::facet::Variant::builder()
                                 #variant_attrs_tokens
-                                .discriminant(#discriminant_ts)
+                                .discriminant(#discriminant_ts as i64)
                                 .data(::facet::StructType::builder().repr(::facet::Repr::c()).unit().build())
                                 #maybe_doc
                                 .build()
@@ -271,7 +271,7 @@ pub(crate) fn process_enum(parsed: Enum) -> TokenStream {
                             ]};
                             ::facet::Variant::builder()
                                 #variant_attrs_tokens
-                                .discriminant(#discriminant_ts)
+                                .discriminant(#discriminant_ts as i64)
                                 .data(::facet::StructType::builder().repr(::facet::Repr::c()).tuple().fields(fields).build())
                                 #maybe_doc
                                 .build()
@@ -327,7 +327,7 @@ pub(crate) fn process_enum(parsed: Enum) -> TokenStream {
                             ]};
                             ::facet::Variant::builder()
                                 #variant_attrs_tokens
-                                .discriminant(#discriminant_ts)
+                                .discriminant(#discriminant_ts as i64)
                                 .data(::facet::StructType::builder().repr(::facet::Repr::c()).struct_().fields(fields).build())
                                 #maybe_doc
                                 .build()
@@ -415,7 +415,7 @@ pub(crate) fn process_enum(parsed: Enum) -> TokenStream {
                         exprs.push(quote! {
                             ::facet::Variant::builder()
                                 #variant_attrs_tokens
-                                .discriminant(#discriminant_ts)
+                                .discriminant(#discriminant_ts as i64)
                                 .data(::facet::StructType::builder().repr(::facet::Repr::c()).unit().build())
                                 #maybe_doc
                                 .build()
@@ -470,7 +470,7 @@ pub(crate) fn process_enum(parsed: Enum) -> TokenStream {
                             ]};
                             ::facet::Variant::builder()
                                 #variant_attrs_tokens
-                                .discriminant(#discriminant_ts)
+                                .discriminant(#discriminant_ts as i64)
                                 .data(::facet::StructType::builder().repr(::facet::Repr::c()).tuple().fields(fields).build())
                                 #maybe_doc
                                 .build()
@@ -527,7 +527,7 @@ pub(crate) fn process_enum(parsed: Enum) -> TokenStream {
                             ]};
                             ::facet::Variant::builder()
                                 #variant_attrs_tokens
-                                .discriminant(#discriminant_ts)
+                                .discriminant(#discriminant_ts as i64)
                                 .data(::facet::StructType::builder().repr(::facet::Repr::c()).struct_().fields(fields).build())
                                 #maybe_doc
                                 .build()
diff --git a/facet/src/sample_generated_code.rs b/facet/src/sample_generated_code.rs
index e7a60d4f4..f906e93c0 100644
--- a/facet/src/sample_generated_code.rs
+++ b/facet/src/sample_generated_code.rs
@@ -1399,7 +1399,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
             [
                 crate::Variant::builder()
                     .name("UnitVariant")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         crate::StructType::builder()
                             .repr(crate::Repr::c())
@@ -1421,7 +1421,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
                     };
                     crate::Variant::builder()
                         .name("TupleVariantSimple")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -1467,7 +1467,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
                     };
                     crate::Variant::builder()
                         .name("TupleVariantMulti")
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -1508,7 +1508,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
                     };
                     crate::Variant::builder()
                         .name("StructVariant")
-                        .discriminant(3i64)
+                        .discriminant(3i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -1532,7 +1532,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
                     };
                     crate::Variant::builder()
                         .name("SensitiveTupleVariant")
-                        .discriminant(4i64)
+                        .discriminant(4i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -1566,7 +1566,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
                     };
                     crate::Variant::builder()
                         .name("StructVariantWithSensitiveField")
-                        .discriminant(5i64)
+                        .discriminant(5i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -1588,7 +1588,9 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
                                                                                     }).build()
                         }]
                     };
-                    crate::Variant::builder().name("ArbitraryVariant").attributes(&[crate::VariantAttribute::Arbitrary("arbitrary")]).discriminant(6i64).data(crate::StructType::builder().repr(crate::Repr::c()).tuple().fields(fields).build()).doc(&[" A variant marked as arbitrary, potentially skipped during processing."]).build()
+                    crate::Variant::builder().name("ArbitraryVariant").attributes(&[crate::VariantAttribute::Arbitrary("arbitrary")]).discriminant(6i64
+                                                                    as
+                                                                    i64).data(crate::StructType::builder().repr(crate::Repr::c()).tuple().fields(fields).build()).doc(&[" A variant marked as arbitrary, potentially skipped during processing."]).build()
                 },
                 {
                     let fields: &'static [crate::Field] = &const {
@@ -1603,7 +1605,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for KitchenSinkEnum {
                     };
                     crate::Variant::builder()
                         .name("NestedEnumVariant")
-                        .discriminant(7i64)
+                        .discriminant(7i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -2048,7 +2050,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for SubEnum {
             [
                 crate::Variant::builder()
                     .name("OptionA")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         crate::StructType::builder()
                             .repr(crate::Repr::c())
@@ -2070,7 +2072,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for SubEnum {
                     };
                     crate::Variant::builder()
                         .name("OptionB")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -2094,7 +2096,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for SubEnum {
                     };
                     crate::Variant::builder()
                         .name("SensitiveOption")
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())
@@ -2119,7 +2121,7 @@ unsafe impl<'__facet> crate::Facet<'__facet> for SubEnum {
                     crate::Variant::builder()
                         .name("ArbitraryOption")
                         .attributes(&[crate::VariantAttribute::Arbitrary("arbitrary")])
-                        .discriminant(3i64)
+                        .discriminant(3i64 as i64)
                         .data(
                             crate::StructType::builder()
                                 .repr(crate::Repr::c())


Test patch:
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__array_field_in_enum.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__array_field_in_enum.snap
index ecc3234d3..e6fc9564d 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__array_field_in_enum.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__array_field_in_enum.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 569
 expression: "expand(r#\"\n        /// Network packet types\n        #[derive(Facet)]\n        #[repr(u8)]\n        pub enum Packet {\n            /// Array of bytes representing the header\n            Header([u8; 4]),\n            Payload(Vec<u8>), // Add another variant for completeness\n        }\n        \"#)"
 ---
 #[used]
@@ -47,7 +46,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Packet {
                     };
                     ::facet::Variant::builder()
                         .name("Header")
-                        .discriminant(0i64)
+                        .discriminant(0i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -77,7 +76,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Packet {
                     };
                     ::facet::Variant::builder()
                         .name("Payload")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_doc_comment.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_doc_comment.snap
index 3b2ad4d8e..e50db9fcf 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_doc_comment.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_doc_comment.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 263
 expression: "expand(r#\"\n        /// This is an enum\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum MyEnum {\n            #[allow(dead_code)]\n            A,\n            #[allow(dead_code)]\n            B,\n        }\n        \"#)"
 ---
 #[used]
@@ -16,7 +15,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for MyEnum {
             [
                 ::facet::Variant::builder()
                     .name("A")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -26,7 +25,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for MyEnum {
                     .build(),
                 ::facet::Variant::builder()
                     .name("B")
-                    .discriminant(1i64)
+                    .discriminant(1i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_generic.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_generic.snap
index 6b9f536a2..607a774e7 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_generic.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_generic.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 430
 expression: "expand(r#\"\n        #[allow(dead_code)]\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum E<'a, T: Facet<'a> + core::hash::Hash, const C: usize = 3>\n        where\n            T: Debug, // Added Debug bound\n             [u8; C]: Debug, // Added Debug bound\n        {\n            Unit,\n            Tuple(T, core::marker::PhantomData<&'a [u8; C]>),\n            Record {\n                field: T,\n                phantom: core::marker::PhantomData<&'a ()>,\n                constant_val: [u8; C],\n            },\n        }\n        \"#)"
 ---
 #[automatically_derived]
@@ -62,7 +61,7 @@ where
             [
                 ::facet::Variant::builder()
                     .name("Unit")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -111,7 +110,7 @@ where
                     };
                     ::facet::Variant::builder()
                         .name("Tuple")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -179,7 +178,7 @@ where
                     };
                     ::facet::Variant::builder()
                         .name("Record")
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_variants_with_comments.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_variants_with_comments.snap
index dfa6f9b8e..ed47eac25 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_variants_with_comments.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_variants_with_comments.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 308
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum CommentedEnum {\n            /// This is variant A\n            #[allow(dead_code)]\n            A,\n            /// This is variant B\n            /// with multiple lines\n            #[allow(dead_code)]\n            B(u32),\n            /// This is variant C\n            /// which has named fields\n            #[allow(dead_code)]\n            C {\n                /// This is field x\n                x: u32,\n                /// This is field y\n                y: String,\n            },\n        }\n        \"#)"
 ---
 #[used]
@@ -34,7 +33,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for CommentedEnum {
             [
                 ::facet::Variant::builder()
                     .name("A")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -62,7 +61,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for CommentedEnum {
                     };
                     ::facet::Variant::builder()
                         .name("B")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -110,7 +109,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for CommentedEnum {
                     };
                     ::facet::Variant::builder()
                         .name("C")
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_binary.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_binary.snap
index d0f1f8e0a..d24394a53 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_binary.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_binary.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 100
 expression: "expand(r#\"\n        #[repr(u8)]\n        #[derive(Facet)]\n        enum BitFlags {\n          None = 0b0000_0000,\n          Read = 0b0000_0001,\n          Write = 0b0000_0010,\n          Execute = 0b0000_0100,\n          All = 0b0000_0111,\n        }\n        \"#)"
 ---
 #[used]
@@ -18,7 +17,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for BitFlags {
             [
                 ::facet::Variant::builder()
                     .name("None")
-                    .discriminant(0b0000_0000)
+                    .discriminant(0b0000_0000 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -28,7 +27,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for BitFlags {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Read")
-                    .discriminant(0b0000_0001)
+                    .discriminant(0b0000_0001 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -38,7 +37,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for BitFlags {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Write")
-                    .discriminant(0b0000_0010)
+                    .discriminant(0b0000_0010 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -48,7 +47,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for BitFlags {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Execute")
-                    .discriminant(0b0000_0100)
+                    .discriminant(0b0000_0100 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -58,7 +57,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for BitFlags {
                     .build(),
                 ::facet::Variant::builder()
                     .name("All")
-                    .discriminant(0b0000_0111)
+                    .discriminant(0b0000_0111 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_decimal.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_decimal.snap
index 4dac72216..b7f972ab2 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_decimal.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_decimal.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 66
 expression: "expand(r#\"\n        #[repr(u8)]\n        #[derive(Facet)]\n        enum Test {\n          Red,\n          Blue = 7,\n          Green,\n          Yellow = 10,\n        }\n        \"#)"
 ---
 #[used]
@@ -16,7 +15,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Test {
             [
                 ::facet::Variant::builder()
                     .name("Red")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -26,7 +25,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Test {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Blue")
-                    .discriminant(7)
+                    .discriminant(7 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -36,7 +35,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Test {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Green")
-                    .discriminant(7 + 1i64)
+                    .discriminant(7 + 1i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -46,7 +45,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Test {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Yellow")
-                    .discriminant(10)
+                    .discriminant(10 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_hexadecimal.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_hexadecimal.snap
index 0970cf117..71d143c13 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_hexadecimal.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_hexadecimal.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 82
 expression: "expand(r#\"\n        #[repr(u16)]\n        #[derive(Facet)]\n        enum Color {\n          Red      = 0x01,\n          Blue     = 0x7F,\n          Green    = 0x80,\n          Yellow   = 0x10,\n          Magenta  = 0xfeed,\n          Cyan     = 0xBEEF,\n        }\n        \"#)"
 ---
 #[used]
@@ -16,7 +15,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Color {
             [
                 ::facet::Variant::builder()
                     .name("Red")
-                    .discriminant(0x01)
+                    .discriminant(0x01 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -26,7 +25,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Color {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Blue")
-                    .discriminant(0x7F)
+                    .discriminant(0x7F as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -36,7 +35,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Color {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Green")
-                    .discriminant(0x80)
+                    .discriminant(0x80 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -46,7 +45,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Color {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Yellow")
-                    .discriminant(0x10)
+                    .discriminant(0x10 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -56,7 +55,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Color {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Magenta")
-                    .discriminant(0xfeed)
+                    .discriminant(0xfeed as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -66,7 +65,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Color {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Cyan")
-                    .discriminant(0xBEEF)
+                    .discriminant(0xBEEF as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_mixed_notations.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_mixed_notations.snap
index cd5b3ca7a..11c1427b6 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_mixed_notations.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_discriminants_mixed_notations.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 117
 expression: "expand(r#\"\n        #[repr(u32)]\n        #[derive(Facet)]\n        enum Status {\n            Ok = 1,\n            Warn = 0xA,\n            Error = 0b1111,\n            Timeout = 0o77,\n        }\n        \"#)"
 ---
 #[used]
@@ -16,7 +15,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Status {
             [
                 ::facet::Variant::builder()
                     .name("Ok")
-                    .discriminant(1)
+                    .discriminant(1 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -26,7 +25,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Status {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Warn")
-                    .discriminant(0xA)
+                    .discriminant(0xA as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -36,7 +35,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Status {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Error")
-                    .discriminant(0b1111)
+                    .discriminant(0b1111 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -46,7 +45,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for Status {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Timeout")
-                    .discriminant(0o77)
+                    .discriminant(0o77 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_facet_attributes.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_facet_attributes.snap
index ec317a03d..f5e91e875 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_facet_attributes.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_facet_attributes.snap
@@ -44,7 +44,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithAttributes {
                         ::facet::VariantAttribute::Arbitrary("name = \"FirstVariant\""),
                         ::facet::VariantAttribute::Arbitrary("discriminant = 10"),
                     ])
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -61,7 +61,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithAttributes {
                     ::facet::Variant::builder()
                         .name("InternalVariant")
                         .attributes(&[::facet::VariantAttribute::Arbitrary("skip")])
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -82,7 +82,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithAttributes {
                         .attributes(&[::facet::VariantAttribute::Arbitrary(
                             "deprecated = \"Use VariantD instead\"",
                         )])
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -100,7 +100,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithAttributes {
                     };
                     ::facet::Variant::builder()
                         .name("VariantD")
-                        .discriminant(3i64)
+                        .discriminant(3i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_macro_discriminants.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_macro_discriminants.snap
index 1492f278d..36f8edd7c 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_macro_discriminants.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_macro_discriminants.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 1083
 expression: "expand(r#\"\n        #[repr(u16)]\n        #[derive(Facet)]\n        enum TestEnum {\n            Value1 = test_macro!(1, 2),\n            Value2 = test_macro!(3, 4),\n        }\n        \"#)"
 ---
 #[used]
@@ -18,7 +17,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for TestEnum {
             [
                 ::facet::Variant::builder()
                     .name("Value1")
-                    .discriminant(test_macro!(1, 2))
+                    .discriminant(test_macro!(1, 2) as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -28,7 +27,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for TestEnum {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Value2")
-                    .discriminant(test_macro!(3, 4))
+                    .discriminant(test_macro!(3, 4) as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_multiple_attributes_per_variant.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_multiple_attributes_per_variant.snap
index 55524ebb0..452f50aa7 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_multiple_attributes_per_variant.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_multiple_attributes_per_variant.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 1037
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum ConfigValue {\n            #[facet(rename = \"TextValue\")]\n            Text(String),\n            #[facet(rename = \"NumberValue\")]\n            Number {\n                #[facet(rename = \"numValue\")]\n                value: f64,\n                #[facet(rename = \"unitName\", sensitive)]\n                unit: String,\n            },\n            #[facet(rename = \"BoolValue\")]\n            Boolean(bool),\n        }\n        \"#)"
 ---
 #[used]
@@ -58,7 +57,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for ConfigValue {
                     };
                     ::facet::Variant::builder()
                         .name("TextValue")
-                        .discriminant(0i64)
+                        .discriminant(0i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -104,7 +103,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for ConfigValue {
                     };
                     ::facet::Variant::builder()
                         .name("NumberValue")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -133,7 +132,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for ConfigValue {
                     };
                     ::facet::Variant::builder()
                         .name("BoolValue")
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_one_level.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_one_level.snap
index 79f93978d..9aca9d47c 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_one_level.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_one_level.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 742
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum OneLevelNested<T> {\n            VariantA(Result<T, String>),\n            VariantB(Option<T>),\n            // Also include a unit variant to check un-nested\n            Plain,\n        }\n        \"#)"
 ---
 #[automatically_derived]
@@ -61,7 +60,7 @@ where
                     };
                     ::facet::Variant::builder()
                         .name("VariantA")
-                        .discriminant(0i64)
+                        .discriminant(0i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -94,7 +93,7 @@ where
                     };
                     ::facet::Variant::builder()
                         .name("VariantB")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -106,7 +105,7 @@ where
                 },
                 ::facet::Variant::builder()
                     .name("Plain")
-                    .discriminant(2i64)
+                    .discriminant(2i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_two_levels.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_two_levels.snap
index b472c57a1..d3889d1ea 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_two_levels.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_nested_generic_in_variant_two_levels.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 759
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum DeeplyNested<T> {\n            LevelOne(\n                Option<\n                    Result<\n                        Vec<T>,\n                        String\n                    >\n                >\n            ),\n            // Another variant to prove non-nested still works.\n            Simple(T),\n        }\n        \"#)"
 ---
 #[automatically_derived]
@@ -58,7 +57,7 @@ where
                     };
                     ::facet::Variant::builder()
                         .name("LevelOne")
-                        .discriminant(0i64)
+                        .discriminant(0i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -88,7 +87,7 @@ where
                     };
                     ::facet::Variant::builder()
                         .name("Simple")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_rename_all.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_rename_all.snap
index 707fc571a..ce2f3633b 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_rename_all.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_rename_all.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 816
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        #[facet(rename_all = \"snake_case\")]\n        enum ApiResponse {\n            OkResponse {\n                #[facet(rename = \"responseData\")]\n                data: String,\n            },\n            ErrorResponse {\n                code: u32,\n                message: String,\n            },\n        }\n        \"#)"
 ---
 #[used]
@@ -51,7 +50,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for ApiResponse {
                     };
                     ::facet::Variant::builder()
                         .name("ok_response")
-                        .discriminant(0i64)
+                        .discriminant(0i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -74,7 +73,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for ApiResponse {
                     };
                     ::facet::Variant::builder()
                         .name("error_response")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_renamed_variants_and_fields.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_renamed_variants_and_fields.snap
index d178eb6c6..441fc232e 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_renamed_variants_and_fields.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_renamed_variants_and_fields.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 994
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum ApiResponse {\n            #[facet(rename = \"Success\")]\n            Ok {\n                #[facet(rename = \"responseData\")]\n                data: String,\n            },\n            #[facet(rename = \"Error\")]\n            Err {\n                #[facet(rename = \"errorCode\")]\n                code: u32,\n                #[facet(rename = \"errorMessage\")]\n                message: String,\n            },\n        }\n        \"#)"
 ---
 #[used]
@@ -51,7 +50,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for ApiResponse {
                     };
                     ::facet::Variant::builder()
                         .name("Success")
-                        .discriminant(0i64)
+                        .discriminant(0i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -96,7 +95,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for ApiResponse {
                     };
                     ::facet::Variant::builder()
                         .name("Error")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_variants.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_variants.snap
index dfd76becb..5a0c17a66 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_variants.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__enum_with_variants.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 51
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        enum EnumWithVariants {\n            Variant1,\n            Variant2(i32),\n            Variant3 { field1: i32, field2: String },\n        }\n        \"#)"
 ---
 #[used]
@@ -35,7 +34,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithVariants {
             [
                 ::facet::Variant::builder()
                     .name("Variant1")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -62,7 +61,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithVariants {
                     };
                     ::facet::Variant::builder()
                         .name("Variant2")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -85,7 +84,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithVariants {
                     };
                     ::facet::Variant::builder()
                         .name("Variant3")
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__pub_crate_enum.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__pub_crate_enum.snap
index 158415e21..c4f869a7e 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__pub_crate_enum.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__pub_crate_enum.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 1110
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(u8)]\n        pub(crate) enum LogLevel {\n            Debug,\n            Info,\n            Warn,\n            Error,\n        }\n        \"#)"
 ---
 #[used]
@@ -18,7 +17,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for LogLevel {
             [
                 ::facet::Variant::builder()
                     .name("Debug")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -28,7 +27,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for LogLevel {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Info")
-                    .discriminant(1i64)
+                    .discriminant(1i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -38,7 +37,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for LogLevel {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Warn")
-                    .discriminant(2i64)
+                    .discriminant(2i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -48,7 +47,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for LogLevel {
                     .build(),
                 ::facet::Variant::builder()
                     .name("Error")
-                    .discriminant(3i64)
+                    .discriminant(3i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum.snap
index 527713df9..347a8d888 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 133
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(C)]\n        enum EnumWithVariants {\n            /// Comment A\n            Variant1,\n            /// Comment B\n            Variant2(i32),\n            Variant3 { field1: i32, field2: String },\n        }\n        \"#)"
 ---
 #[used]
@@ -63,7 +62,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithVariants {
             [
                 ::facet::Variant::builder()
                     .name("Variant1")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
@@ -96,7 +95,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithVariants {
                     };
                     ::facet::Variant::builder()
                         .name("Variant2")
-                        .discriminant(1i64)
+                        .discriminant(1i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
@@ -152,7 +151,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithVariants {
                     };
                     ::facet::Variant::builder()
                         .name("Variant3")
-                        .discriminant(2i64)
+                        .discriminant(2i64 as i64)
                         .data(
                             ::facet::StructType::builder()
                                 .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_empty_struct_variant.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_empty_struct_variant.snap
index 40b06f766..c1b83bed5 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_empty_struct_variant.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_empty_struct_variant.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 150
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(C)]\n        enum EnumWithEmptyStructVariant {\n            Variant1 { },\n        }\n        \"#)"
 ---
 #[used]
@@ -46,7 +45,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithEmptyStructVariant {
                 let fields: &'static [::facet::Field] = &const { [] };
                 ::facet::Variant::builder()
                     .name("Variant1")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_lifetime_field.snap b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_lifetime_field.snap
index 1dd47cac3..a9e37ab78 100644
--- a/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_lifetime_field.snap
+++ b/facet-derive-emit/tests/codegen/snapshots/r#mod__codegen__repr_c_enum_lifetime_field.snap
@@ -1,6 +1,5 @@
 ---
 source: facet-derive-emit/tests/codegen/mod.rs
-assertion_line: 163
 expression: "expand(r#\"\n        #[derive(Facet)]\n        #[repr(C)]\n        enum EnumWithLifetimeField {\n            Variant1 { field1: &'static str },\n        }\n        \"#)"
 ---
 #[used]
@@ -67,7 +66,7 @@ unsafe impl<'__facet> ::facet::Facet<'__facet> for EnumWithLifetimeField {
                 };
                 ::facet::Variant::builder()
                     .name("Variant1")
-                    .discriminant(0i64)
+                    .discriminant(0i64 as i64)
                     .data(
                         ::facet::StructType::builder()
                             .repr(::facet::Repr::c())
diff --git a/facet/tests/derive.rs b/facet/tests/derive.rs
index cb156ca43..c7ba89773 100644
--- a/facet/tests/derive.rs
+++ b/facet/tests/derive.rs
@@ -565,3 +565,23 @@ fn plain_tuple() {
         _ => panic!("Expected tuple to be a UserType::Struct"),
     }
 }
+
+#[test]
+fn test_macro_u16() {
+    macro_rules! test_macro_u16 {
+        () => {
+            242u16
+        };
+    }
+
+    const CONST_VALUE_U16: u16 = 142;
+
+    #[repr(u16)]
+    #[derive(Facet)]
+    #[allow(dead_code)]
+    enum TestEnum {
+        Value1 = 42u16,
+        Value2 = CONST_VALUE_U16,
+        Value3 = test_macro_u16!(),
+    }
+}