move sugg to derive session diagnostic

This commit is contained in:
yukang 2023-05-09 11:51:04 +08:00
parent 5e94b5faf1
commit 4d219d0666
3 changed files with 18 additions and 9 deletions

View file

@ -906,6 +906,18 @@ pub(crate) struct SuggRemoveComma {
pub span: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(
parse_sugg_add_let_for_stmt,
style = "verbose",
applicability = "maybe-incorrect",
code = "let "
)]
pub(crate) struct SuggAddMissingLetStmt {
#[primary_span]
pub span: Span,
}
#[derive(Subdiagnostic)]
pub(crate) enum ExpectedIdentifierFound {
#[label(parse_expected_identifier_found_reserved_identifier)]

View file

@ -13,7 +13,7 @@ use crate::errors::{
IncorrectUseOfAwait, ParenthesesInForHead, ParenthesesInForHeadSugg,
PatternMethodParamWithoutBody, QuestionMarkInType, QuestionMarkInTypeSugg, SelfParamNotFirst,
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens,
StructLiteralNeedingParensSugg, SuggEscapeIdentifier, SuggRemoveComma,
StructLiteralNeedingParensSugg, SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma,
UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead,
};
@ -32,8 +32,8 @@ use rustc_ast::{
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{
pluralize, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed,
FatalError, Handler, IntoDiagnostic, MultiSpan, PResult,
pluralize, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage,
ErrorGuaranteed, FatalError, Handler, IntoDiagnostic, MultiSpan, PResult,
};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::Spanned;
@ -1019,12 +1019,8 @@ impl<'a> Parser<'a> {
match self.parse_ty() {
Ok(_) => {
if self.token == token::Eq {
err.span_suggestion_verbose(
prev_span,
"you might have meant to introduce a new binding",
"let ".to_string(),
Applicability::MaybeIncorrect,
);
let sugg = SuggAddMissingLetStmt { span: prev_span };
sugg.add_to_diagnostic(err);
}
}
Err(e) => {