Skip to content

Commit adcc55d

Browse files
committed
Cleanups in SessionDiagnostic derive
1 parent 8ab71ab commit adcc55d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl DiagnosticDeriveBuilder {
155155
} else {
156156
Ident::new(name, attr.span())
157157
};
158-
return Ok(quote! { #diag.#fn_name(rustc_errors::fluent::_subdiag::#fn_name); });
158+
return Ok(self.add_subdiagnostic(&fn_name, parse_quote! { _subdiag::#fn_name }));
159159
}
160160
_ => throw_invalid_attr!(attr, &meta),
161161
};
@@ -449,20 +449,18 @@ impl DiagnosticDeriveBuilder {
449449

450450
let (span_field, mut applicability) = self.span_and_applicability_of_ty(info)?;
451451

452-
let mut msg = None;
453452
let mut code = None;
454453

455454
let mut nested_iter = nested.into_iter().peekable();
456-
if let Some(nested_attr) = nested_iter.peek() {
457-
if let NestedMeta::Meta(Meta::Path(path)) = nested_attr {
458-
msg = Some(path.clone());
459-
}
455+
let msg = if let Some(NestedMeta::Meta(Meta::Path(path))) = nested_iter.peek() {
456+
let path = path.clone();
457+
// Move the iterator forward if a path was found (don't otherwise so that
458+
// code/applicability can be found or an error emitted).
459+
nested_iter.next();
460+
Some(path)
461+
} else {
462+
None
460463
};
461-
// Move the iterator forward if a path was found (don't otherwise so that
462-
// code/applicability can be found or an error emitted).
463-
if msg.is_some() {
464-
let _ = nested_iter.next();
465-
}
466464

467465
for nested_attr in nested_iter {
468466
let meta = match nested_attr {

0 commit comments

Comments
 (0)