use proc_macro2::TokenStream;
use syn::{DeriveInput, ExprPath, Generics, Type, visit_mut::VisitMut};
use super::{attributes::generated_lint_attributes, generics::ReplaceSelf, quote_mixed};
pub(crate) struct MethodMarker {
lint_attributes: TokenStream,
pub(crate) generics: Generics,
pub(crate) field_ty: Type,
pub(crate) method: ExprPath,
}
impl MethodMarker {
pub(crate) fn new(
ast: &DeriveInput,
generics: &Generics,
field_ty: &Type,
method: &ExprPath,
) -> Self {
let mut replace_self = ReplaceSelf::new(ast);
let mut generics = generics.clone();
let mut field_ty = field_ty.clone();
let mut method = method.clone();
replace_self.visit_generics_mut(&mut generics);
replace_self.visit_type_mut(&mut field_ty);
replace_self.visit_expr_path_mut(&mut method);
Self {
lint_attributes: generated_lint_attributes(&ast.attrs),
generics,
field_ty,
method,
}
}
pub(crate) fn wrap(&self, function: TokenStream) -> TokenStream {
let lint_attributes = &self.lint_attributes;
quote_mixed!(
#lint_attributes
const _: () = {
#[allow(dead_code, clippy::all)]
#function
};
)
}
}