diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 9783e1b..e198c76 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -2,7 +2,7 @@ extern crate proc_macro; use proc_macro2::{Span, TokenStream}; use quote::quote; -use syn::*; +use syn::{ext::IdentExt as _, *}; mod container_attributes; mod field_attributes; @@ -31,7 +31,7 @@ fn expand_derive_arbitrary(input: syn::DeriveInput) -> Result { // This won't be used if `needs_recursive_count` ends up false. let recursive_count = syn::Ident::new( - &format!("RECURSIVE_COUNT_{}", input.ident), + &format!("RECURSIVE_COUNT_{}", input.ident.unraw()), Span::call_site(), ); diff --git a/tests/derive.rs b/tests/derive.rs index c45cc24..b370658 100644 --- a/tests/derive.rs +++ b/tests/derive.rs @@ -30,6 +30,24 @@ fn struct_with_named_fields() { assert_eq!((3, Some(3)), ::size_hint(0)); } +#[derive(Copy, Clone, Debug, Eq, PartialEq, Arbitrary)] +#[allow(non_camel_case_types)] +struct r#struct { + pub r#fn: u8, + pub r#struct: u8, + pub r#let: u8, +} + +#[test] +fn struct_with_raw_named_fields() { + let r#struct: r#struct = arbitrary_from(&[4, 5, 6]); + assert_eq!(r#struct.r#fn, 4); + assert_eq!(r#struct.r#struct, 5); + assert_eq!(r#struct.r#let, 6); + + assert_eq!((3, Some(3)), ::size_hint(0)); +} + #[derive(Copy, Clone, Debug, Arbitrary)] struct MyTupleStruct(u8, bool);