Skip to content

Commit 760c435

Browse files
committed
Migrate "struct literal body without path" error to diagnostic struct
1 parent ba10f2c commit 760c435

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

compiler/rustc_parse/src/errors.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1014,3 +1014,21 @@ pub(crate) enum ExpectedSemiSugg {
10141014
#[suggestion_short(parser::sugg_add_semi, code = ";", applicability = "machine-applicable")]
10151015
AddSemi(#[primary_span] Span),
10161016
}
1017+
1018+
#[derive(Diagnostic)]
1019+
#[diag(parser::struct_literal_body_without_path)]
1020+
pub(crate) struct StructLiteralBodyWithoutPath {
1021+
#[primary_span]
1022+
pub span: Span,
1023+
#[subdiagnostic]
1024+
pub sugg: StructLiteralBodyWithoutPathSugg,
1025+
}
1026+
1027+
#[derive(Subdiagnostic)]
1028+
#[multipart_suggestion(parser::suggestion, applicability = "has-placeholders")]
1029+
pub(crate) struct StructLiteralBodyWithoutPathSugg {
1030+
#[suggestion_part(code = "{{ SomeStruct ")]
1031+
pub before: Span,
1032+
#[suggestion_part(code = " }}")]
1033+
pub after: Span,
1034+
}

compiler/rustc_parse/src/parser/diagnostics.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use super::{
66
use crate::errors::{
77
AmbiguousPlus, BadQPathStage2, BadTypePlus, BadTypePlusSub, ExpectedIdentifier, ExpectedSemi,
88
ExpectedSemiSugg, InInTypo, IncorrectAwait, IncorrectSemicolon, IncorrectUseOfAwait,
9-
SuggEscapeToUseAsIdentifier, SuggRemoveComma, UseEqInstead,
9+
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, SuggEscapeToUseAsIdentifier,
10+
SuggRemoveComma, UseEqInstead,
1011
};
1112

1213
use crate::lexer::UnmatchedBrace;
@@ -21,10 +22,10 @@ use rustc_ast::{
2122
};
2223
use rustc_ast_pretty::pprust;
2324
use rustc_data_structures::fx::FxHashSet;
25+
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
2426
use rustc_errors::{
25-
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
27+
Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
2628
};
27-
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
2829
use rustc_span::source_map::Spanned;
2930
use rustc_span::symbol::{kw, sym, Ident};
3031
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
@@ -645,19 +646,13 @@ impl<'a> Parser<'a> {
645646
// field: value,
646647
// } }
647648
err.delay_as_bug();
648-
self.struct_span_err(
649-
expr.span,
650-
fluent::parser::struct_literal_body_without_path,
651-
)
652-
.multipart_suggestion(
653-
fluent::parser::suggestion,
654-
vec![
655-
(expr.span.shrink_to_lo(), "{ SomeStruct ".to_string()),
656-
(expr.span.shrink_to_hi(), " }".to_string()),
657-
],
658-
Applicability::MaybeIncorrect,
659-
)
660-
.emit();
649+
self.sess.emit_err(StructLiteralBodyWithoutPath {
650+
span: expr.span,
651+
sugg: StructLiteralBodyWithoutPathSugg {
652+
before: expr.span.shrink_to_lo(),
653+
after: expr.span.shrink_to_hi(),
654+
},
655+
});
661656
self.restore_snapshot(snapshot);
662657
let mut tail = self.mk_block(
663658
vec![self.mk_stmt_err(expr.span)],

0 commit comments

Comments
 (0)