Debian Codegraph @

.cargo/vendor/proc-macro2/tests/marker.rs

raw
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;
60
61 assert_impl!(LineColumn is Send and Sync);
62 }
63
64 mod unwind_safe {
65 #[cfg(procmacro2_semver_exempt)]
66 use proc_macro2::LineColumn;
67 use proc_macro2::{
68 Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
69 };
70 use std::panic::{RefUnwindSafe, UnwindSafe};
71
72 macro_rules! assert_unwind_safe {
73 ($($types:ident)*) => {
74 $(
75 assert_impl!($types is UnwindSafe and RefUnwindSafe);
76 )*
77 };
78 }
79
80 assert_unwind_safe! {
81 Delimiter
82 Group
83 Ident
84 LexError
85 Literal
86 Punct
87 Spacing
88 Span
89 TokenStream
90 TokenTree
91 }
92
93 #[cfg(procmacro2_semver_exempt)]
94 assert_unwind_safe! {
95 LineColumn
96 }
97 }