macros: Move ensure_feature_presence check from ruma_api to request / response

This commit is contained in:
Jonas Platte 2022-11-10 11:02:28 +01:00
parent 2451f33a64
commit 7d018897b0
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
3 changed files with 13 additions and 5 deletions

View File

@ -50,8 +50,6 @@ pub struct Api {
impl Api {
pub fn expand_all(self) -> TokenStream {
let maybe_feature_error = ensure_feature_presence().map(syn::Error::to_compile_error);
let ruma_common = import_ruma_common();
let metadata = &self.metadata;
@ -73,8 +71,6 @@ impl Api {
let metadata_doc = format!("Metadata for the `{}` API endpoint.", name.value());
quote! {
#maybe_feature_error
// For some reason inlining the expression causes issues with macro parsing
const _RUMA_API_VERSION_HISTORY: #ruma_common::api::VersionHistory = #history;

View File

@ -10,6 +10,7 @@ use syn::{
use super::{
attribute::{DeriveRequestMeta, RequestMeta},
ensure_feature_presence,
util::collect_lifetime_idents,
};
use crate::util::import_ruma_common;
@ -21,12 +22,16 @@ pub fn expand_request(attr: RequestAttr, item: ItemStruct) -> TokenStream {
let ruma_common = import_ruma_common();
let ruma_macros = quote! { #ruma_common::exports::ruma_macros };
let maybe_feature_error = ensure_feature_presence().map(syn::Error::to_compile_error);
let error_ty = attr.0.first().map_or_else(
|| quote! { #ruma_common::api::error::MatrixError },
|DeriveRequestMeta::Error(ty)| quote! { #ty },
);
quote! {
#maybe_feature_error
#[derive(
Clone,
Debug,

View File

@ -9,7 +9,10 @@ use syn::{
DeriveInput, Field, Generics, Ident, ItemStruct, Lifetime, Token, Type,
};
use super::attribute::{DeriveResponseMeta, ResponseMeta};
use super::{
attribute::{DeriveResponseMeta, ResponseMeta},
ensure_feature_presence,
};
use crate::util::import_ruma_common;
mod incoming;
@ -19,6 +22,8 @@ pub fn expand_response(attr: ResponseAttr, item: ItemStruct) -> TokenStream {
let ruma_common = import_ruma_common();
let ruma_macros = quote! { #ruma_common::exports::ruma_macros };
let maybe_feature_error = ensure_feature_presence().map(syn::Error::to_compile_error);
let error_ty = attr
.0
.iter()
@ -29,6 +34,8 @@ pub fn expand_response(attr: ResponseAttr, item: ItemStruct) -> TokenStream {
.unwrap_or_else(|| quote! { #ruma_common::api::error::MatrixError });
quote! {
#maybe_feature_error
#[derive(
Clone,
Debug,