Migrate "struct literal body without path" error to diagnostic struct
This commit is contained in:
parent
ba10f2c0f2
commit
760c4352d6
2 changed files with 30 additions and 17 deletions
|
@ -1014,3 +1014,21 @@ pub(crate) enum ExpectedSemiSugg {
|
||||||
#[suggestion_short(parser::sugg_add_semi, code = ";", applicability = "machine-applicable")]
|
#[suggestion_short(parser::sugg_add_semi, code = ";", applicability = "machine-applicable")]
|
||||||
AddSemi(#[primary_span] Span),
|
AddSemi(#[primary_span] Span),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(parser::struct_literal_body_without_path)]
|
||||||
|
pub(crate) struct StructLiteralBodyWithoutPath {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub sugg: StructLiteralBodyWithoutPathSugg,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[multipart_suggestion(parser::suggestion, applicability = "has-placeholders")]
|
||||||
|
pub(crate) struct StructLiteralBodyWithoutPathSugg {
|
||||||
|
#[suggestion_part(code = "{{ SomeStruct ")]
|
||||||
|
pub before: Span,
|
||||||
|
#[suggestion_part(code = " }}")]
|
||||||
|
pub after: Span,
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ use super::{
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
AmbiguousPlus, BadQPathStage2, BadTypePlus, BadTypePlusSub, ExpectedIdentifier, ExpectedSemi,
|
AmbiguousPlus, BadQPathStage2, BadTypePlus, BadTypePlusSub, ExpectedIdentifier, ExpectedSemi,
|
||||||
ExpectedSemiSugg, InInTypo, IncorrectAwait, IncorrectSemicolon, IncorrectUseOfAwait,
|
ExpectedSemiSugg, InInTypo, IncorrectAwait, IncorrectSemicolon, IncorrectUseOfAwait,
|
||||||
SuggEscapeToUseAsIdentifier, SuggRemoveComma, UseEqInstead,
|
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, SuggEscapeToUseAsIdentifier,
|
||||||
|
SuggRemoveComma, UseEqInstead,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::lexer::UnmatchedBrace;
|
use crate::lexer::UnmatchedBrace;
|
||||||
|
@ -21,10 +22,10 @@ use rustc_ast::{
|
||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{
|
|
||||||
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
|
|
||||||
};
|
|
||||||
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
|
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
|
||||||
|
use rustc_errors::{
|
||||||
|
Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
|
||||||
|
};
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
||||||
|
@ -645,19 +646,13 @@ impl<'a> Parser<'a> {
|
||||||
// field: value,
|
// field: value,
|
||||||
// } }
|
// } }
|
||||||
err.delay_as_bug();
|
err.delay_as_bug();
|
||||||
self.struct_span_err(
|
self.sess.emit_err(StructLiteralBodyWithoutPath {
|
||||||
expr.span,
|
span: expr.span,
|
||||||
fluent::parser::struct_literal_body_without_path,
|
sugg: StructLiteralBodyWithoutPathSugg {
|
||||||
)
|
before: expr.span.shrink_to_lo(),
|
||||||
.multipart_suggestion(
|
after: expr.span.shrink_to_hi(),
|
||||||
fluent::parser::suggestion,
|
},
|
||||||
vec![
|
});
|
||||||
(expr.span.shrink_to_lo(), "{ SomeStruct ".to_string()),
|
|
||||||
(expr.span.shrink_to_hi(), " }".to_string()),
|
|
||||||
],
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
self.restore_snapshot(snapshot);
|
self.restore_snapshot(snapshot);
|
||||||
let mut tail = self.mk_block(
|
let mut tail = self.mk_block(
|
||||||
vec![self.mk_stmt_err(expr.span)],
|
vec![self.mk_stmt_err(expr.span)],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue