Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,7 +31,7 @@ fn expand_derive_arbitrary(input: syn::DeriveInput) -> Result<TokenStream> {

// 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(),
);

Expand Down
18 changes: 18 additions & 0 deletions tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ fn struct_with_named_fields() {
assert_eq!((3, Some(3)), <Rgb as Arbitrary>::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)), <r#struct as Arbitrary>::size_hint(0));
}

#[derive(Copy, Clone, Debug, Arbitrary)]
struct MyTupleStruct(u8, bool);

Expand Down
Loading