diff options
| author | Ralf Jung <post@ralfj.de> | 2025-05-17 09:53:02 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-05-17 09:53:02 +0200 |
| commit | 8f2da9b487f47827d565c52e019db5a464f31808 (patch) | |
| tree | 301e9048498969ddd68998a0b787e50108b9f881 /compiler/rustc_parse/src/errors.rs | |
| parent | 3a9ee90deda02db57e34c1434960008678d9923d (diff) | |
| parent | a69bc17fb8026bdc0d24bb1896ff95f0eba1da4e (diff) | |
| download | rust-8f2da9b487f47827d565c52e019db5a464f31808.tar.gz rust-8f2da9b487f47827d565c52e019db5a464f31808.zip | |
Merge from rustc
Diffstat (limited to 'compiler/rustc_parse/src/errors.rs')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 766baf6f80c..31a48b22cfe 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -436,10 +436,28 @@ pub(crate) enum IfExpressionMissingThenBlockSub { #[derive(Diagnostic)] #[diag(parse_ternary_operator)] -#[help] pub(crate) struct TernaryOperator { #[primary_span] pub span: Span, + /// If we have a span for the condition expression, suggest the if/else + #[subdiagnostic] + pub sugg: Option<TernaryOperatorSuggestion>, + /// Otherwise, just print the suggestion message + #[help(parse_use_if_else)] + pub no_sugg: bool, +} + +#[derive(Subdiagnostic, Copy, Clone)] +#[multipart_suggestion(parse_use_if_else, applicability = "maybe-incorrect", style = "verbose")] +pub(crate) struct TernaryOperatorSuggestion { + #[suggestion_part(code = "if ")] + pub before_cond: Span, + #[suggestion_part(code = "{{")] + pub question: Span, + #[suggestion_part(code = "}} else {{")] + pub colon: Span, + #[suggestion_part(code = " }}")] + pub end: Span, } #[derive(Subdiagnostic)] |
