Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 1624: `break` with values for `loop` #37339
Comments
aturon
added
B-RFC-approved
B-unstable
A-lang
labels
Oct 22, 2016
This comment has been minimized.
This comment has been minimized.
|
Currently awaiting implementation. cc @dhardy |
This comment has been minimized.
This comment has been minimized.
|
@aturon How would we go about advertising mentorship? If someone wants to implement this and they're not already familiar with the compiler internals, they can come to (Although I may be spreading myself thin a bit too much instead of finishing my own refactors.) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I hear you @aturon but don't have the time just now (and maybe for a few weeks). |
goffrie
added a commit
to goffrie/rust
that referenced
this issue
Oct 30, 2016
goffrie
added a commit
to goffrie/rust
that referenced
this issue
Oct 30, 2016
goffrie
added a commit
to goffrie/rust
that referenced
this issue
Nov 10, 2016
goffrie
added a commit
to goffrie/rust
that referenced
this issue
Nov 17, 2016
goffrie
added a commit
to goffrie/rust
that referenced
this issue
Nov 18, 2016
goffrie
added a commit
to goffrie/rust
that referenced
this issue
Nov 22, 2016
bors
added a commit
that referenced
this issue
Nov 22, 2016
stjepang
added a commit
to stjepang/rust
that referenced
this issue
Dec 16, 2016
This comment has been minimized.
This comment has been minimized.
|
Out of curiosity is there anything holding this back from being stabilized? |
aturon
added
the
T-lang
label
Mar 10, 2017
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl Not that I'm aware of. More obscure features like this are hard to judge, since we naturally tend to get very little feedback on them. In any case, it's certainly been around long enough that going to FCP to try to advertise for more feedback seems good: @rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 10, 2017
•
|
Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot reviewed |
This comment has been minimized.
This comment has been minimized.
|
I guess I don't have any technical reason against stabilising this (I was in favour of the RFC and nothing has changed my mind). But I kind of think that if a feature isn't being used at all then we should consider removing it rather than stabilising it. Is it worth posting in users.r-l.o to see if people are using it and whether there are any problems? |
This comment has been minimized.
This comment has been minimized.
|
It’s not surprising that a feature isn’t used when it’s not available yet. Much of the ecosystem has moved to the stable channel. |
This comment has been minimized.
This comment has been minimized.
andrewtj
commented
Mar 12, 2017
|
@nrc I played with it, saw that it worked, and then promptly stopped using it because while it's nice (really!) it's not worth jumping off stable for some indeterminate period. So if my experience is a barometer you may not get that much feedback but maybe that's to be expected for this feature. |
This comment has been minimized.
This comment has been minimized.
Boscop
commented
Mar 13, 2017
|
FWIW, I'm using it, e.g. for things like: let (filename, mut file) = loop {
let uuid = Uuid::new_v4().simple().to_string();
let filename = format!("{}.{}", uuid, ImageFormat::from_image_format(fmt).as_str());
let fpath = ::helper::filename_to_local(&filename);
if let Ok(f) = fs::OpenOptions::new().write(true).create_new(true).open(&fpath) {
break (filename, f);
}
};
img.save(&mut file, fmt)?; |
This comment has been minimized.
This comment has been minimized.
|
I also wouldn't depend on a nightly feature for this, but would use it if it were available. As it stands I'd tend to just use a temporary variable, but I'd rather not if this were stable. |
This comment has been minimized.
This comment has been minimized.
|
(Likewise, I originally popped in here to ask about stabilization because I was going to suggest it to someone on twitter who was lamenting the necessity of the temporary variables, before I realized that it's only available on nightly.) |
This comment has been minimized.
This comment has been minimized.
|
It should take more than just "apparent lack of usage" to remove a feature for which the RFC was accepted, with the motivation clearly understood. People won't go out of their way to change their existing code just to use this feature, but it offers a better alternative for some cases, doesn't introduce any significant complexity, and makes the syntax more consistent with the expression oriented nature of Rust. |
This comment has been minimized.
This comment has been minimized.
|
While I'm personally wildly in favor of this, it is important that features be evaluated before stabilization. There was a thread before on this connundrum, but I don't recall it concluding with a solution either :/. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 16, 2017
|
|
rfcbot
added
the
final-comment-period
label
Mar 16, 2017
steveklabnik
removed
the
A-lang
label
Mar 24, 2017
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 26, 2017
|
The final comment period is now complete. |
nikomatsakis
added
E-easy
E-medium
E-mentor
and removed
E-medium
labels
Apr 11, 2017
This comment has been minimized.
This comment has been minimized.
|
So, we've decided to stabilize this feature. That means we would like some PRs. I'm going to mark this bug as |
This was referenced May 12, 2017
This comment has been minimized.
This comment has been minimized.
|
Pull requests for the documentation sent to the various repositories. Should I wait for the stabilization PR? |
carols10cents
referenced this issue
May 15, 2017
Merged
loop_break_value: add documentation for book #41857
pietroalbini
referenced this issue
May 15, 2017
Merged
Stabilize the loop_break_value feature #42016
This comment has been minimized.
This comment has been minimized.
|
I noticed a small inconsistency between documentation and implementation: the RFC claims
but the impl doesn't support Perhaps this is for the best anyway until "break with value" is supported by |
This comment has been minimized.
This comment has been minimized.
|
New reference PR: rust-lang-nursery/reference#56 |
bors
added a commit
that referenced
this issue
May 22, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
May 23, 2017
This comment has been minimized.
This comment has been minimized.
|
It might make sense to allow break to take a value of type () in while and for loops too, for consistency. |
This comment has been minimized.
This comment has been minimized.
|
A future RFC could extend this to labelled blocks without loops. let result : u64 = 'block: {
if foo() { break 'block 1 }
if bar() { break 'block 2 }
3
};This would also give you a way to handle for and while let result : u64 = 'block: {
for e in container.iter() {
let v = foo(e);
if v > 0 { break 'block v }
}
0
};The semantics would be exactly the same as let result : u64 = 'block: loop { break {
for e in container.iter() {
let v = foo(e);
if v > 0 { break 'block v }
}
0
}};EDIT: I made this into a Pre-RFC. |
This comment has been minimized.
This comment has been minimized.
|
We specifically decided to limit this to |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis The proposal here is different: it's talking about jumping out to a labeled block, rather than simply breaking out of a loop. It just happens to combine reasonably well with loops. |
This comment has been minimized.
This comment has been minimized.
|
Hmm, one extra level of indentation, but way less controversy! That's a pretty neat trick @ciphergoth. |
This comment has been minimized.
This comment has been minimized.
|
Can this issue be closed? The stabilisation PR #42016 has been merged since. |
This comment has been minimized.
This comment has been minimized.
|
I think so, closing. |
aturon commentedOct 22, 2016
•
edited by nikomatsakis
RFC.
Current status: