• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(clippy::extra_unused_type_parameters)]
2 
3 use proc_macro2::{
4     Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
5 };
6 
7 macro_rules! assert_impl {
8     ($ty:ident is $($marker:ident) and +) => {
9         #[test]
10         #[allow(non_snake_case)]
11         fn $ty() {
12             fn assert_implemented<T: $($marker +)+>() {}
13             assert_implemented::<$ty>();
14         }
15     };
16 
17     ($ty:ident is not $($marker:ident) or +) => {
18         #[test]
19         #[allow(non_snake_case)]
20         fn $ty() {
21             $(
22                 {
23                     // Implemented for types that implement $marker.
24                     #[allow(dead_code)]
25                     trait IsNotImplemented {
26                         fn assert_not_implemented() {}
27                     }
28                     impl<T: $marker> IsNotImplemented for T {}
29 
30                     // Implemented for the type being tested.
31                     trait IsImplemented {
32                         fn assert_not_implemented() {}
33                     }
34                     impl IsImplemented for $ty {}
35 
36                     // If $ty does not implement $marker, there is no ambiguity
37                     // in the following trait method call.
38                     <$ty>::assert_not_implemented();
39                 }
40             )+
41         }
42     };
43 }
44 
45 assert_impl!(Delimiter is Send and Sync);
46 assert_impl!(Spacing is Send and Sync);
47 
48 assert_impl!(Group is not Send or Sync);
49 assert_impl!(Ident is not Send or Sync);
50 assert_impl!(LexError is not Send or Sync);
51 assert_impl!(Literal is not Send or Sync);
52 assert_impl!(Punct is not Send or Sync);
53 assert_impl!(Span is not Send or Sync);
54 assert_impl!(TokenStream is not Send or Sync);
55 assert_impl!(TokenTree is not Send or Sync);
56 
57 #[cfg(procmacro2_semver_exempt)]
58 mod semver_exempt {
59     use proc_macro2::{LineColumn, SourceFile};
60 
61     assert_impl!(LineColumn is Send and Sync);
62 
63     assert_impl!(SourceFile is not Send or Sync);
64 }
65 
66 mod unwind_safe {
67     use proc_macro2::{
68         Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
69     };
70     #[cfg(procmacro2_semver_exempt)]
71     use proc_macro2::{LineColumn, SourceFile};
72     use std::panic::{RefUnwindSafe, UnwindSafe};
73 
74     macro_rules! assert_unwind_safe {
75         ($($types:ident)*) => {
76             $(
77                 assert_impl!($types is UnwindSafe and RefUnwindSafe);
78             )*
79         };
80     }
81 
82     assert_unwind_safe! {
83         Delimiter
84         Group
85         Ident
86         LexError
87         Literal
88         Punct
89         Spacing
90         Span
91         TokenStream
92         TokenTree
93     }
94 
95     #[cfg(procmacro2_semver_exempt)]
96     assert_unwind_safe! {
97         LineColumn
98         SourceFile
99     }
100 }
101