5 use syn
::{Data, DeriveInput}
;
13 snapshot
!(input
as DeriveInput
, @r
###"
29 #[derive(Debug, Clone)]
32 pub attrs
: Vec
<Attribute
>
36 snapshot
!(input
as DeriveInput
, @r
###"
49 tokens: TokenStream(`( Debug , Clone )`),
52 vis: Visibility::Public,
56 fields: Fields::Named {
59 vis: Visibility::Public,
74 vis: Visibility::Public,
82 arguments: PathArguments::AngleBracketed {
107 snapshot
!(input
.attrs
[0].parse_meta().unwrap(), @r
###"
142 union MaybeUninit
<T
> {
148 snapshot
!(input
as DeriveInput
, @r
###"
151 ident: "MaybeUninit",
162 fields: FieldsNamed {
166 ident: Some("uninit"),
172 ident: Some("value"),
193 #[cfg(feature = "full")]
196 /// See the std::result module documentation for details.
198 pub enum Result
<T
, E
> {
203 // Smuggling data into a proc_macro_derive,
204 // in the style of https://github.com/dtolnay/proc-macro-hack
205 ProcMacroHack
= (0, "data").0
209 snapshot
!(input
as DeriveInput
, @r
###"
222 tokens: TokenStream(`= r" See the std::result module documentation for details."`),
234 tokens: TokenStream(``),
237 vis: Visibility::Public,
255 fields: Fields::Unnamed {
275 fields: Fields::Unnamed {
296 discriminant: Some(Expr::Lit {
301 ident: "ProcMacroHack",
303 discriminant: Some(Expr::Field {
314 member: Unnamed(Index {
324 let meta_items
: Vec
<_
> = input
327 .map(|attr
| attr
.parse_meta().unwrap())
330 snapshot
!(meta_items
, @r
###"
341 lit: " See the std::result module documentation for details.",
356 fn test_attr_with_path() {
358 #[::attr_args::identity
359 fn main() { assert_eq!(foo(), "Hello, world!"); }
]
363 snapshot
!(input
as DeriveInput
, @r
###"
381 tokens: TokenStream(`fn main ( ) { assert_eq ! ( foo ( ) , "Hello, world!" ) ; }`),
394 assert
!(input
.attrs
[0].parse_meta().is_err());
398 fn test_attr_with_non_mod_style_path() {
404 snapshot
!(input
as DeriveInput
, @r
###"
417 tokens: TokenStream(`< T >`),
430 assert
!(input
.attrs
[0].parse_meta().is_err());
434 fn test_attr_with_mod_style_path_with_self() {
440 snapshot
!(input
as DeriveInput
, @r
###"
457 tokens: TokenStream(``),
470 snapshot
!(input
.attrs
[0].parse_meta().unwrap(), @r
###"
487 fn test_pub_restricted() {
488 // Taken from tests/rust/src/test/ui/resolve/auxiliary/privacy-struct-ctor.rs
490 pub(in m
) struct Z(pub(in m
::n
) u8);
493 snapshot
!(input
as DeriveInput
, @r
###"
495 vis: Visibility::Restricted {
509 fields: Fields::Unnamed {
512 vis: Visibility::Restricted {
547 fn test_vis_crate() {
552 snapshot
!(input
as DeriveInput
, @r
###"
554 vis: Visibility::Crate,
566 fn test_pub_restricted_crate() {
571 snapshot
!(input
as DeriveInput
, @r
###"
573 vis: Visibility::Restricted {
594 fn test_pub_restricted_super() {
599 snapshot
!(input
as DeriveInput
, @r
###"
601 vis: Visibility::Restricted {
622 fn test_pub_restricted_in_super() {
624 pub(in super) struct S
;
627 snapshot
!(input
as DeriveInput
, @r
###"
629 vis: Visibility::Restricted {
651 fn test_fields_on_unit_struct() {
656 snapshot
!(input
as DeriveInput
, @r
###"
668 let data
= match input
.data
{
669 Data
::Struct(data
) => data
,
670 _
=> panic
!("expected a struct"),
673 assert_eq
!(0, data
.fields
.iter().count());
677 fn test_fields_on_named_struct() {
685 snapshot
!(input
as DeriveInput
, @r
###"
691 fields: Fields::Named {
709 vis: Visibility::Public,
729 let data
= match input
.data
{
730 Data
::Struct(data
) => data
,
731 _
=> panic
!("expected a struct"),
734 snapshot
!(data
.fields
.into_iter().collect
::<Vec
<_
>>(), @r
###"
752 vis: Visibility::Public,
771 fn test_fields_on_tuple_struct() {
773 struct S(i32, pub String
);
776 snapshot
!(input
as DeriveInput
, @r
###"
782 fields: Fields::Unnamed {
798 vis: Visibility::Public,
817 let data
= match input
.data
{
818 Data
::Struct(data
) => data
,
819 _
=> panic
!("expected a struct"),
822 snapshot
!(data
.fields
.iter().collect
::<Vec
<_
>>(), @r
###"
838 vis: Visibility::Public,
855 fn test_ambiguous_crate() {
857 // The field type is `(crate::X)` not `crate (::X)`.
861 snapshot
!(input
as DeriveInput
, @r
###"
867 fields: Fields::Unnamed {