From f669b78ffc9db8352c859d8c83c244975dbf0397 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 24 May 2022 15:09:47 +0100 Subject: errors: simplify referring to fluent attributes To render the message of a Fluent attribute, the identifier of the Fluent message must be known. `DiagnosticMessage::FluentIdentifier` contains both the message's identifier and optionally the identifier of an attribute. Generated constants for each attribute would therefore need to be named uniquely (amongst all error messages) or be able to refer to only the attribute identifier which will be combined with a message identifier later. In this commit, the latter strategy is implemented as part of the `Diagnostic` type's functions for adding subdiagnostics of various kinds. Signed-off-by: David Wood --- compiler/rustc_parse/src/parser/diagnostics.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index c9da58aae5c..12302315e90 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -17,10 +17,10 @@ use rustc_ast::{ }; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, ErrorGuaranteed}; use rustc_errors::{ - Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult, + fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult, }; +use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, ErrorGuaranteed}; use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, Ident}; @@ -658,13 +658,10 @@ impl<'a> Parser<'a> { err.delay_as_bug(); self.struct_span_err( expr.span, - DiagnosticMessage::fluent("parser-struct-literal-body-without-path"), + fluent::parser::struct_literal_body_without_path, ) .multipart_suggestion( - DiagnosticMessage::fluent_attr( - "parser-struct-literal-body-without-path", - "suggestion", - ), + fluent::parser::suggestion, vec![ (expr.span.shrink_to_lo(), "{ SomeStruct ".to_string()), (expr.span.shrink_to_hi(), " }".to_string()), -- cgit 1.4.1-3-g733a5