-
Notifications
You must be signed in to change notification settings - Fork 19
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
Implement Try
and FromResidual<!>
for ()
#187
Comments
(Since I was mentioned in the meeting notes) I could go either way on this. See my previous comments in https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Use.20.60ControlFlow.60.20in.20HIR.20.60Visitor.60.20compiler-team.23597/near/339419883. I feel kinda weird about it, like maybe it wants something different, but it also meets all the expected properties, and TLDR I'm happy to follow libs-api's instincts either way on this one 🙂 |
We discussed this in a recent libs API meeting. This implementation would allow for quite confusing code. For example, The motivation seems to come down to basically The issue of Addressing that issue is perhaps something that can be done at the language level. (Some way to allow implementing a |
Closing ACP as per the above comment. |
Allow AST and HIR visitors to return `ControlFlow` Alternative to rust-lang#108598. Since rust-lang/libs-team#187 was rejected, this implements our own version of the `Try` trait (`VisitorResult`) and the `try` macro (`try_visit`). Since this change still allows visitors to return `()`, no changes have been made to the existing ones. They can be done in a separate PR.
Allow AST and HIR visitors to return `ControlFlow` Alternative to rust-lang#108598. Since rust-lang/libs-team#187 was rejected, this implements our own version of the `Try` trait (`VisitorResult`) and the `try` macro (`try_visit`). Since this change still allows visitors to return `()`, no changes have been made to the existing ones. They can be done in a separate PR.
Rollup merge of rust-lang#121256 - Jarcho:visitor2, r=oli-obk Allow AST and HIR visitors to return `ControlFlow` Alternative to rust-lang#108598. Since rust-lang/libs-team#187 was rejected, this implements our own version of the `Try` trait (`VisitorResult`) and the `try` macro (`try_visit`). Since this change still allows visitors to return `()`, no changes have been made to the existing ones. They can be done in a separate PR.
Allow AST and HIR visitors to return `ControlFlow` Alternative to #108598. Since rust-lang/libs-team#187 was rejected, this implements our own version of the `Try` trait (`VisitorResult`) and the `try` macro (`try_visit`). Since this change still allows visitors to return `()`, no changes have been made to the existing ones. They can be done in a separate PR.
Allow AST and HIR visitors to return `ControlFlow` Alternative to #108598. Since rust-lang/libs-team#187 was rejected, this implements our own version of the `Try` trait (`VisitorResult`) and the `try` macro (`try_visit`). Since this change still allows visitors to return `()`, no changes have been made to the existing ones. They can be done in a separate PR.
Proposal
Problem statement
Using
ControlFlow<Self::T>
in a trait where most implementors setT = !
. (orResult<_, Self::T>
) results in a lot of boilerplate for the implementer.Motivation, use-cases
Visitors with an early return can be modeled as a trait such as the following (used in rustc):
With non-branching implementations looking like (actual implementations can get worse):
Solution sketches
If
Try
andFromResidual<!>
are implemented for()
, then the previous example would instead be:Any impl which requires branching can then set
ResultTy
toControlFlow<T>
(orResult<(), T>
if that makes more sense).An alternative would be to use a custom
ResultTy
trait implemented for both()
andControlFlow<T>
(and others if needed). This would allow effectively the same interface, except anything which interacts with genericVisitor
s wouldn't be able to use the?
operator. This would mainly affect the implementation ofwalk_*
functions which would otherwise make heavy use of it.Downsides would be allowing
foo()?????
whenfoo
returns()
. This is easily solved with a lint any any use of?
on an expression of the type()
.Links and related work
Came up on zulip while discussing using
ControlFlow
more.What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: