-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
By-reference pattern guards #2036
Comments
You cannot fix this with |
I think this is either a bug or a missing feature in the language, depending on your philosophical point of view :) Each binding in a pattern has one of four binding mode, based on keywords (or on context, with #2005). When matching a value of type
Currently, the type of We could change the language so that the type in guards is not the same as in the arm’s body in the "by value" cases: However, now that I’ve typed all this, I realize that this may be a breaking change in the |
I only meant if it should be considered a bug that you seemingly cannot use
I now see
|
Ah, so if I rephrase, an alternative is to not change the type of
Try |
You still get "error[E0301]: cannot mutably borrow in a pattern guard" even with |
I believe this is a duplicate of https://github.com/rust-lang/rfcs/blob/master/text/0107-pattern-guards-with-bind-by-move.md , is that right? |
Yes, it would seem so. Closing as duplicate. |
errors with
The usual workaround is to use
Some(ref v)
instead. But this prevents the match block from taking ownership.This forces the guard to be moved into the match, which leads to duplicate code A and B:
It would be more ergonomic if moving match arms with guards passed their values by reference to the guard.
The text was updated successfully, but these errors were encountered: