Skip to content
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

Support ? for Option and Result #950

Merged
merged 4 commits into from
Jan 9, 2024
Merged

Conversation

tjhance
Copy link
Collaborator

@tjhance tjhance commented Dec 27, 2023

Internally, rustc de-sugars the 'x?' operation to something like this:

match x.branch() {
    ControlFlow::Break(b) => { return from_residual(x); }
    ControlFlow::Continue(c) => c,
}

To support '?', we just need to add support for all the content in the de-sugar:

Result should work the same way, but the problem is that the Result's implementation of FromResidual is more generic than we support right now. It's a similar problem to vec indexing, and we can work around it the same way, but this PR doesn't handle it.

UPDATE: Result is now supported.

@tjhance tjhance changed the title Support ? for Option Support ? for Option and Result Jan 8, 2024
@tjhance tjhance merged commit 17528d1 into numeric-fields-in-structs Jan 9, 2024
5 checks passed
@tjhance tjhance deleted the question-mark-2 branch January 9, 2024 18:43
@tjhance
Copy link
Collaborator Author

tjhance commented Jan 9, 2024

(merged this into the wrong branch ... I'll fix it manually)

tjhance added a commit that referenced this pull request Jan 9, 2024
* support ? for Option

* support Result based on Chris's suggestion
tjhance added a commit that referenced this pull request Jan 9, 2024
@tjhance
Copy link
Collaborator Author

tjhance commented Jan 9, 2024

I forgot that this is dependent on #949. So, I will merge this into main after #949 is in.

tjhance added a commit that referenced this pull request Jan 14, 2024
* support ? for Option

* support Result based on Chris's suggestion
@tjhance
Copy link
Collaborator Author

tjhance commented Jan 14, 2024

Now merged in, for real, via 49cd0a5

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.

2 participants