Skip to content

Commit 9132f5a

Browse files
authored
Merge pull request #233 from bb010g/main
Allow deriving for types that use raw identifiers.
2 parents dc22fde + 6af815c commit 9132f5a

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

derive/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate proc_macro;
22

33
use proc_macro2::{Span, TokenStream};
44
use quote::quote;
5-
use syn::*;
5+
use syn::{ext::IdentExt as _, *};
66

77
mod container_attributes;
88
mod field_attributes;
@@ -31,7 +31,7 @@ fn expand_derive_arbitrary(input: syn::DeriveInput) -> Result<TokenStream> {
3131

3232
// This won't be used if `needs_recursive_count` ends up false.
3333
let recursive_count = syn::Ident::new(
34-
&format!("RECURSIVE_COUNT_{}", input.ident),
34+
&format!("RECURSIVE_COUNT_{}", input.ident.unraw()),
3535
Span::call_site(),
3636
);
3737

tests/derive.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ fn struct_with_named_fields() {
3030
assert_eq!((3, Some(3)), <Rgb as Arbitrary>::size_hint(0));
3131
}
3232

33+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Arbitrary)]
34+
#[allow(non_camel_case_types)]
35+
struct r#struct {
36+
pub r#fn: u8,
37+
pub r#struct: u8,
38+
pub r#let: u8,
39+
}
40+
41+
#[test]
42+
fn struct_with_raw_named_fields() {
43+
let r#struct: r#struct = arbitrary_from(&[4, 5, 6]);
44+
assert_eq!(r#struct.r#fn, 4);
45+
assert_eq!(r#struct.r#struct, 5);
46+
assert_eq!(r#struct.r#let, 6);
47+
48+
assert_eq!((3, Some(3)), <r#struct as Arbitrary>::size_hint(0));
49+
}
50+
3351
#[derive(Copy, Clone, Debug, Arbitrary)]
3452
struct MyTupleStruct(u8, bool);
3553

0 commit comments

Comments
 (0)