macros: move sess out of builder

`sess` field of `SessionDiagnosticDeriveBuilder` is never actually used
in the builder's member functions, so it doesn't need to be a field.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-06-29 16:22:27 +01:00
parent 406579ae13
commit 7f9d8480d6

View File

@ -20,6 +20,7 @@ use synstructure::{BindingInfo, Structure};
/// The central struct for constructing the `into_diagnostic` method from an annotated struct. /// The central struct for constructing the `into_diagnostic` method from an annotated struct.
pub(crate) struct SessionDiagnosticDerive<'a> { pub(crate) struct SessionDiagnosticDerive<'a> {
structure: Structure<'a>, structure: Structure<'a>,
sess: syn::Ident,
builder: SessionDiagnosticDeriveBuilder, builder: SessionDiagnosticDeriveBuilder,
} }
@ -28,18 +29,18 @@ impl<'a> SessionDiagnosticDerive<'a> {
Self { Self {
builder: SessionDiagnosticDeriveBuilder { builder: SessionDiagnosticDeriveBuilder {
diag, diag,
sess,
fields: build_field_mapping(&structure), fields: build_field_mapping(&structure),
kind: None, kind: None,
code: None, code: None,
slug: None, slug: None,
}, },
sess,
structure, structure,
} }
} }
pub(crate) fn into_tokens(self) -> TokenStream { pub(crate) fn into_tokens(self) -> TokenStream {
let SessionDiagnosticDerive { mut structure, mut builder } = self; let SessionDiagnosticDerive { mut structure, sess, mut builder } = self;
let ast = structure.ast(); let ast = structure.ast();
let attrs = &ast.attrs; let attrs = &ast.attrs;
@ -96,7 +97,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
.each(|field_binding| builder.generate_field_attrs_code(field_binding)); .each(|field_binding| builder.generate_field_attrs_code(field_binding));
let span = ast.span().unwrap(); let span = ast.span().unwrap();
let (diag, sess) = (&builder.diag, &builder.sess); let diag = &builder.diag;
let init = match (builder.kind, builder.slug) { let init = match (builder.kind, builder.slug) {
(None, _) => { (None, _) => {
span_err(span, "diagnostic kind not specified") span_err(span, "diagnostic kind not specified")
@ -159,7 +160,6 @@ impl<'a> SessionDiagnosticDerive<'a> {
} }
}; };
let sess = &builder.sess;
structure.gen_impl(quote! { structure.gen_impl(quote! {
gen impl<'__session_diagnostic_sess> rustc_session::SessionDiagnostic<'__session_diagnostic_sess, #param_ty> gen impl<'__session_diagnostic_sess> rustc_session::SessionDiagnostic<'__session_diagnostic_sess, #param_ty>
for @Self for @Self
@ -200,8 +200,6 @@ impl SessionDiagnosticKind {
/// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a /// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a
/// double mut borrow later on. /// double mut borrow later on.
struct SessionDiagnosticDeriveBuilder { struct SessionDiagnosticDeriveBuilder {
/// Name of the session parameter that's passed in to the `as_error` method.
sess: syn::Ident,
/// The identifier to use for the generated `DiagnosticBuilder` instance. /// The identifier to use for the generated `DiagnosticBuilder` instance.
diag: syn::Ident, diag: syn::Ident,