1use proc_macro2::{Span, TokenStream};
2use quote::{quote_spanned, ToTokens};
3
4pub enum Deprecation {
5 PyClassTextSignature,
6 PyMethodsNewDeprecatedForm,
7}
8
9impl Deprecation {
10 fn ident(&self, span: Span) -> syn::Ident {
11 let string: &str = match self {
12 Deprecation::PyClassTextSignature => "PYCLASS_TEXT_SIGNATURE",
13 Deprecation::PyMethodsNewDeprecatedForm => "PYMETHODS_NEW_DEPRECATED_FORM",
14 };
15 syn::Ident::new(string, span)
16 }
17}
18
19#[derive(Default)]
20pub struct Deprecations(Vec<(Deprecation, Span)>);
21
22impl Deprecations {
23 pub fn new() -> Self {
24 Deprecations(Vec::new())
25 }
26
27 pub fn push(&mut self, deprecation: Deprecation, span: Span) {
28 self.0.push((deprecation, span))
29 }
30}
31
32impl ToTokens for Deprecations {
33 fn to_tokens(&self, tokens: &mut TokenStream) {
34 for (deprecation: &Deprecation, span: &Span) in &self.0 {
35 let ident: Ident = deprecation.ident(*span);
36 quote_spannedTokenStream!(
37 *span =>
38 #[allow(clippy::let_unit_value)]
39 {
40 let _ = _pyo3::impl_::deprecations::#ident;
41 }
42 )
43 .to_tokens(tokens)
44 }
45 }
46}
47