Matthias Krüger
d5fb8d2aef
Rollup merge of #102592 - WaffleLapkin:less_lifetimes, r=cjgillot
...
Remove a couple lifetimes that can be infered
From the review: https://github.com/rust-lang/rust/pull/101986#discussion_r974497497
r? `@cjgillot`
2022-10-03 08:00:48 +02:00
Michael Goulet
90a8d67491
Avoid ICE in printing RPITIT type
2022-10-02 20:43:13 +00:00
Michael Goulet
d0d6af9146
Lint for unsatisfied nested opaques
2022-10-02 19:50:19 +00:00
Maybe Waffle
8cc8140775
Remove a couple lifetimes that could be infered
2022-10-02 15:40:20 +00:00
Dylan DPC
f3ab5a66a9
Rollup merge of #102538 - cjgillot:def-span-ctxt, r=fee1-dead
...
Give `def_span` the same SyntaxContext as `span_with_body`.
https://github.com/rust-lang/rust/issues/102217
I'm not sure how to add a test, since the erroneous span was crafted using a proc macro.
The debug assertion in `def_span` will ensure we have the correct behaviour.
2022-10-02 20:42:21 +05:30
Michael Goulet
f088e543cb
Delay evaluating lint primary message until after it would be suppressed
2022-10-02 06:32:40 +00:00
Camille GILLOT
9f2ab5b9ad
Use a SortedMap instead of a VecMap.
2022-10-01 16:24:30 +02:00
Camille GILLOT
d08669c4fa
Compute by owner instead of HirId.
2022-10-01 16:22:40 +02:00
Camille GILLOT
26e5fe9e85
Do not fetch HIR node when iterating to find lint.
2022-10-01 16:20:21 +02:00
Camille GILLOT
34bc5c8824
Move lint level computation to rustc_middle::lint.
2022-10-01 16:18:54 +02:00
Camille GILLOT
41db9b152f
Move code to rustc_lint.
2022-10-01 16:18:13 +02:00
Camille GILLOT
107170b9c3
Remove unused tool_name.
2022-10-01 16:12:54 +02:00
Deadbeef
3cb1811e45
Compute lint_levels
by definition
2022-10-01 16:12:50 +02:00
Camille GILLOT
6019cbbfd3
Allow query system to recover a HirId.
2022-10-01 15:58:42 +02:00
bors
744e397d88
Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebank
...
Move lint level source explanation to the bottom
So, uhhhhh
r? `@estebank`
## User-facing change
"note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic:
```diff
- = note: `#[warn(unsupported_calling_conventions)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678 >
+ = note: `#[warn(unsupported_calling_conventions)]` on by default
```
Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO.
## Developer-facing change
`struct_span_lint` and similar methods have a different signature.
Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)`
After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>`
The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion.
Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere.
## Subtle problem
By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings...
I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate.
## P.S.
I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
2022-10-01 10:44:25 +00:00
Maybe Waffle
ad3d1fc9d5
Move lint level source explanation to the bottom
2022-10-01 10:03:06 +00:00
Maybe Waffle
a8f7e244b7
Refactor rustc lint API
2022-10-01 10:03:06 +00:00
Camille GILLOT
c321933e22
Give def_span
the same SyntaxContext as span_with_body
.
2022-10-01 11:38:59 +02:00
Matthias Krüger
05b9f0e360
Rollup merge of #102483 - spastorino:create-defs-on-lowering, r=cjgillot
...
create def ids for impl traits during ast lowering
r? `@cjgillot`
2022-09-30 23:38:25 +02:00
Santiago Pastorino
b2bef02bcd
create def ids for impl traits during ast lowering
2022-09-30 15:12:01 -03:00
Boxy
c1a9cf42b4
make query take (LocalDefId, DefId)
2022-09-30 18:53:32 +01:00
Boxy
86a8a3beb4
make compare_const_impl
a query and use it in instance.rs
2022-09-30 17:47:44 +01:00
est31
2c72ea7748
Stabilize map_first_last
2022-09-30 17:00:07 +02:00
b-naber
e1f735a5d1
don't repeat lifetime names from outer binder in print
2022-09-30 15:44:38 +02:00
Matthias Krüger
25017f8bce
Rollup merge of #101075 - ellishg:rustc_codegen_gcc_diagnostics, r=davidtwco
...
Migrate rustc_codegen_gcc to SessionDiagnostics
As part of #100717 this pr migrates diagnostics to `SessionDiagnostics` for the `rustc_codegen_gcc` crate.
``@rustbot`` label +A-translation
2022-09-30 10:22:36 +02:00
bors
b3aa4997d4
Auto merge of #102164 - compiler-errors:rpitit-foreign, r=TaKO8Ki
...
Serialize return-position `impl Trait` in trait hidden values in foreign libraries
Fixes #101630
2022-09-30 04:24:14 +00:00
bors
1bb8d276c9
Auto merge of #101887 - nnethercote:shrink-Res, r=spastorino
...
Shrink `hir::def::Res`
r? `@spastorino`
2022-09-29 22:45:24 +00:00
bors
9f1a21ae2b
Auto merge of #101893 - oli-obk:lift_derive, r=lcnr
...
Fix perf regression from TypeVisitor changes
Regression occurred in https://github.com/rust-lang/rust/pull/101858#issuecomment-1248732579
Instead of just reverting, we only fixed part of the regression. The main regression was due to actually correctly visiting a type that contains types and consts and should therefor be visited. This is not actually observable (yet?), but we should still do it correctly instead of risking major bugs in the future.
2022-09-29 17:05:00 +00:00
Yuki Okushi
039e9e2160
Rollup merge of #102399 - b-naber:binder-print-ice, r=lcnr
...
Account for use of index-based lifetime names in print of binder
Fixes https://github.com/rust-lang/rust/issues/102374
r? ```@lcnr```
cc ```@steffahn```
2022-09-29 11:42:06 +09:00
Nicholas Nethercote
f07d4efc45
Shrink hir::def::Res
.
...
`Res::SelfTy` currently has two `Option`s. When the second one is `Some`
the first one is never consulted. So we can split it into two variants,
`Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res`
from 24 bytes to 12. This then shrinks `hir::Path` and
`hir::PathSegment`, which are the HIR types that take up the most space.
2022-09-29 08:44:52 +10:00
b-naber
4fdc78e6bf
account for use of index-based lifetime names in print of binder
2022-09-28 12:31:08 +02:00
Noah Lev
4bf789fba7
rustdoc: Queryify is_notable_trait
...
This might help with #102375 .
2022-09-27 17:44:54 -07:00
lcnr
1fc86a63f4
rustc_typeck to rustc_hir_analysis
2022-09-27 10:37:23 +02:00
Matthias Krüger
b02062e886
Rollup merge of #101996 - b-naber:binder-print, r=lcnr
...
Don't duplicate region names for late-bound regions in print of Binder
Fixes https://github.com/rust-lang/rust/issues/101280
2022-09-26 19:19:20 +02:00
b-naber
6118ee343f
address review
2022-09-26 14:21:39 +02:00
b-naber
456f4e8d22
don't duplicate late-bound region names in print of Binder
2022-09-26 13:10:55 +02:00
Pietro Albini
3975d55d98
remove cfg(bootstrap)
2022-09-26 10:14:45 +02:00
fee1-dead
39c6bdc30d
Rollup merge of #102270 - Nilstrieb:delete-useless-benches, r=TaKO8Ki
...
Remove benches from `rustc_middle`
These benches benchmark rust langauge features and not the compiler, so they seem to be in the wrong place here. They also all take <1ns, making them pretty useless. Looking at their git history, they just seem to have been carried around for many, many years. This commit ends their journey.
2022-09-26 13:09:43 +08:00
bors
ff40f2ec95
Auto merge of #101710 - jyn514:move-dep-kind-node, r=cjgillot
...
Move DepKindStruct from rustc_middle to rustc_query_system
Helps with https://github.com/rust-lang/rust/issues/96524 . cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60DepKindStruct.60.20to.20rustc_query_system.20.2396524
r? `@cjgillot`
2022-09-25 21:37:10 +00:00
bors
f5193a9fcc
Auto merge of #95474 - oli-obk:tait_ub, r=jackh726
...
Neither require nor imply lifetime bounds on opaque type for well formedness
The actual hidden type can live arbitrarily longer than any individual lifetime and arbitrarily shorter than all but one of the lifetimes.
fixes #86218
fixes #84305
This is a **breaking change** but it is a necessary soundness fix
2022-09-25 19:15:26 +00:00
Joshua Nelson
00cde6d4b9
Move the codegen_unit
debug assert from rustc_query_system
to query_impl
...
This allows removing a function from the `DepKind` trait.
2022-09-25 12:08:36 -05:00
Joshua Nelson
ccc8d000f2
Move some more code from rustc_middle to rustc_query_system
2022-09-25 12:08:36 -05:00
Joshua Nelson
f3f91bb514
Move functions on DepKindStruct
from rustc_middle to rustc_query_system
2022-09-25 12:07:17 -05:00
Joshua Nelson
93a0fb190e
Move DepKindStruct
from rustc_middle to rustc_query_system
2022-09-25 11:56:23 -05:00
Nilstrieb
ddf7982741
Remove benches from rustc_middle
...
These benches benchmark rust langauge features and not the compiler,
so they seem to be in the wrong place here. They also all take <1ns,
making them pretty useless. Looking at their git history, they just
seem to have been carried around for many, many years. This commit
ends their journey.
2022-09-25 18:35:43 +02:00
bors
d0ece44cfa
Auto merge of #102040 - TaKO8Ki:separate-definitions-and-hir-owners, r=cjgillot
...
Separate definitions and HIR owners in the type system
Fixes #83158
r? `@cjgillot`
2022-09-24 22:42:07 +00:00
Ellis Hoag
ac97487645
fix lifetime error
2022-09-24 11:36:16 -07:00
Ellis Hoag
5c7e629b63
rebase and update trait names
2022-09-24 11:06:05 -07:00
Ellis Hoag
6e22c0a8e1
impl SessionDiagnostic for LayoutError and Spanned<T>
2022-09-24 10:25:19 -07:00
Takayuki Maeda
8fe936099a
separate definitions and HIR
owners
...
fix a ui test
use `into`
fix clippy ui test
fix a run-make-fulldeps test
implement `IntoQueryParam<DefId>` for `OwnerId`
use `OwnerId` for more queries
change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-24 23:21:19 +09:00
Matthias Krüger
bf167e0ae5
Rollup merge of #102088 - oli-obk:cleanups, r=bjorn3
...
Fix wrongly refactored Lift impl
see https://github.com/rust-lang/rust/pull/101858#issuecomment-1252713639
r? ``@bjorn3``
2022-09-24 14:29:53 +02:00
bors
bb5a016175
Auto merge of #102064 - cjgillot:revert, r=Mark-Simulacrum
...
Revert perf-regression 101620
Reverts #101862 #101620
r? `@Mark-Simulacrum`
2022-09-24 09:36:29 +00:00
Matthias Krüger
a842357d37
Rollup merge of #102152 - compiler-errors:issue-102140, r=fee1-dead
...
Calculate `ProjectionTy::trait_def_id` for return-position `impl Trait` in trait correctly
Fixes #102140
2022-09-24 07:38:56 +02:00
bors
e1c28e0c85
Auto merge of #102068 - cjgillot:erased-lifetime-print, r=eholk
...
Always print '_, even for erased lifetimes.
Explicit lifetime arguments are now the recommended syntax in rust 2018 and rust 2021. This PR applies this discipline to rustc itself.
2022-09-24 01:23:17 +00:00
Camille GILLOT
aac2c7ddd8
Always print '_, even for erased lifetimes.
2022-09-23 18:42:14 +02:00
bors
9a963e3bad
Auto merge of #102056 - b-naber:unevaluated, r=lcnr
...
Introduce mir::Unevaluated
Previously the distinction between unevaluated constants in the type-system and in mir was not explicit and a little confusing. Probably better to introduce its own type for that.
r? `@lcnr`
2022-09-23 13:39:11 +00:00
b-naber
a705e65605
rename Unevaluated to UnevaluatedConst
2022-09-23 14:27:34 +02:00
bors
4d44e09cb1
Auto merge of #102165 - matthiaskrgr:rollup-n5oquhe, r=matthiaskrgr
...
Rollup of 8 pull requests
Successful merges:
- #100734 (Split out async_fn_in_trait into a separate feature)
- #101664 (Note if mismatched types have a similar name)
- #101815 (Migrated the rustc_passes annotation without effect diagnostic infrastructure)
- #102042 (Distribute rust-docs-json via rustup.)
- #102066 (rustdoc: remove unnecessary `max-width` on headers)
- #102095 (Deduplicate two functions that would soon have been three)
- #102104 (Set 'exec-env:RUST_BACKTRACE=0' in const-eval-select tests)
- #102112 (Allow full relro on powerpc64-unknown-linux-gnu)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-23 09:33:23 +00:00
Matthias Krüger
c2d2535b84
Rollup merge of #101664 - mejrs:similarity, r=fee1-dead
...
Note if mismatched types have a similar name
If users get a type error between similarly named types, it will point out that these are actually different types, and where they were defined.
2022-09-23 04:29:16 +02:00
Michael Goulet
2fa31d3e78
Serialize RPITIT values in libs
2022-09-23 00:56:55 +00:00
Michael Goulet
79c665b2a3
Calculate ProjectionTy::trait_def_id correctly
2022-09-22 19:49:18 +00:00
Matthias Krüger
aa384834d7
Rollup merge of #102133 - b-naber:use-valtrees-in-fast-reject, r=lcnr
...
Use valtrees for comparison
r? `@lcnr`
2022-09-22 21:34:54 +02:00
Matthias Krüger
b93c9a7d37
Rollup merge of #102128 - oli-obk:const_unification, r=lcnr
...
Const unification is already infallible, remove the error handling logic
r? `@lcnr`
is this expected to be used in the future? Right now it is dead code.
2022-09-22 21:34:53 +02:00
Camille GILLOT
fc43df0333
Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"
...
This reverts commit 2cb9a65684
, reversing
changes made to 750bd1a7ff
.
2022-09-22 19:36:11 +02:00
Camille GILLOT
381bd2a836
Revert "Auto merge of #101862 - cjgillot:lint-regression, r=oli-obk"
...
This reverts commit bc7b17cfe3
, reversing
changes made to 5253b0a0a1
.
2022-09-22 19:34:01 +02:00
b-naber
e8594257f6
use valtrees for comparison
2022-09-22 13:10:53 +02:00
b-naber
efb908991b
address review
2022-09-22 12:35:29 +02:00
b-naber
9f3784df89
introduce mir::Unevaluated
2022-09-22 12:35:28 +02:00
Oli Scherer
13438ee29c
Const unification is already infallible, remove the error handling logic
2022-09-22 08:20:13 +00:00
bors
7a8636c843
Auto merge of #100982 - fee1-dead-contrib:const-impl-requires-const-trait, r=oli-obk
...
Require `#[const_trait]` on `Trait` for `impl const Trait`
r? `@oli-obk`
2022-09-22 04:22:24 +00:00
Jhonny Bill Mena
e52e2344dc
FIX - adopt new Diagnostic naming in newly migrated modules
...
FIX - ambiguous Diagnostic link in docs
UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic
[Gardening] FIX - formatting via `x fmt`
FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way
DELETE - unneeded allow attributes in Handler method
FIX - broken test
FIX - Rebase conflict
UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21 11:43:22 -04:00
Jhonny Bill Mena
5f91719f75
UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
...
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
a3396b2070
UPDATE - rename DiagnosticHandler macro to Diagnostic
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
19b348fed4
UPDATE - rename DiagnosticHandler trait to IntoDiagnostic
2022-09-21 11:39:52 -04:00
Oli Scherer
37928f5986
Neither require nor imply lifetime bounds on opaque type for well formedness
2022-09-21 13:11:54 +00:00
Oli Scherer
3e6c9e5a19
Fix wrongly refactored Lift impl
2022-09-21 08:29:19 +00:00
bors
432abd86f2
Auto merge of #102061 - notriddle:rollup-kwu9vp8, r=notriddle
...
Rollup of 12 pull requests
Successful merges:
- #100250 (Manually cleanup token stream when macro expansion aborts.)
- #101014 (Fix -Zmeta-stats ICE by giving `FileEncoder` file read permissions)
- #101958 (Improve error for when query is unsupported by crate)
- #101976 (MirPhase: clarify that linting is not a semantic change)
- #102001 (Use LLVM C-API to build atomic cmpxchg and fence)
- #102008 (Add GUI test for notable traits element position)
- #102013 (Simplify rpitit handling on lower_fn_decl)
- #102021 (some post-valtree cleanup)
- #102027 (rustdoc: remove `docblock` class from `item-decl`)
- #102034 (rustdoc: remove no-op CSS `h1-6 { border-bottom-color }`)
- #102038 (Make the `normalize-overflow` rustdoc test actually do something)
- #102053 (⬆️ rust-analyzer)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-20 19:10:11 +00:00
Michael Howell
b149c48186
Rollup merge of #102021 - lcnr:tyConst-fun, r=b-naber,BoxyUwU
...
some post-valtree cleanup
r? project-const-generics cc ```@b-naber```
2022-09-20 10:13:01 -07:00
Michael Howell
0d2e57cb04
Rollup merge of #101976 - RalfJung:mir-semantic-phases, r=oli-obk
...
MirPhase: clarify that linting is not a semantic change
r? ```@JakobDegen```
2022-09-20 10:12:58 -07:00
Michael Howell
2c893737a6
Rollup merge of #101958 - hanar3:101666/enhance-error-message, r=oli-obk
...
Improve error for when query is unsupported by crate
This is an improvement to the error message mentioned on #101666 . It seems like a good idea to also add [this link to the rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html ), if explaining the query system in detail is a concern here, but I'm unsure if there is any restrictions on adding links to error messages.
2022-09-20 10:12:58 -07:00
bors
cd8cc91045
Auto merge of #101989 - fee1-dead-contrib:const_trait_impl-assoc-caller-bounds, r=oli-obk
...
make projection bounds with const bounds satisfy const
Fixes #101982 .
2022-09-20 16:24:36 +00:00
bors
4136b59b7d
Auto merge of #99806 - oli-obk:unconstrained_opaque_type, r=estebank
...
Allow patterns to constrain the hidden type of opaque types
fixes #96572
reverts a revert as original PR was a perf regression that was fixed by reverting it: https://github.com/rust-lang/rust/pull/99368#issuecomment-1186587864 )
TODO:
* check if https://github.com/rust-lang/rust/issues/99685 is avoided
2022-09-20 12:09:52 +00:00
Oli Scherer
f841f1b443
Retry with inlining attributes
2022-09-20 09:30:07 +00:00
Matthias Krüger
7697a244cc
Rollup merge of #101881 - TaKO8Ki:remove-unused-struct-field, r=sanxiyn
...
Remove an unused struct field `late_bound`
2022-09-19 17:55:19 +02:00
mejrs
c65866000e
Incorporate feedback
2022-09-19 17:19:45 +02:00
lcnr
c54c5a3c77
DestructuredConst
split mir and ty
2022-09-19 17:00:38 +02:00
lcnr
638b612154
remove ty::Const::from_inline_const
2022-09-19 16:10:18 +02:00
Oli Scherer
18ab705073
Actually visit/fold the types inside CanonicalVarInfos
2022-09-19 14:00:34 +00:00
lcnr
0c3e01d8f6
extend polymorphization hack comment.
2022-09-19 11:44:29 +02:00
lcnr
647052fc04
remove the Subst
trait, always use EarlyBinder
2022-09-19 11:37:27 +02:00
lcnr
d398b54de6
do not implement type traversal for EarlyBinder
2022-09-19 11:28:32 +02:00
bors
efa717bc2d
Auto merge of #101924 - jackh726:revert-static-hrtb-error, r=compiler-errors
...
Re-add HRTB implied static bug note
r? `@compiler-errors` since you reviewed it previously
I deleted a `normalize` call and forgot about it. Whoops.
2022-09-19 04:56:14 +00:00
Deadbeef
ee96ae0a32
make projection bounds with const bounds satisfy const
2022-09-18 18:05:30 +00:00
Ralf Jung
eed6fdb0eb
clarify that linting is not a semantic change
2022-09-18 14:14:42 +02:00
bors
bc7b17cfe3
Auto merge of #101862 - cjgillot:lint-regression, r=oli-obk
...
Do not fetch HIR node when iterating to find lint.
Addresses the regression in https://github.com/rust-lang/rust/pull/101620
2022-09-18 00:46:14 +00:00
hanar3
0405a5d4e9
improve error message for when a query isn't supported
2022-09-17 20:25:37 -03:00
Matthias Krüger
a6b34cd928
Rollup merge of #101713 - Bryanskiy:AccessLevels, r=petrochenkov
...
change AccessLevels representation
Part of RFC (https://github.com/rust-lang/rust/issues/48054 ). This patch implements effective visibility table with basic methods and change AccessLevels table representation according to it.
r? ``@petrochenkov``
2022-09-17 23:30:49 +02:00
bors
48de123d7a
Auto merge of #101857 - lcnr:make-dyn-again, r=jackh726
...
change `FnMutDelegate` to trait objects
cc #100016 as mentioned in the last t-compiler meeting
r? `@jackh726`
2022-09-17 13:37:48 +00:00
Dylan DPC
3ad81e0dd8
Rollup merge of #93628 - est31:stabilize_let_else, r=joshtriplett
...
Stabilize `let else`
🎉 **Stabilizes the `let else` feature, added by [RFC 3137](https://github.com/rust-lang/rfcs/pull/3137 ).** 🎉
Reference PR: https://github.com/rust-lang/reference/pull/1156
closes #87335 (`let else` tracking issue)
FCP: https://github.com/rust-lang/rust/pull/93628#issuecomment-1029383585
----------
## Stabilization report
### Summary
The feature allows refutable patterns in `let` statements if the expression is
followed by a diverging `else`:
```Rust
fn get_count_item(s: &str) -> (u64, &str) {
let mut it = s.split(' ');
let (Some(count_str), Some(item)) = (it.next(), it.next()) else {
panic!("Can't segment count item pair: '{s}'");
};
let Ok(count) = u64::from_str(count_str) else {
panic!("Can't parse integer: '{count_str}'");
};
(count, item)
}
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
```
### Differences from the RFC / Desugaring
Outside of desugaring I'm not aware of any differences between the implementation and the RFC. The chosen desugaring has been changed from the RFC's [original](https://rust-lang.github.io/rfcs/3137-let-else.html#reference-level-explanations ). You can read a detailed discussion of the implementation history of it in `@cormacrelf` 's [summary](https://github.com/rust-lang/rust/pull/93628#issuecomment-1041143670 ) in this thread, as well as the [followup](https://github.com/rust-lang/rust/pull/93628#issuecomment-1046598419 ). Since that followup, further changes have happened to the desugaring, in #98574 , #99518 , #99954 . The later changes were mostly about the drop order: On match, temporaries drop in the same order as they would for a `let` declaration. On mismatch, temporaries drop before the `else` block.
### Test cases
In chronological order as they were merged.
Added by df9a2e0687
(#87688 ):
* [`ui/pattern/usefulness/top-level-alternation.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/pattern/usefulness/top-level-alternation.rs ) to ensure the unreachable pattern lint visits patterns inside `let else`.
Added by 5b95df4bdc
(#87688 ):
* [`ui/let-else/let-else-bool-binop-init.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-bool-binop-init.rs ) to ensure that no lazy boolean expressions (using `&&` or `||`) are allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-brace-before-else.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-brace-before-else.rs ) to ensure that no `}` directly preceding the `else` is allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-check.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-check.rs ) to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for the `else` block.
* [`ui/let-else/let-else-irrefutable.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-irrefutable.rs ) to ensure that the `irrefutable_let_patterns` lint fires.
* [`ui/let-else/let-else-missing-semicolon.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-missing-semicolon.rs ) to ensure the presence of semicolons at the end of the `let` statement.
* [`ui/let-else/let-else-non-diverging.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-non-diverging.rs ) to ensure the `else` block diverges.
* [`ui/let-else/let-else-run-pass.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-run-pass.rs ) to ensure the feature works in some simple test case settings.
* [`ui/let-else/let-else-scope.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-scope.rs ) to ensure the bindings created by the outer `let` expression are not available in the `else` block of it.
Added by bf7c32a447
(#89965 ):
* [`ui/let-else/issue-89960.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/issue-89960.rs ) as a regression test for the ICE-on-error bug #89960 . Later in 102b9125e1
this got removed in favour of more comprehensive tests.
Added by 856541963c
(#89974 ):
* [`ui/let-else/let-else-if.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-if.rs ) to test for the improved error message that points out that `let else if` is not possible.
Added by 9b45713b6c
:
* [`ui/let-else/let-else-allow-unused.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-unused.rs ) as a regression test for #89807 , to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for bindings created by the `let else` pattern.
Added by 61bcd8d307
(#89841 ):
* [`ui/let-else/let-else-non-copy.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-non-copy.rs ) to ensure that a copy is performed out of non-copy wrapper types. This mirrors `if let` behaviour. The test case bases on rustc internal changes originally meant for #89933 but then removed from the PR due to the error prior to the improvements of #89841 .
* [`ui/let-else/let-else-source-expr-nomove-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-source-expr-nomove-pass.rs ) to ensure that while there is a move of the binding in the successful case, the `else` case can still access the non-matching value. This mirrors `if let` behaviour.
Added by 102b9125e1
(#89841 ):
* [`ui/let-else/let-else-ref-bindings.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings.rs ) and [`ui/let-else/let-else-ref-bindings-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings-pass.rs ) to check `ref` and `ref mut` keywords in the pattern work correctly and error when needed.
Added by 2715c5f984
(#89841 ):
* Match ergonomic tests adapted from the `rfc2005` test suite.
Added by fec8a507a2
(#89841 ):
* [`ui/let-else/let-else-deref-coercion-annotated.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion-annotated.rs ) and [`ui/let-else/let-else-deref-coercion.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion.rs ) to check deref coercions.
#### Added since this stabilization report was originally written (2022-02-09)
Added by 76ea566677
(#94211 ):
* [`ui/let-else/let-else-destructuring.rs`](https://github.com/rust-lang/rust/blob/1.63.0/src/test/ui/let-else/let-else-destructuring.rs ) to give a nice error message if an user tries to do an assignment with a (possibly refutable) pattern and an `else` block, like asked for in #93995 .
Added by e7730dcb7e
(#94208 ):
* [`ui/let-else/let-else-allow-in-expr.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-in-expr.rs ) to test whether `#[allow(unused_variables)]` works in the expr, as well as its non presence, as well as putting it on the entire `let else` *affects* the expr, too. This was adding a missing test as pointed out by the stabilization report.
* Expansion of `ui/let-else/let-else-allow-unused.rs` and `ui/let-else/let-else-check.rs` to ensure that non-presence of `#[allow(unused)]` does issue the unused lint. This was adding a missing test case as pointed out by the stabilization report.
Added by 5bd71063b3
(#94208 ):
* [`ui/let-else/let-else-slicing-error.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-slicing-error.rs ), a regression test for #92069 , which got fixed without addition of a regression test. This resolves a missing test as pointed out by the stabilization report.
Added by 5374688e1d
(#98574 ):
* [`src/test/ui/async-await/async-await-let-else.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/async-await/async-await-let-else.rs ) to test the interaction of async/await with `let else`
Added by 6c529ded86
(#98574 ):
* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs ) as a (partial) regression test for #98672
Added by 9b56640106
(#99518 ):
* [`src/test/ui/let-else/let-else-temp-borrowck.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs ) as a regression test for #93951
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #98672 (especially regarding `else` drop order)
Added by baf9a7cb57
(#99518 ):
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #93951 , similar to `let-else-temp-borrowck.rs`
Added by 60be2de8b7
(#99518 ):
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a program that can now be compiled thanks to borrow checker implications of #99518
Added by 47a7a91c96
(#100132 ):
* [`src/test/ui/let-else/issue-100103.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-100103.rs ), as a regression test for #100103 , to ensure that there is no ICE when doing `Err(...)?` inside else blocks.
Added by e3c5bd617d
(#100443 ):
* [`src/test/ui/let-else/let-else-then-diverge.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-then-diverge.rs ), to verify that there is no unreachable code error with the current desugaring.
Added by 981852677c
(#100443 ):
* [`src/test/ui/let-else/issue-94176.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-94176.rs ), to make sure that a correct span is emitted for a missing trailing expression error. Regression test for #94176 .
Added by e182d12a84
(#100434 ):
* [src/test/ui/unpretty/pretty-let-else.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/unpretty/pretty-let-else.rs ), as a regression test to ensure pretty printing works for `let else` (this bug surfaced in many different ways)
Added by e26285603c
(#99954 ):
* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs ) extended to contain & borrows as well, as this was identified as an earlier issue with the desugaring: https://github.com/rust-lang/rust/issues/98672#issuecomment-1200196921
Added by 2d8460ef43
(#99291 ):
* [`src/test/ui/let-else/let-else-drop-order.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-drop-order.rs ) a matrix based test for various drop order behaviour of `let else`. Especially, it verifies equality of `let` and `let else` drop orders, [resolving](https://github.com/rust-lang/rust/pull/93628#issuecomment-1238498468 ) a [stabilization blocker](https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523 ).
Added by 1b87ce0d40
(#101410 ):
* Edit to `src/test/ui/let-else/let-else-temporary-lifetime.rs` to add the `-Zvalidate-mir` flag, as a regression test for #99228
Added by af591ebe4d
(#101410 ):
* [`src/test/ui/let-else/issue-99975.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-99975.rs ) as a regression test for the ICE #99975 .
Added by this PR:
* `ui/let-else/let-else.rs`, a simple run-pass check, similar to `ui/let-else/let-else-run-pass.rs`.
### Things not currently tested
* ~~The `#[allow(...)]` tests check whether allow works, but they don't check whether the non-presence of allow causes a lint to fire.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~There is no `#[allow(...)]` test for the expression, as there are tests for the pattern and the else block.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~`let-else-brace-before-else.rs` forbids the `let ... = {} else {}` pattern and there is a rustfix to obtain `let ... = ({}) else {}`. I'm not sure whether the `.fixed` files are checked by the tooling that they compile. But if there is no such check, it would be neat to make sure that `let ... = ({}) else {}` compiles.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~#92069 got closed as fixed, but no regression test was added. Not sure it's worth to add one.~~ → *test added by 5bd71063b3810d977aa376d1e6dd7cec359330cc*
* ~~consistency between `let else` and `if let` regarding lifetimes and drop order: https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523~~ → *test added by 2d8460ef43d902f34ba2133fe38f66ee8d2fdafc*
Edit: they are all tested now.
### Possible future work / Refutable destructuring assignments
[RFC 2909](https://rust-lang.github.io/rfcs/2909-destructuring-assignment.html ) specifies destructuring assignment, allowing statements like `FooBar { a, b, c } = foo();`.
As it was stabilized, destructuring assignment only allows *irrefutable* patterns, which before the advent of `let else` were the only patterns that `let` supported.
So the combination of `let else` and destructuring assignments gives reason to think about extensions of the destructuring assignments feature that allow refutable patterns, discussed in #93995 .
A naive mapping of `let else` to destructuring assignments in the form of `Some(v) = foo() else { ... };` might not be the ideal way. `let else` needs a diverging `else` clause as it introduces new bindings, while assignments have a default behaviour to fall back to if the pattern does not match, in the form of not performing the assignment. Thus, there is no good case to require divergence, or even an `else` clause at all, beyond the need for having *some* introducer syntax so that it is clear to readers that the assignment is not a given (enums and structs look similar). There are better candidates for introducer syntax however than an empty `else {}` clause, like `maybe` which could be added as a keyword on an edition boundary:
```Rust
let mut v = 0;
maybe Some(v) = foo(&v);
maybe Some(v) = foo(&v) else { bar() };
```
Further design discussion is left to an RFC, or the linked issue.
2022-09-17 15:31:06 +05:30
bors
c524c7dd25
Auto merge of #98588 - b-naber:valtrees-cleanup, r=lcnr
...
Use only ty::Unevaluated<'tcx, ()> in type system
r? `@lcnr`
2022-09-17 03:04:22 +00:00