From adcc55d622e92b6067deb76c6c1159802ed96fae Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Sep 2022 14:27:42 +0200 Subject: [PATCH] Cleanups in SessionDiagnostic derive --- .../src/diagnostics/diagnostic_builder.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 32d6ba62a0d..2bff12b0059 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -155,7 +155,7 @@ impl DiagnosticDeriveBuilder { } else { Ident::new(name, attr.span()) }; - return Ok(quote! { #diag.#fn_name(rustc_errors::fluent::_subdiag::#fn_name); }); + return Ok(self.add_subdiagnostic(&fn_name, parse_quote! { _subdiag::#fn_name })); } _ => throw_invalid_attr!(attr, &meta), }; @@ -449,20 +449,18 @@ impl DiagnosticDeriveBuilder { let (span_field, mut applicability) = self.span_and_applicability_of_ty(info)?; - let mut msg = None; let mut code = None; let mut nested_iter = nested.into_iter().peekable(); - if let Some(nested_attr) = nested_iter.peek() { - if let NestedMeta::Meta(Meta::Path(path)) = nested_attr { - msg = Some(path.clone()); - } + let msg = if let Some(NestedMeta::Meta(Meta::Path(path))) = nested_iter.peek() { + let path = path.clone(); + // Move the iterator forward if a path was found (don't otherwise so that + // code/applicability can be found or an error emitted). + nested_iter.next(); + Some(path) + } else { + None }; - // Move the iterator forward if a path was found (don't otherwise so that - // code/applicability can be found or an error emitted). - if msg.is_some() { - let _ = nested_iter.next(); - } for nested_attr in nested_iter { let meta = match nested_attr {