Jack Huey
3cf0e98dc9
Stabilize GATs
2022-08-30 23:06:24 -04:00
Joshua Nelson
31e39446ec
Stabilize #![feature(label_break_value)]
...
# Stabilization proposal
The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now).
There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`.
There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed).
1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234
2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176
3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630
Many different examples of code that's simpler using this feature have been provided:
- A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014
- A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251 . This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize).
- Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395
- Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733
- An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569
- Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006
Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249
nrc later resolved their concern, mostly because of the aforementioned macro problems.
joshtriplett suggested that macros could be able to generate IR directly
(https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983 ) but there are no open RFCs,
and the design space seems rather speculative.
joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804
withoutboats has regrettably left the language team.
joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353
[issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+
## Report
+ Feature gate:
- d695a497bb/src/test/ui/feature-gates/feature-gate-label_break_value.rs
+ Diagnostics:
- 6b2d3d5f3c/compiler/rustc_parse/src/parser/diagnostics.rs (L2629)
- f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L749)
- f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L1001)
- 111df9e6ed/compiler/rustc_passes/src/loops.rs (L254)
- d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L2079)
- d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L1569)
+ Tests:
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs
- https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs
## Interactions with other features
Labels follow the hygiene of local variables.
label-break-value is permitted within `try` blocks:
```rust
let _: Result<(), ()> = try {
'foo: {
Err(())?;
break 'foo;
}
};
```
label-break-value is disallowed within closures, generators, and async blocks:
```rust
'a: {
|| break 'a
//~^ ERROR use of unreachable label `'a`
//~| ERROR `break` inside of a closure
}
```
label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]:
```rust
fn labeled_match() {
match false 'b: { //~ ERROR block label not supported here
_ => {}
}
}
macro_rules! m {
($b:block) => {
'lab: $b; //~ ERROR cannot use a `block` macro fragment here
unsafe $b; //~ ERROR cannot use a `block` macro fragment here
|x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here
}
}
fn foo() {
m!({});
}
```
[_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html
[_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23 21:14:12 -05:00
Maybe Waffle
30a3673478
Add rustfmt test for formatting for<> before closures
2022-07-12 21:00:13 +04:00
Caleb Cartwright
591b056376
Merge commit ' c4416f20dc' into sync-rustfmt
2022-06-22 22:14:32 -05:00
Caleb Cartwright
ecddc26b0e
Merge commit ' 7b73b60fac' into sync-rustfmt
2022-06-12 22:03:05 -05:00
Jacob Pratt
6970246886
Remove crate visibility modifier in libs, tests
2022-05-21 00:32:47 -04:00
ydah
36ad596ef3
Fix typo
...
This PR is fixes typo "avaiable" to "available".
2022-05-20 10:39:10 +09:00
Caleb Cartwright
419df99e18
Merge commit ' 5ff7b632a9' into sync-rustfmt-subtree
2022-03-29 23:17:30 -05:00
Caleb Cartwright
521fdcbe4d
Merge commit ' 4a053f206f' into sync-rustfmt-subtree
2021-12-29 20:49:39 -06:00
Caleb Cartwright
f6ade7ca36
Merge commit ' 8da8371857' into sync-rustfmt-subtree
2021-12-02 21:35:30 -06:00
Caleb Cartwright
30fb1246b4
Merge commit ' ea199bacef' into rustfmt-sync
2021-11-07 20:37:34 -06:00
Caleb Cartwright
d3ecb02bdd
ensure cargo-fmt tests are excluded from root workspace
2021-10-20 10:12:22 -05:00
Caleb Cartwright
714e904969
Merge commit ' efa8f5521d' into rustfmt-subtree
2021-10-20 00:11:59 -05:00
Cameron Steffen
cb4439a315
Temporary fix rustfmt for let-else
2021-08-30 20:18:41 -05:00
Deadbeef
2d7dbf2e05
Fix rustfmt test
2021-08-27 11:53:03 +00:00
Deadbeef
8660832086
Introduce ~const
...
- [x] Removed `?const` and change uses of `?const`
- [x] Added `~const` to the AST. It is gated behind const_trait_impl.
- [x] Validate `~const` in ast_validation.
- [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and
`ConstIfConst` allowing future extensions)
- [ ] Adjust trait selection and pre-existing code to use `BoundConstness`.
- [ ] Optional steps (*for this PR, obviously*)
- [ ] Fix #88155
- [ ] Do something with constness bounds in chalk
2021-08-27 05:07:37 +00:00
Frank Steffahn
2f9ddf3bc7
Fix typos “an”→“a” and a few different ones that appeared in the same search
2021-08-22 18:15:49 +02:00
Caleb Cartwright
102a06b36b
Merge commit ' 4236289b75' into update-rustfmt
2021-07-25 22:57:19 -05:00
Caleb Cartwright
d2f2237d31
fix(rustfmt): load nested out-of-line mods correctly
2021-06-17 22:35:19 -05:00
Caleb Cartwright
b2d45c0d4b
Add 'src/tools/rustfmt/' from commit ' 7872306edf'
...
git-subtree-dir: src/tools/rustfmt
git-subtree-mainline: e659b6de91
git-subtree-split: 7872306edf
2021-05-14 21:53:36 -05:00