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
Matthias Krüger
d793cd266c
Rollup merge of #100796 - TaKO8Ki:remove-unnecessary-string-searching, r=compiler-errors
...
Refactor: remove unnecessary string searchings
This patch removes unnecessary string searchings for checking if function arguments have `&` and `&mut`.
2022-08-20 19:45:17 +02:00
Matthias Krüger
7f0289623c
Rollup merge of #100769 - TaKO8Ki:suggest-adding-reference-to-trait-assoc-item, r=cjgillot
...
Suggest adding a reference to a trait assoc item
fixes #100289
2022-08-20 19:45:15 +02:00
Takayuki Maeda
a311b8a4c5
use more descriptive names
2022-08-20 19:35:17 +09:00
Takayuki Maeda
973510749d
remove unnecessary string searchings
...
remove unnecessary string searchings for checking if function arguments have `&` and `&mut`
2022-08-20 15:54:39 +09:00
Takayuki Maeda
64b3e4af20
suggest adding a reference to a trait assoc item
2022-08-20 02:51:20 +09:00
Andy Wang
84a199369b
Reword "Required because of the requirements on the impl of ..."
2022-08-18 21:08:08 +01: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
lcnr
1cede2c126
is_knowable
use Result
instead of Option
2022-08-17 10:17:54 +02:00
Michael Goulet
8b64988575
Fix error message with non-tupled bare fn trait
2022-08-16 01:21:11 +00:00
Matthias Krüger
a1fdea2b78
Rollup merge of #100514 - compiler-errors:issue-100191, r=spastorino
...
Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls
Fixes #100191
r? ``@spastorino``
2022-08-15 20:11:36 +02:00
Michael Goulet
75dfe55a5d
TypeError can be Copy
2022-08-14 19:58:46 +00:00
Dylan DPC
92344e369b
Rollup merge of #99861 - lcnr:orphan-check-cg, r=jackh726
...
orphan check: rationalize our handling of constants
cc `@rust-lang/types` `@rust-lang/project-const-generics` on whether you agree with this reasoning.
r? types
2022-08-14 17:09:13 +05:30
Michael Goulet
c436930f91
Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls
2022-08-13 22:11:42 +00:00
lcnr
1ec2b9bce8
wf correctly shallow_resolve consts
2022-08-13 21:04:52 +02:00
Mark Rousskov
154a09dd91
Adjust cfgs
2022-08-12 16:28:15 -04:00
bors
aeb5067967
Auto merge of #100315 - compiler-errors:norm-ct-in-proj, r=lcnr
...
Keep going if normalized projection has unevaluated consts in `QueryNormalizer`
#100312 was the wrong approach, I think this is the right one.
When normalizing a type, if we see that it's a projection, we currently defer to `tcx.normalize_projection_ty`, which normalizes the projections away but doesn't touch the unevaluated constants. So now we just continue to fold the type if it has unevaluated constants so we make sure to evaluate those too, if we can.
Fixes #100217
Fixes #83972
Fixes #84669
Fixes #86710
Fixes #82268
Fixes #73298
2022-08-11 10:47:48 +00:00
Michael Goulet
d2667e4b71
Move folding into just projection cases
2022-08-09 18:19:58 +00:00
bors
63e4312e6b
Auto merge of #99217 - lcnr:implied-bounds-pre-norm, r=lcnr
...
consider unnormalized types for implied bounds
extracted, and slightly modified, from #98900
The idea here is that generally, rustc is split into things which can assume its inputs are well formed[^1], and things which have verify that themselves.
Generally most predicates should only deal with well formed inputs, e.g. a `&'a &'b (): Trait` predicate should be able to assume that `'b: 'a` holds. Normalization can loosen wf requirements (see #91068 ) and must therefore not be used in places which still have to check well formedness. The only such place should hopefully be `WellFormed` predicates
fixes #87748 and #98543
r? `@jackh726` cc `@rust-lang/types`
[^1]: These places may still encounter non-wf inputs and have to deal with them without causing an ICE as we may check for well formedness out of order.
2022-08-09 16:39:43 +00:00
Dylan DPC
d910e5376b
Rollup merge of #100221 - compiler-errors:impossible-trait-items, r=lcnr,notriddle,camelid
...
Don't document impossible to call default trait items on impls
Closes #100176
This only skips documenting _default_ trait items on impls, not ones that are written inside the impl block. This is a conservative approach, since I think we should document all items written in an impl block (I guess unless hidden or whatever), but the existence of this new query I added makes this easy to extend to other rustdoc cases.
2022-08-09 17:34:54 +05:30
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
Michael Goulet
ca7e3c4a83
Keep going if normalized projection has unevaluated consts in QueryNormalizer
2022-08-09 09:41:28 +00:00
Michael Goulet
3fdf3cb80c
Adjust wording
2022-08-08 00:13:41 +00:00
Michael Goulet
750f04d309
Implement special-cased projection error message for some common traits
2022-08-07 23:57:53 +00:00
Michael Goulet
b3b23aada9
Don't document impossible to call default trait items on impls
2022-08-07 23:44:05 +00:00
bors
bd04658eb6
Auto merge of #99743 - compiler-errors:fulfillment-context-cleanups, r=jackh726
...
Some `FulfillmentContext`-related cleanups
Use `ObligationCtxt` in some places, remove some `FulfillmentContext`s in others...
r? types
2022-08-06 06:48:15 +00:00
Matthias Krüger
01ccde5ec8
Rollup merge of #100095 - jackh726:early-binder, r=lcnr
...
More EarlyBinder cleanups
Each commit is independent
r? types
2022-08-04 22:25:04 +02:00
Michael Goulet
f5af266b6d
Address nits
2022-08-04 13:59:25 +00:00
Michael Goulet
fe894756f8
Add traits::fully_solve_obligation
that acts like traits::fully_normalize
...
It spawns up a trait engine, registers the single obligation, then fully
solves it
2022-08-04 13:50:56 +00:00
Michael Goulet
3e48434cc7
Use ObligationCtxt in impossible_predicates
2022-08-04 13:42:13 +00:00
Michael Goulet
61d9b1656d
Remove unnecessary FulfillmentContext from need_migrate_deref_output_trait_object
2022-08-04 13:42:13 +00:00
Michael Goulet
37d412cff7
Remove FulfillmentContext param from fully_normalize
2022-08-04 13:42:13 +00:00
Matthias Krüger
02fcec2ac8
Rollup merge of #99795 - compiler-errors:delay-specialization-normalize-error, r=spastorino
...
Delay a bug when failed to normalize trait ref during specialization
The error messages still kinda suck here but they don't ICE anymore...
Fixes #45814
Fixes #43037
r? types
2022-08-03 22:29:30 +02:00
Matthias Krüger
0de7f756f0
Rollup merge of #99746 - compiler-errors:more-trait-engine, r=jackh726
...
Use `TraitEngine` in more places that don't specifically need `FulfillmentContext::new_in_snapshot`
Not sure if this change is worthwhile, but couldn't hurt re: chalkification
r? types
2022-08-03 22:29:27 +02:00
Jack Huey
955fcad758
Add bound_impl_subject and bound_return_ty
2022-08-03 01:02:46 -04:00
Jack Huey
96a69dce2c
Change sized_constraints to return EarlyBinder
2022-08-03 00:14:24 -04:00
Jack Huey
e21624dc80
Add bound_predicates_of and bound_explicit_predicates_of
2022-08-02 22:44:08 -04: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
Michael Goulet
16a3601f62
Delay a bug when failed to normalize trait ref during specialization
2022-08-03 01:37:02 +00:00
bors
e4417cf020
Auto merge of #92268 - jswrenn:transmute, r=oli-obk
...
Initial implementation of transmutability trait.
*T'was the night before Christmas and all through the codebase, not a miri was stirring — no hint of `unsafe`!*
This PR provides an initial, **incomplete** implementation of *[MCP 411: Lang Item for Transmutability](https://github.com/rust-lang/compiler-team/issues/411 )*. The `core::mem::BikeshedIntrinsicFrom` trait provided by this PR is implemented on-the-fly by the compiler for types `Src` and `Dst` when the bits of all possible values of type `Src` are safely reinterpretable as a value of type `Dst`.
What this PR provides is:
- [x] [support for transmutations involving primitives](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/primitives )
- [x] [support for transmutations involving arrays](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/arrays )
- [x] [support for transmutations involving structs](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/structs )
- [x] [support for transmutations involving enums](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/enums )
- [x] [support for transmutations involving unions](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/unions )
- [x] [support for weaker validity checks](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/unions/should_permit_intersecting_if_validity_is_assumed.rs ) (i.e., `Assume::VALIDITY`)
- [x] visibility checking
What isn't yet implemented:
- [ ] transmutability options passed using the `Assume` struct
- [ ] [support for references](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/references.rs )
- [ ] smarter error messages
These features will be implemented in future PRs.
2022-08-02 21:17:31 +00:00
bors
4493a0f472
Auto merge of #100063 - matthiaskrgr:rollup-lznouys, r=matthiaskrgr
...
Rollup of 7 pull requests
Successful merges:
- #99987 (Always include a position span in `rustc_parse_format::Argument`)
- #100005 (Remove Clean trait for ast::Attribute and improve Attributes::from_ast)
- #100025 (Remove redundant `TransferWrapper` struct)
- #100045 (Properly reject the `may_unwind` option in `global_asm!`)
- #100052 (RISC-V ASM test: relax label name constraint.)
- #100053 (move [`assertions_on_result_states`] to restriction)
- #100057 (Remove more Clean trait implementations)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-02 17:18:58 +00:00
Matthias Krüger
a0991b8ba8
Rollup merge of #99987 - Alexendoo:parse-format-position-span, r=fee1-dead
...
Always include a position span in `rustc_parse_format::Argument`
Moves the spans from the `Position` enum to always be included in the `Argument` struct. Doesn't make any changes to use it in rustc, but it will be useful for some upcoming Clippy lints
2022-08-02 17:17:30 +02: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
957548183d
Remove trait_of_item query.
2022-08-01 21:39:26 +02:00
Camille GILLOT
d7ea161b7e
Remove DefId from AssocItemContainer.
2022-08-01 21:38:45 +02:00
Camille GILLOT
110f0656cb
Store associated item defaultness in impl_defaultness.
2022-08-01 21:38:16 +02:00
Ellen
49d001c5f3
fmt...
2022-08-01 20:15:58 +01:00
Matthias Krüger
4606830f83
Rollup merge of #100012 - TaKO8Ki:avoid-ty-to-string-conversions, r=fee1-dead
...
Avoid `Ty` to `String` conversions
follow-up to #98668
2022-08-01 16:49:34 +02:00
Matthias Krüger
8db3d7cfb6
Rollup merge of #99911 - cjgillot:no-guess, r=davidtwco
...
Remove some uses of `guess_head_span`
That function cuts a span at the first occurrence of `{`. Using `def_span` is almost always more precise.
2022-08-01 16:49:31 +02:00