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 trait IsNotImplemented { 25 fn assert_not_implemented() {} 26 } 27 impl<T: $marker> IsNotImplemented for T {} 28 29 // Implemented for the type being tested. 30 trait IsImplemented { 31 fn assert_not_implemented() {} 32 } 33 impl IsImplemented for $ty {} 34 35 // If $ty does not implement $marker, there is no ambiguity 36 // in the following trait method call. 37 <$ty>::assert_not_implemented(); 38 } 39 )+ 40 } 41 }; 42 } 43 44 assert_impl!(Delimiter is Send and Sync); 45 assert_impl!(Spacing is Send and Sync); 46 47 assert_impl!(Group is not Send or Sync); 48 assert_impl!(Ident is not Send or Sync); 49 assert_impl!(LexError is not Send or Sync); 50 assert_impl!(Literal is not Send or Sync); 51 assert_impl!(Punct is not Send or Sync); 52 assert_impl!(Span is not Send or Sync); 53 assert_impl!(TokenStream is not Send or Sync); 54 assert_impl!(TokenTree is not Send or Sync); 55 56 #[cfg(procmacro2_semver_exempt)] 57 mod semver_exempt { 58 use proc_macro2::{LineColumn, SourceFile}; 59 60 assert_impl!(LineColumn is Send and Sync); 61 62 assert_impl!(SourceFile is not Send or Sync); 63 } 64 65 #[cfg(not(no_libprocmacro_unwind_safe))] 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