From 44c573d1a08ec93f854fcecfe09d6a24a840b64c Mon Sep 17 00:00:00 2001 From: tinger Date: Wed, 16 Jul 2025 11:53:46 +0200 Subject: [PATCH] Add support for `until` to the deprecated macro This allows easily annotating the `until` version in impl blocks using the `#[scope]` macro. --- crates/typst-macros/src/scope.rs | 33 +++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/crates/typst-macros/src/scope.rs b/crates/typst-macros/src/scope.rs index 4df4f2487..ece5bbf3b 100644 --- a/crates/typst-macros/src/scope.rs +++ b/crates/typst-macros/src/scope.rs @@ -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,13 +53,31 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result { _ => bail!(child, "unexpected item in scope"), }; - if let Some(message) = attrs.iter().find_map(|attr| match &attr.meta { - syn::Meta::NameValue(pair) if pair.path.is_ident("deprecated") => { - Some(&pair.value) + 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") => { + let message = &pair.value; + def = quote! { #def.deprecated(#message) } + } + syn::Meta::List(list) if list.path.is_ident("deprecated") => { + let args = list.parse_args_with( + Punctuated::::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) } + } + } + _ => {} } - _ => None, - }) { - def = quote! { #def.deprecated(#message) } } definitions.push(def);