move sugg to derive session diagnostic
This commit is contained in:
parent
5e94b5faf1
commit
4d219d0666
3 changed files with 18 additions and 9 deletions
|
@ -339,6 +339,7 @@ parse_expected_identifier = expected identifier
|
||||||
parse_sugg_escape_identifier = escape `{$ident_name}` to use it as an identifier
|
parse_sugg_escape_identifier = escape `{$ident_name}` to use it as an identifier
|
||||||
|
|
||||||
parse_sugg_remove_comma = remove this comma
|
parse_sugg_remove_comma = remove this comma
|
||||||
|
parse_sugg_add_let_for_stmt = you might have meant to introduce a new binding
|
||||||
|
|
||||||
parse_expected_semi_found_reserved_identifier_str = expected `;`, found reserved identifier `{$token}`
|
parse_expected_semi_found_reserved_identifier_str = expected `;`, found reserved identifier `{$token}`
|
||||||
parse_expected_semi_found_keyword_str = expected `;`, found keyword `{$token}`
|
parse_expected_semi_found_keyword_str = expected `;`, found keyword `{$token}`
|
||||||
|
|
|
@ -906,6 +906,18 @@ pub(crate) struct SuggRemoveComma {
|
||||||
pub span: Span,
|
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)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum ExpectedIdentifierFound {
|
pub(crate) enum ExpectedIdentifierFound {
|
||||||
#[label(parse_expected_identifier_found_reserved_identifier)]
|
#[label(parse_expected_identifier_found_reserved_identifier)]
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::errors::{
|
||||||
IncorrectUseOfAwait, ParenthesesInForHead, ParenthesesInForHeadSugg,
|
IncorrectUseOfAwait, ParenthesesInForHead, ParenthesesInForHeadSugg,
|
||||||
PatternMethodParamWithoutBody, QuestionMarkInType, QuestionMarkInTypeSugg, SelfParamNotFirst,
|
PatternMethodParamWithoutBody, QuestionMarkInType, QuestionMarkInTypeSugg, SelfParamNotFirst,
|
||||||
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens,
|
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens,
|
||||||
StructLiteralNeedingParensSugg, SuggEscapeIdentifier, SuggRemoveComma,
|
StructLiteralNeedingParensSugg, SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma,
|
||||||
UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
|
UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
|
||||||
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead,
|
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead,
|
||||||
};
|
};
|
||||||
|
@ -32,8 +32,8 @@ 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::{
|
use rustc_errors::{
|
||||||
pluralize, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed,
|
pluralize, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage,
|
||||||
FatalError, Handler, IntoDiagnostic, MultiSpan, PResult,
|
ErrorGuaranteed, FatalError, Handler, IntoDiagnostic, MultiSpan, PResult,
|
||||||
};
|
};
|
||||||
use rustc_session::errors::ExprParenthesesNeeded;
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
|
@ -1019,12 +1019,8 @@ impl<'a> Parser<'a> {
|
||||||
match self.parse_ty() {
|
match self.parse_ty() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if self.token == token::Eq {
|
if self.token == token::Eq {
|
||||||
err.span_suggestion_verbose(
|
let sugg = SuggAddMissingLetStmt { span: prev_span };
|
||||||
prev_span,
|
sugg.add_to_diagnostic(err);
|
||||||
"you might have meant to introduce a new binding",
|
|
||||||
"let ".to_string(),
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue