Rollup merge of #100713 - Xiretza:parser-expr-session-diagnostics, r=estebank
Convert diagnostics in parser/expr to SessionDiagnostic This migrates all the easy cases in `rustc_parse::parser::expr` to `SessionDiagnostic`s, I've left things such as `multipart_suggestion`s out for now in the hopes of a derive API being developed soon.
This commit is contained in:
commit
75b7089d1e
3 changed files with 596 additions and 282 deletions
|
@ -363,6 +363,349 @@ pub enum InvalidVariableDeclarationSub {
|
|||
UseLetNotVar(#[primary_span] Span),
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_comparison_operator)]
|
||||
pub(crate) struct InvalidComparisonOperator {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub invalid: String,
|
||||
#[subdiagnostic]
|
||||
pub sub: InvalidComparisonOperatorSub,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
pub(crate) enum InvalidComparisonOperatorSub {
|
||||
#[suggestion_short(
|
||||
parser::use_instead,
|
||||
applicability = "machine-applicable",
|
||||
code = "{correct}"
|
||||
)]
|
||||
Correctable {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
invalid: String,
|
||||
correct: String,
|
||||
},
|
||||
#[label(parser::spaceship_operator_invalid)]
|
||||
Spaceship(#[primary_span] Span),
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_logical_operator)]
|
||||
#[note]
|
||||
pub(crate) struct InvalidLogicalOperator {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub incorrect: String,
|
||||
#[subdiagnostic]
|
||||
pub sub: InvalidLogicalOperatorSub,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
pub(crate) enum InvalidLogicalOperatorSub {
|
||||
#[suggestion_short(
|
||||
parser::use_amp_amp_for_conjunction,
|
||||
applicability = "machine-applicable",
|
||||
code = "&&"
|
||||
)]
|
||||
Conjunction(#[primary_span] Span),
|
||||
#[suggestion_short(
|
||||
parser::use_pipe_pipe_for_disjunction,
|
||||
applicability = "machine-applicable",
|
||||
code = "||"
|
||||
)]
|
||||
Disjunction(#[primary_span] Span),
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::tilde_is_not_unary_operator)]
|
||||
pub(crate) struct TildeAsUnaryOperator(
|
||||
#[primary_span]
|
||||
#[suggestion_short(applicability = "machine-applicable", code = "!")]
|
||||
pub Span,
|
||||
);
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::unexpected_token_after_not)]
|
||||
pub(crate) struct NotAsNegationOperator {
|
||||
#[primary_span]
|
||||
pub negated: Span,
|
||||
pub negated_desc: String,
|
||||
#[suggestion_short(applicability = "machine-applicable", code = "!")]
|
||||
pub not: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::malformed_loop_label)]
|
||||
pub(crate) struct MalformedLoopLabel {
|
||||
#[primary_span]
|
||||
#[suggestion(applicability = "machine-applicable", code = "{correct_label}")]
|
||||
pub span: Span,
|
||||
pub correct_label: Ident,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::lifetime_in_borrow_expression)]
|
||||
pub(crate) struct LifetimeInBorrowExpression {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[suggestion(applicability = "machine-applicable", code = "")]
|
||||
#[label]
|
||||
pub lifetime_span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::field_expression_with_generic)]
|
||||
pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span);
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::macro_invocation_with_qualified_path)]
|
||||
pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span);
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::unexpected_token_after_label)]
|
||||
pub(crate) struct UnexpectedTokenAfterLabel(
|
||||
#[primary_span]
|
||||
#[label(parser::unexpected_token_after_label)]
|
||||
pub Span,
|
||||
);
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::require_colon_after_labeled_expression)]
|
||||
#[note]
|
||||
pub(crate) struct RequireColonAfterLabeledExpression {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub label: Span,
|
||||
#[suggestion_short(applicability = "machine-applicable", code = ": ")]
|
||||
pub label_end: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::do_catch_syntax_removed)]
|
||||
#[note]
|
||||
pub(crate) struct DoCatchSyntaxRemoved {
|
||||
#[primary_span]
|
||||
#[suggestion(applicability = "machine-applicable", code = "try")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::float_literal_requires_integer_part)]
|
||||
pub(crate) struct FloatLiteralRequiresIntegerPart {
|
||||
#[primary_span]
|
||||
#[suggestion(applicability = "machine-applicable", code = "{correct}")]
|
||||
pub span: Span,
|
||||
pub correct: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_int_literal_width)]
|
||||
#[help]
|
||||
pub(crate) struct InvalidIntLiteralWidth {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub width: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_num_literal_base_prefix)]
|
||||
#[note]
|
||||
pub(crate) struct InvalidNumLiteralBasePrefix {
|
||||
#[primary_span]
|
||||
#[suggestion(applicability = "maybe-incorrect", code = "{fixed}")]
|
||||
pub span: Span,
|
||||
pub fixed: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_num_literal_suffix)]
|
||||
#[help]
|
||||
pub(crate) struct InvalidNumLiteralSuffix {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub suffix: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_float_literal_width)]
|
||||
#[help]
|
||||
pub(crate) struct InvalidFloatLiteralWidth {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub width: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_float_literal_suffix)]
|
||||
#[help]
|
||||
pub(crate) struct InvalidFloatLiteralSuffix {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub suffix: String,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::int_literal_too_large)]
|
||||
pub(crate) struct IntLiteralTooLarge {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::missing_semicolon_before_array)]
|
||||
pub(crate) struct MissingSemicolonBeforeArray {
|
||||
#[primary_span]
|
||||
pub open_delim: Span,
|
||||
#[suggestion_verbose(applicability = "maybe-incorrect", code = ";")]
|
||||
pub semicolon: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::invalid_block_macro_segment)]
|
||||
pub(crate) struct InvalidBlockMacroSegment {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub context: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::if_expression_missing_then_block)]
|
||||
pub(crate) struct IfExpressionMissingThenBlock {
|
||||
#[primary_span]
|
||||
pub if_span: Span,
|
||||
#[subdiagnostic]
|
||||
pub sub: IfExpressionMissingThenBlockSub,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
pub(crate) enum IfExpressionMissingThenBlockSub {
|
||||
#[help(parser::condition_possibly_unfinished)]
|
||||
UnfinishedCondition(#[primary_span] Span),
|
||||
#[help(parser::add_then_block)]
|
||||
AddThenBlock(#[primary_span] Span),
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::if_expression_missing_condition)]
|
||||
pub(crate) struct IfExpressionMissingCondition {
|
||||
#[primary_span]
|
||||
#[label(parser::condition_label)]
|
||||
pub if_span: Span,
|
||||
#[label(parser::block_label)]
|
||||
pub block_span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::expected_expression_found_let)]
|
||||
pub(crate) struct ExpectedExpressionFoundLet {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::expected_else_block)]
|
||||
pub(crate) struct ExpectedElseBlock {
|
||||
#[primary_span]
|
||||
pub first_tok_span: Span,
|
||||
pub first_tok: String,
|
||||
#[label]
|
||||
pub else_span: Span,
|
||||
#[suggestion(applicability = "maybe-incorrect", code = "if ")]
|
||||
pub condition_start: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::outer_attribute_not_allowed_on_if_else)]
|
||||
pub(crate) struct OuterAttributeNotAllowedOnIfElse {
|
||||
#[primary_span]
|
||||
pub last: Span,
|
||||
|
||||
#[label(parser::branch_label)]
|
||||
pub branch_span: Span,
|
||||
|
||||
#[label(parser::ctx_label)]
|
||||
pub ctx_span: Span,
|
||||
pub ctx: String,
|
||||
|
||||
#[suggestion(applicability = "machine-applicable", code = "")]
|
||||
pub attributes: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::missing_in_in_for_loop)]
|
||||
pub(crate) struct MissingInInForLoop {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[subdiagnostic]
|
||||
pub sub: MissingInInForLoopSub,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
pub(crate) enum MissingInInForLoopSub {
|
||||
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
|
||||
#[suggestion_short(parser::use_in_not_of, applicability = "maybe-incorrect", code = "in")]
|
||||
InNotOf(#[primary_span] Span),
|
||||
#[suggestion_short(parser::add_in, applicability = "maybe-incorrect", code = " in ")]
|
||||
AddIn(#[primary_span] Span),
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::missing_comma_after_match_arm)]
|
||||
pub(crate) struct MissingCommaAfterMatchArm {
|
||||
#[primary_span]
|
||||
#[suggestion(applicability = "machine-applicable", code = ",")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::catch_after_try)]
|
||||
#[help]
|
||||
pub(crate) struct CatchAfterTry {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::comma_after_base_struct)]
|
||||
#[note]
|
||||
pub(crate) struct CommaAfterBaseStruct {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[suggestion_short(applicability = "machine-applicable", code = "")]
|
||||
pub comma: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::eq_field_init)]
|
||||
pub(crate) struct EqFieldInit {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[suggestion(applicability = "machine-applicable", code = ":")]
|
||||
pub eq: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::dotdotdot)]
|
||||
pub(crate) struct DotDotDot {
|
||||
#[primary_span]
|
||||
#[suggestion(parser::suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")]
|
||||
#[suggestion(parser::suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(parser::left_arrow_operator)]
|
||||
pub(crate) struct LeftArrowOperator {
|
||||
#[primary_span]
|
||||
#[suggestion(applicability = "maybe-incorrect", code = "< -")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
// SnapshotParser is used to create a snapshot of the parser
|
||||
// without causing duplicate errors being emitted when the `Parser`
|
||||
// is dropped.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue