-
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
block-break-value #2430
Comments
cc #2046, @ciphergoth |
Do you have a specific use case for this? (I'm not asking for hypotheses on how this could be used; do you have something specific you want to use this for?) Much of the motivation for introducing labeled |
Mainly combining 'label and try, to avoid nesting. See: // as part of a very complex function, like a game loop
let x = try {
if self.ready {
let a = do_complex_thing?;
more_complex_things(a)
} else {
Err(NotReady)
}
}
// Vs:
let x = 'label: try {
if !self.ready {
break 'label Err(NotReady);
}
// avoids nesting
let a = do_complex_thing?;
more_complex_things(a)
} (I find the latter much more readable, as the "normal" case is at the bottom of the block, not nested, and the "exceptional" case is out of the way. and yes I know about "omg please split your functions" but uh... no?) |
Or just using let x = try {
if !self.ready { throw NotReady; }
let a = do_complex_thing?;
more_complex_things(a)
} |
I'm glad label-break-value was accepted, but hope it's only rarely seen outside of macros offering interesting control flow constructs. I see it and Any time LBV is actually used the control flow is already unusual, so I actually appreciate the explicitness that comes from having a dedicated |
Closing since this doesn't seem to be going anywhere. If you want to continue with this proposal, please open a topic on internals.rust-lang.org, or write up a formal RFC proposal. |
We have:
It would be nice to extend this to other blocks:
As opposed to:
This avoids a whole level of indentation and an unnecessary pair of
{}
.Note that
while let
andwhile
wouldn't be changed because those can't return values.(Note that IDEs/rustfmt are unable to cope with:
Instead, they rewrite it to:
)
The text was updated successfully, but these errors were encountered: