Yuki Okushi
f4550a6edf
Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov
...
Stabilize `#![feature(label_break_value)]`
See the stabilization report in https://github.com/rust-lang/rust/issues/48594#issuecomment-1186213313 .
2022-08-25 08:50:54 +09: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
Dylan DPC
f42cdf76e1
Rollup merge of #100368 - chenyukang:fix-100321, r=lcnr
...
InferCtxt tainted_by_errors_flag should be Option<ErrorGuaranteed>
Fixes #100321 .
Use Cell<Option<ErrorGuaranteed>> to guarantee that we emit an error when that flag is set.
2022-08-23 20:40:03 +05:30
yukang
8be37644db
InferCtxt emit error when incorrectly tainted by errors
2022-08-22 22:15:23 +08:00
SparrowLii
a01ac5a699
re-base and use OutlivesEnvironment::with_bounds
2022-08-22 18:36:02 +08:00
SparrowLii
d037f1843e
add with_bounds
to OutlivesEnvironment
and implied_bounds_tys
to outlives_bounds::InferCtxtExt
2022-08-22 18:09:59 +08:00
SparrowLii
5d9e4d07fc
get rid of RefCell
in TransitiveRelation
2022-08-22 18:08:46 +08:00
Michael Goulet
c005e760f5
Rework point-at-arg
2022-08-21 02:34:52 +00:00
Matthias Krüger
51769af6ea
Rollup merge of #100691 - compiler-errors:issue-100690, r=estebank
...
Make `same_type_modulo_infer` a proper `TypeRelation`
Specifically, this fixes #100690 because we no longer consider a `ReLateBound` and a `ReVar` to be equal. `ReVar` can only be equal to free regions or static.
2022-08-20 19:32:11 +02:00
Matthias Krüger
61a529d902
Rollup merge of #100617 - chenyukang:fix-100605, r=compiler-errors
...
Suggest the right help message for as_ref
Fixes #100605
2022-08-20 07:09:00 +02:00
yukang
3de74f7e2b
Suggest the right help message for as_ref
2022-08-20 09:43:37 +08:00
bors
8064a49508
Auto merge of #99860 - oli-obk:revert_97346, r=pnkfelix
...
Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, …
…r=oli-obk"
This reverts commit c703d11dcc
, reversing
changes made to 64eb9ab869
.
it didn't apply cleanly, so now it works the same for RPIT and for TAIT instead of just working for RPIT, but we should keep those in sync anyway. It also exposed a TAIT bug (see the feature gated test that now ICEs).
r? `@pnkfelix`
fixes #99536
2022-08-18 15:41:30 +00:00
Michael Goulet
64bd8c1dc4
Make same_type_modulo_infer a proper TypeRelation
2022-08-17 19:02:55 +00:00
Michael Goulet
fc7fc0fae5
ty::Error does not match other types for region constraints
2022-08-17 17:23:52 +00:00
Michael Goulet
8b64988575
Fix error message with non-tupled bare fn trait
2022-08-16 01:21:11 +00:00
Michael Goulet
75dfe55a5d
TypeError can be Copy
2022-08-14 19:58:46 +00:00
Michael Goulet
aa1a07f114
Do not inline non-simple argument type errors into labels
2022-08-13 18:24:36 +00:00
Mark Rousskov
154a09dd91
Adjust cfgs
2022-08-12 16:28:15 -04:00
lcnr
f25cb83296
don't normalize wf predicates
...
this allows us to soundly use unnormalized projections for wf
2022-08-09 12:54:32 +02:00
Matthias Krüger
6919a07eb8
Rollup merge of #100102 - b-naber:typo-higher-ranked-sub, r=Dylan-DPC
...
Fix typo
r? ```@jackh726```
2022-08-03 22:30:46 +02:00
b-naber
1405ce35ac
fix typo
2022-08-03 11:04:10 +02:00
bors
b759b2efad
Auto merge of #99509 - lcnr:commit_unconditionally, r=jackh726
...
remove `commit_unconditionally`
`commit_unconditionally` is a noop unless we somehow inspect the current state of our snapshot. The only thing which does that is the leak check which was only used in one place where `commit_if_ok` is probably at least as, or even more, correct.
r? rust-lang/types
2022-08-03 01:55:20 +00:00
bors
06f4950cbd
Auto merge of #100032 - BoxyUwU:no_ty_in_placeholder_const, r=compiler-errors
...
make `PlaceholderConst` not store the type of the const
Currently the `Placeholder` variant on `ConstKind` is 28 bytes when with this PR its 8 bytes, i am not sure this is really useful at all rn since `Unevaluated` and `Value` variants are huge still but eventually it should be possible to get both down to 16 bytes 🤔 . Mostly opening this to see if this change has any perf impact when done before it can make `ConstKind`/`ConstS` smaller
2022-08-02 13:10:49 +00:00
Matthias Krüger
0629445300
Rollup merge of #99156 - lcnr:omoe-wa, r=wesleywiser
...
`codegen_fulfill_obligation` expect erased regions
it's a query, so by erasing regions before calling it, we get better caching.
This doesn't actually change anything as its already the status quo.
2022-08-02 07:30:39 +02:00
Camille GILLOT
d7ea161b7e
Remove DefId from AssocItemContainer.
2022-08-01 21:38:45 +02:00
Ellen
49d001c5f3
fmt...
2022-08-01 20:15:58 +01:00
Ellen
825a7cc65c
make PlaceholderConst
not store the type of the const
2022-08-01 15:42:38 +01:00
Takayuki Maeda
03622552ec
use appropriate HirID
for finding else_span
2022-07-31 11:33:01 +09:00
Dylan DPC
c668820365
Rollup merge of #99311 - kckeiks:clean-up-body-owner-methods, r=cjgillot
...
change maybe_body_owned_by to take local def id
Issue https://github.com/rust-lang/rust/issues/96341
r? `@cjgillot`
2022-07-30 20:39:46 +05:30
bors
110777b60c
Auto merge of #99796 - compiler-errors:issue-53475, r=oli-obk
...
use `check_region_obligations_and_report_errors` to avoid ICEs
If we don't call `process_registered_region_obligations` before `resolve_regions_and_report_errors` then we'll ICE if we have any region obligations, and `check_region_obligations_and_report_errors` just does both of these for us in a nice convenient function.
Fixes #53475
r? types
2022-07-30 09:35:22 +00:00
Miguel Guarniz
16513d689e
Rename local_did to def_id
...
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:26:10 -04:00
Miguel Guarniz
25bdc8965e
Change maybe_body_owned_by to take local def id
...
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:25:58 -04:00
lcnr
1436fa9e90
optimize bound vars replacement :3
2022-07-29 08:45:06 +02:00
Michael Goulet
16f49800db
Document check_region_obligations_and_report_errors, simplify a call to resolve_regions
2022-07-29 06:17:17 +00:00
Oli Scherer
a85eb3d9df
Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, r=oli-obk"
...
This reverts commit c703d11dcc
, reversing
changes made to 64eb9ab869
.
2022-07-28 15:22:02 +00:00
lcnr
c3fce8e937
anonymize all bound vars, not just regions
2022-07-28 16:13:47 +02:00
lcnr
fd59d058ec
BoundVarReplacer
: trait object instead of 3 fns
2022-07-28 16:13:47 +02:00
bors
ada80a13b9
Auto merge of #99725 - lcnr:dedup-region_bound_pairs, r=compiler-errors
...
use `FxIndexSet` for `region_bound_pairs`
should help with #99217 and might generally be a perf improvement.
r? types
2022-07-27 22:02:14 +00:00
Guillaume Gomez
c37ee1a7e0
Rollup merge of #99728 - cjgillot:ast-lifetimes-anon-clean, r=petrochenkov
...
Clean up HIR-based lifetime resolution
Based on https://github.com/rust-lang/rust/pull/97313 .
Fixes #98932 .
r? `@petrochenkov`
2022-07-27 17:55:07 +02:00
Yuki Okushi
3b780fc279
Rollup merge of #99079 - compiler-errors:issue-99073, r=oli-obk
...
Check that RPITs constrained by a recursive call in a closure are compatible
Fixes #99073
Adapts a similar visitor pattern to `find_opaque_ty_constraints` (that we use to check TAITs), but with some changes:
0. Only walk the "OnlyBody" children, instead of all items in the RPIT's defining scope
1. Only walk through the body's children if we found a constraining usage
2. Don't actually do any inference, just do a comparison and error if they're mismatched
----
r? `@oli-obk` -- you know all this impl-trait stuff best... is this the right approach? I can explain the underlying issue better if you'd like, in case that might reveal a better solution. Not sure if it's possible to gather up the closure's defining usages of the RPIT while borrowck'ing the outer function, that might be a better place to put this check...
2022-07-27 19:05:32 +09:00
Camille GILLOT
556b02704f
Stop creating anonymous late lifetimes.
2022-07-26 19:00:31 +02:00
Matthias Krüger
ddb6a46316
Rollup merge of #99729 - cjgillot:rm-unused-tuple, r=michaelwoerister
...
Remove unused tuple fields
Found by https://github.com/rust-lang/rust/pull/95977
2022-07-26 16:57:50 +02:00
Dylan DPC
ad32667bc8
Rollup merge of #99748 - compiler-errors:better-impl-trait-printing, r=fee1-dead
...
Use full type name instead of just saying `impl Trait` in "captures lifetime" error
I think this is very useful, especially when there's >1 `impl Trait`, and it just means passing around a bit more info that we already have access to.
2022-07-26 14:27:00 +05:30
Dylan DPC
a39c00ee8d
Rollup merge of #99618 - compiler-errors:uhh-idk, r=lcnr
...
handle consts with param/infer in `const_eval_resolve` better
This PR addresses [this thread here](https://github.com/rust-lang/rust/pull/99449#discussion_r924141230 ). Was this the change you were looking for ``@lcnr?``
Interestingly, one test has begun to pass. Was that expected?
r? ``@lcnr``
2022-07-26 14:26:56 +05:30
Michael Goulet
82ad5c95b6
Revert "use opaque_ty_origin_unchecked instead of destructuring HIR"
...
This reverts commit 5a4601fea5
.
2022-07-26 07:46:30 +00:00
Michael Goulet
b248647ef0
Address nits, move substs replacement to separate function
2022-07-26 06:43:50 +00:00
Michael Goulet
d3492ca852
Use real opaque type instead of just saying impl Trait
2022-07-26 06:19:58 +00:00
Michael Goulet
f1618e8924
handle consts with param/infer in const_eval_resolve better
2022-07-25 23:41:13 +00:00
Camille GILLOT
ec83476748
Unused tuple fields in rustc_infer.
2022-07-25 19:45:10 +02:00
lcnr
2e796acf33
use FxIndexSet
for region_bound_pairs
2022-07-25 18:39:34 +02:00