Skip to content

Improve ternary operator recovery #141003

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 16, 2025
Merged

Conversation

clubby789
Copy link
Contributor

@clubby789 clubby789 commented May 14, 2025

This

  • Improves the span of the error to not point at the next token
  • Where possible, we use the span of the condition to further improve the span of the error to include the cond, and suggest a maybe-incorrect fix

Currently this works on free expressions, not let statements; some more refactoring would be needed to pass the span down, which I'm not sure is worth doing.

Old

image

New

image

@rustbot
Copy link
Collaborator

rustbot commented May 14, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 14, 2025
@compiler-errors
Copy link
Member

r? compiler-errors @bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 14, 2025

📌 Commit 1267333 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2025
compiler-errors added a commit to compiler-errors/rust that referenced this pull request May 15, 2025
…ler-errors

Improve ternary operator recovery

This
- Improves the span of the error to not point at the next token
- Where possible, we use the span of the condition to further improve the span of the error to include the cond, and suggest a maybe-incorrect fix

Currently this works on free expressions, not let statements; some more refactoring would be needed to pass the span down, which I'm not sure is worth doing.

### Old
![image](https://github.com/user-attachments/assets/5688cefc-e4ef-4135-a5ba-340ce05ae6f3)

### New
![image](https://github.com/user-attachments/assets/154f5380-e0c8-42c7-9bf8-0adb3d0433fa)
bors added a commit to rust-lang-ci/rust that referenced this pull request May 15, 2025
…mpiler-errors

Rollup of 14 pull requests

Successful merges:

 - rust-lang#139749 (docs(library/core/src/pin): fix typo "necessarily" -> "necessary")
 - rust-lang#140130 (Add LLDB providers for BTreeMap and BTreeSet)
 - rust-lang#140685 (Simplify `Vec::as_non_null` implementation and make it `const`)
 - rust-lang#140712 (normalization: avoid incompletely constraining GAT args)
 - rust-lang#140768 (Improve `dangerous_implicit_aurorefs` diagnostic output)
 - 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#140947 (Flush errors before deep normalize in `dropck_outlives`)
 - rust-lang#140966 (Remove #![feature(let_chains)] from library and src/librustdoc)
 - rust-lang#140977 ([win] Use a dash instead of slash for linker to avoid breaking lld)
 - rust-lang#140990 (VxWorks: updates from recent libc versions)
 - rust-lang#141003 (Improve ternary operator recovery)
 - 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
bors added a commit to rust-lang-ci/rust that referenced this pull request May 16, 2025
…iaskrgr

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
hkBst added a commit to hkBst/rust that referenced this pull request May 16, 2025
…ler-errors

Improve ternary operator recovery

This
- Improves the span of the error to not point at the next token
- Where possible, we use the span of the condition to further improve the span of the error to include the cond, and suggest a maybe-incorrect fix

Currently this works on free expressions, not let statements; some more refactoring would be needed to pass the span down, which I'm not sure is worth doing.

### Old
![image](https://github.com/user-attachments/assets/5688cefc-e4ef-4135-a5ba-340ce05ae6f3)

### New
![image](https://github.com/user-attachments/assets/154f5380-e0c8-42c7-9bf8-0adb3d0433fa)
@bors bors merged commit e53b9f8 into rust-lang:master May 16, 2025
6 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 16, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 16, 2025
Rollup merge of rust-lang#141003 - clubby789:ternary-improve, r=compiler-errors

Improve ternary operator recovery

This
- Improves the span of the error to not point at the next token
- Where possible, we use the span of the condition to further improve the span of the error to include the cond, and suggest a maybe-incorrect fix

Currently this works on free expressions, not let statements; some more refactoring would be needed to pass the span down, which I'm not sure is worth doing.

### Old
![image](https://github.com/user-attachments/assets/5688cefc-e4ef-4135-a5ba-340ce05ae6f3)

### New
![image](https://github.com/user-attachments/assets/154f5380-e0c8-42c7-9bf8-0adb3d0433fa)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants