mirror of
https://github.com/typst/typst
synced 2025-07-27 14:27:56 +08:00
Add support for until
to the deprecated macro
This allows easily annotating the `until` version in impl blocks using the `#[scope]` macro.
This commit is contained in:
parent
e6ac31e92c
commit
44c573d1a0
@ -1,7 +1,8 @@
|
||||
use heck::ToKebabCase;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{Result, parse_quote};
|
||||
use syn::punctuated::Punctuated;
|
||||
use syn::{MetaNameValue, Result, Token, parse_quote};
|
||||
|
||||
use crate::util::{BareType, foundations};
|
||||
|
||||
@ -52,15 +53,33 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result<TokenStream> {
|
||||
_ => bail!(child, "unexpected item in scope"),
|
||||
};
|
||||
|
||||
if let Some(message) = attrs.iter().find_map(|attr| match &attr.meta {
|
||||
if let Some(attr) = attrs.iter().find(|attr| attr.path().is_ident("deprecated")) {
|
||||
match &attr.meta {
|
||||
syn::Meta::NameValue(pair) if pair.path.is_ident("deprecated") => {
|
||||
Some(&pair.value)
|
||||
let message = &pair.value;
|
||||
def = quote! { #def.deprecated(#message) }
|
||||
}
|
||||
_ => None,
|
||||
syn::Meta::List(list) if list.path.is_ident("deprecated") => {
|
||||
let args = list.parse_args_with(
|
||||
Punctuated::<MetaNameValue, Token![,]>::parse_separated_nonempty,
|
||||
)?;
|
||||
|
||||
if let Some(message) = args.iter().find_map(|pair| {
|
||||
pair.path.is_ident("message").then_some(&pair.value)
|
||||
}) {
|
||||
def = quote! { #def.deprecated(#message) }
|
||||
}
|
||||
|
||||
if let Some(version) = args.iter().find_map(|pair| {
|
||||
pair.path.is_ident("until").then_some(&pair.value)
|
||||
}) {
|
||||
def = quote! { #def.deprecated_until(#version) }
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
definitions.push(def);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user