Skip to content

Rename and rewrite the "question mark operator" #1931

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2025

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Jul 14, 2025

This renames the "question mark operator" section, and rewrites it to reference the Try trait. See individual commits for a more detailed description.

Fixes #1927

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Jul 14, 2025
@ehuss ehuss force-pushed the try-types branch 5 times, most recently from 6a69850 to 7f33268 Compare July 15, 2025 22:13
This renames the "question mark operator" section to the "try
propagation expression", and also drops the grammar name "error
propagation expression".

The "error propagation expression" isn't really accurate, since `?`
isn't just for errors.

The intent is to describe the expression by what it does (as most other
expressions do) instead of how it looks. It also felt a little awkward
to call it the "question mark expression".
@traviscross traviscross force-pushed the try-types branch 2 times, most recently from 61f349c to fa63c9a Compare July 15, 2025 22:22
This moves the examples to the intro. It also adds a ControlFlow
example. The intent here is to prepare for changing the rest of the
text, and the examples won't quite fit like the used to. I also prefer
the idea of having an example near every intro section.

Edited-by: TC
This rewrites the section to say that it uses the `Try` trait. I felt it
was a bit too awkward to avoid it (since it is unstable).

This keeps an explicit list of the types that the `Try` trait is
implemented for, and adds the missing types (like `ControlFlow`).

The intent is that when `Try` is stabilized that the desuggaring note
moves to a normative rule, the `expr.try.restricted-types` rule is
removed (and instead direct the user to the standard library
documentation).

I'm still holding out hope that they change the terminology, since I
think the current choice is going to be confusing.

This has a hack to allow `feature(try_trait_v2)` by abusing the style
checker by adding some spaces. I really wanted to keep this example
tested to ensure that it is kept up-to-date. However, I may regret this
in the future.

Fixes rust-lang#1927

Edited-by: TC
@traviscross traviscross enabled auto-merge July 15, 2025 22:37
@traviscross traviscross added this pull request to the merge queue Jul 15, 2025
Merged via the queue into rust-lang:master with commit d179e97 Jul 15, 2025
5 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expr.try (the question mark operator) is out of date with regards to Try/FromResidual implementors
3 participants