|
| 1 | +// ignore-tidy-filelength |
| 2 | + |
1 | 3 | use std::borrow::Cow;
|
2 | 4 |
|
3 | 5 | use rustc_ast::token::Token;
|
@@ -2592,13 +2594,86 @@ pub(crate) struct ExpectedCommaAfterPatternField {
|
2592 | 2594 | #[derive(Diagnostic)]
|
2593 | 2595 | #[diag(parse_unexpected_expr_in_pat)]
|
2594 | 2596 | pub(crate) struct UnexpectedExpressionInPattern {
|
| 2597 | + /// The unexpected expr's span. |
2595 | 2598 | #[primary_span]
|
2596 | 2599 | #[label]
|
2597 | 2600 | pub span: Span,
|
2598 | 2601 | /// Was a `RangePatternBound` expected?
|
2599 | 2602 | pub is_bound: bool,
|
2600 |
| - /// Was the unexpected expression a `MethodCallExpression`? |
2601 |
| - pub is_method_call: bool, |
| 2603 | + /// The unexpected expr's precedence (used in match arm guard suggestions). |
| 2604 | + pub expr_precedence: i8, |
| 2605 | +} |
| 2606 | + |
| 2607 | +#[derive(Subdiagnostic)] |
| 2608 | +pub(crate) enum UnexpectedExpressionInPatternSugg { |
| 2609 | + #[multipart_suggestion( |
| 2610 | + parse_unexpected_expr_in_pat_create_guard_sugg, |
| 2611 | + applicability = "maybe-incorrect" |
| 2612 | + )] |
| 2613 | + CreateGuard { |
| 2614 | + /// Where to put the suggested identifier. |
| 2615 | + #[suggestion_part(code = "{ident}")] |
| 2616 | + ident_span: Span, |
| 2617 | + /// Where to put the match arm. |
| 2618 | + #[suggestion_part(code = " if {ident} == {expr}")] |
| 2619 | + pat_hi: Span, |
| 2620 | + /// The suggested identifier. |
| 2621 | + ident: String, |
| 2622 | + /// The unexpected expression. |
| 2623 | + expr: String, |
| 2624 | + }, |
| 2625 | + |
| 2626 | + #[multipart_suggestion( |
| 2627 | + parse_unexpected_expr_in_pat_update_guard_sugg, |
| 2628 | + applicability = "maybe-incorrect" |
| 2629 | + )] |
| 2630 | + UpdateGuard { |
| 2631 | + /// Where to put the suggested identifier. |
| 2632 | + #[suggestion_part(code = "{ident}")] |
| 2633 | + ident_span: Span, |
| 2634 | + /// The beginning of the match arm guard's expression (insert a `(` if `Some`). |
| 2635 | + #[suggestion_part(code = "(")] |
| 2636 | + guard_lo: Option<Span>, |
| 2637 | + /// The end of the match arm guard's expression. |
| 2638 | + #[suggestion_part(code = "{guard_hi_paren} && {ident} == {expr}")] |
| 2639 | + guard_hi: Span, |
| 2640 | + /// Either `")"` or `""`. |
| 2641 | + guard_hi_paren: &'static str, |
| 2642 | + /// The suggested identifier. |
| 2643 | + ident: String, |
| 2644 | + /// The unexpected expression. |
| 2645 | + expr: String, |
| 2646 | + }, |
| 2647 | + |
| 2648 | + #[multipart_suggestion( |
| 2649 | + parse_unexpected_expr_in_pat_const_sugg, |
| 2650 | + applicability = "has-placeholders" |
| 2651 | + )] |
| 2652 | + Const { |
| 2653 | + /// Where to put the extracted constant declaration. |
| 2654 | + #[suggestion_part(code = "{indentation}const {ident}: /* Type */ = {expr};\n")] |
| 2655 | + stmt_lo: Span, |
| 2656 | + /// Where to put the suggested identifier. |
| 2657 | + #[suggestion_part(code = "{ident}")] |
| 2658 | + ident_span: Span, |
| 2659 | + /// The suggested identifier. |
| 2660 | + ident: String, |
| 2661 | + /// The unexpected expression. |
| 2662 | + expr: String, |
| 2663 | + /// The statement's block's indentation. |
| 2664 | + indentation: String, |
| 2665 | + }, |
| 2666 | + |
| 2667 | + #[multipart_suggestion( |
| 2668 | + parse_unexpected_expr_in_pat_inline_const_sugg, |
| 2669 | + applicability = "maybe-incorrect" |
| 2670 | + )] |
| 2671 | + InlineConst { |
| 2672 | + #[suggestion_part(code = "const {{ ")] |
| 2673 | + start_span: Span, |
| 2674 | + #[suggestion_part(code = " }}")] |
| 2675 | + end_span: Span, |
| 2676 | + }, |
2602 | 2677 | }
|
2603 | 2678 |
|
2604 | 2679 | #[derive(Diagnostic)]
|
|
0 commit comments