Skip to content

Commit 4d02892

Browse files
committed
Allow raw identifiers to be used as fluent arguments
1 parent 8489a67 commit 4d02892

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
281281
if should_generate_set_arg(&field) {
282282
let diag = &self.parent.diag;
283283
let ident = field.ident.as_ref().unwrap();
284+
// strip `r#` prefix, if present
285+
let ident = format_ident!("{}", ident);
284286
return quote! {
285287
#diag.set_arg(
286288
stringify!(#ident),

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
189189

190190
let diag = &self.diag;
191191
let ident = ast.ident.as_ref().unwrap();
192+
// strip `r#` prefix, if present
193+
let ident = format_ident!("{}", ident);
194+
192195
quote! {
193196
#diag.set_arg(
194197
stringify!(#ident),

src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,9 @@ enum ExampleEnum {
671671
#[diag(typeck::ambiguous_lifetime_bound)]
672672
Baz,
673673
}
674+
675+
#[derive(Diagnostic)]
676+
#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
677+
struct RawIdentDiagnosticArg {
678+
pub r#type: String,
679+
}

src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,11 @@ struct BI {
633633
#[suggestion_part(code = "")]
634634
spans: Vec<Span>,
635635
}
636+
637+
#[derive(Subdiagnostic)]
638+
#[label(parser::add_paren)]
639+
struct BJ {
640+
#[primary_span]
641+
span: Span,
642+
r#type: String,
643+
}

0 commit comments

Comments
 (0)