Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c79bbfa

Browse files
committedMay 16, 2025
Auto merge of rust-lang#141066 - matthiaskrgr:rollup-e7tyrj5, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#140791 (std: explain prefer `TryInto` over `TryFrom` when specifying traits bounds on generic function) - rust-lang#140834 (move (or remove) some impl Trait tests) - rust-lang#140910 (Remove `stable` attribute from wasi fs (read_exact|write_all)_at) - rust-lang#140984 (fix doc for UnixStream) - rust-lang#140997 (Add negative test coverage for `-Clink-self-contained` and `-Zlinker-features`) - rust-lang#141003 (Improve ternary operator recovery) - rust-lang#141009 (Migrate to modern datetime API) - rust-lang#141013 (Implement methods to set STARTUPINFO flags for Command API on Windows) - rust-lang#141026 (rustc-dev-guide subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7e19eef + 5ce27f5 commit c79bbfa

File tree

110 files changed

+461
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+461
-259
lines changed
 

‎compiler/rustc_parse/messages.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,6 @@ parse_switch_ref_box_order = switch the order of `ref` and `box`
815815
.suggestion = swap them
816816
817817
parse_ternary_operator = Rust has no ternary operator
818-
.help = use an `if-else` expression instead
819818
820819
parse_tilde_is_not_unary_operator = `~` cannot be used as a unary operator
821820
.suggestion = use `!` to perform bitwise not
@@ -963,6 +962,8 @@ parse_use_empty_block_not_semi = expected { "`{}`" }, found `;`
963962
parse_use_eq_instead = unexpected `==`
964963
.suggestion = try using `=` instead
965964
965+
parse_use_if_else = use an `if-else` expression instead
966+
966967
parse_use_let_not_auto = write `let` instead of `auto` to introduce a new variable
967968
parse_use_let_not_var = write `let` instead of `var` to introduce a new variable
968969

‎compiler/rustc_parse/src/errors.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,28 @@ pub(crate) enum IfExpressionMissingThenBlockSub {
436436

437437
#[derive(Diagnostic)]
438438
#[diag(parse_ternary_operator)]
439-
#[help]
440439
pub(crate) struct TernaryOperator {
441440
#[primary_span]
442441
pub span: Span,
442+
/// If we have a span for the condition expression, suggest the if/else
443+
#[subdiagnostic]
444+
pub sugg: Option<TernaryOperatorSuggestion>,
445+
/// Otherwise, just print the suggestion message
446+
#[help(parse_use_if_else)]
447+
pub no_sugg: bool,
448+
}
449+
450+
#[derive(Subdiagnostic, Copy, Clone)]
451+
#[multipart_suggestion(parse_use_if_else, applicability = "maybe-incorrect", style = "verbose")]
452+
pub(crate) struct TernaryOperatorSuggestion {
453+
#[suggestion_part(code = "if ")]
454+
pub before_cond: Span,
455+
#[suggestion_part(code = "{{")]
456+
pub question: Span,
457+
#[suggestion_part(code = "}} else {{")]
458+
pub colon: Span,
459+
#[suggestion_part(code = " }}")]
460+
pub end: Span,
443461
}
444462

445463
#[derive(Subdiagnostic)]

0 commit comments

Comments
 (0)