Skip to content

Commit 7f9d848

Browse files
committed
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 <[email protected]>
1 parent 406579a commit 7f9d848

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use synstructure::{BindingInfo, Structure};
2020
/// The central struct for constructing the `into_diagnostic` method from an annotated struct.
2121
pub(crate) struct SessionDiagnosticDerive<'a> {
2222
structure: Structure<'a>,
23+
sess: syn::Ident,
2324
builder: SessionDiagnosticDeriveBuilder,
2425
}
2526

@@ -28,18 +29,18 @@ impl<'a> SessionDiagnosticDerive<'a> {
2829
Self {
2930
builder: SessionDiagnosticDeriveBuilder {
3031
diag,
31-
sess,
3232
fields: build_field_mapping(&structure),
3333
kind: None,
3434
code: None,
3535
slug: None,
3636
},
37+
sess,
3738
structure,
3839
}
3940
}
4041

4142
pub(crate) fn into_tokens(self) -> TokenStream {
42-
let SessionDiagnosticDerive { mut structure, mut builder } = self;
43+
let SessionDiagnosticDerive { mut structure, sess, mut builder } = self;
4344

4445
let ast = structure.ast();
4546
let attrs = &ast.attrs;
@@ -96,7 +97,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
9697
.each(|field_binding| builder.generate_field_attrs_code(field_binding));
9798

9899
let span = ast.span().unwrap();
99-
let (diag, sess) = (&builder.diag, &builder.sess);
100+
let diag = &builder.diag;
100101
let init = match (builder.kind, builder.slug) {
101102
(None, _) => {
102103
span_err(span, "diagnostic kind not specified")
@@ -159,7 +160,6 @@ impl<'a> SessionDiagnosticDerive<'a> {
159160
}
160161
};
161162

162-
let sess = &builder.sess;
163163
structure.gen_impl(quote! {
164164
gen impl<'__session_diagnostic_sess> rustc_session::SessionDiagnostic<'__session_diagnostic_sess, #param_ty>
165165
for @Self
@@ -200,8 +200,6 @@ impl SessionDiagnosticKind {
200200
/// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a
201201
/// double mut borrow later on.
202202
struct SessionDiagnosticDeriveBuilder {
203-
/// Name of the session parameter that's passed in to the `as_error` method.
204-
sess: syn::Ident,
205203
/// The identifier to use for the generated `DiagnosticBuilder` instance.
206204
diag: syn::Ident,
207205

0 commit comments

Comments
 (0)