Esteban Küber
3a471b5fd8
Account for x @ y
and suggest ref x @ ref y
2022-11-23 12:17:48 -08:00
b-naber
c39de61d2a
include closures and generators in try_compute_field_ty
2022-11-23 20:55:17 +01:00
b-naber
4040734e44
get field ty during projecting
2022-11-23 20:55:15 +01:00
b-naber
fd6fed3027
address review
2022-11-23 20:01:53 +01:00
b-naber
f015842ed2
properly handle enum field projections
2022-11-23 20:01:11 +01:00
b-naber
4d3a91b12b
use non-ascribed type as field type in mir
2022-11-23 19:59:00 +01:00
b-naber
ac31d52324
implement PlaceBuilder::try_ty
2022-11-23 19:58:56 +01:00
bors
80b3c6dbde
Auto merge of #103947 - camsteffen:place-clones, r=cjgillot
...
Reduce `PlaceBuilder` cloning
Some API tweaks with an eye towards reducing clones.
2022-11-23 13:13:50 +00:00
bors
66ccf36f16
Auto merge of #104711 - Dylan-DPC:rollup-gkw1qr8, r=Dylan-DPC
...
Rollup of 6 pull requests
Successful merges:
- #104295 (Check generics parity before collecting return-position `impl Trait`s in trait)
- #104464 (Reduce exceptions overallocation on non Windows x86_64)
- #104615 (Create def_id for async fns during lowering)
- #104669 (Only declare bindings for if-let guards once per arm)
- #104701 (Remove a lifetime resolution hack from `compare_predicate_entailment`)
- #104710 (disable strict-provenance-violating doctests in Miri)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-22 13:18:45 +00:00
Dylan DPC
d29491aba0
Rollup merge of #104669 - LeSeulArtichaut:88015-if-let-guard-bindings, r=cjgillot
...
Only declare bindings for if-let guards once per arm
Currently, each candidate for a match arm uses separate locals for the bindings in the if-let guard, causing problems (#88015 ) when those branches converge in the arm body.
Fixes #88015 (🤞 )
2022-11-22 16:36:38 +05:30
bors
b7463e8bdb
Auto merge of #103578 - petrochenkov:nofict, r=nagisa
...
Unreserve braced enum variants in value namespace
With this PR braced enum variants (`enum E { V { /*...*/ } }`) no longer take a slot in value namespace, so the special case mentioned in the note in https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md#braced-structs is removed.
Report - https://github.com/rust-lang/rust/pull/103578#issuecomment-1292594900 .
2022-11-22 10:17:09 +00:00
Oli Scherer
c2ecd8f1f6
merge self type and substs in trait_method
2022-11-21 20:41:17 +00:00
Oli Scherer
7658e0fccf
Stop passing the self-type as a separate argument.
2022-11-21 20:39:46 +00:00
Oli Scherer
4d9451b1d1
Fix an ICE that I just made worse
2022-11-21 20:36:15 +00:00
Oli Scherer
25c4760b5d
Some cleanup around trait_method lookup
2022-11-21 20:34:56 +00:00
Oli Scherer
9e4c3f41c1
Use iterators instead of slices at more sites
2022-11-21 20:34:28 +00:00
Oli Scherer
ec8d01fdcc
Allow iterators instead of requiring slices that will get turned into iterators
2022-11-21 20:33:55 +00:00
Oli Scherer
6f77c97b38
Assert that various types have the right amount of generic args and fix the sites that used the wrong amount
2022-11-21 20:31:59 +00:00
Oli Scherer
0c47deed9f
Reduce the amount of passed-around arguments that will get merged into one later anyway
2022-11-21 20:28:48 +00:00
Vadim Petrochenkov
7a5376d23c
Unreserve braced enum variants in value namespace
2022-11-21 22:40:06 +03:00
Léo Lanteri Thauvin
baa59d1a77
Only declare bindings for if-let guards once per arm
2022-11-21 12:45:29 +01:00
Cameron Steffen
cc8dddbac9
Factor out conservative_is_privately_uninhabited
2022-11-20 19:04:11 -06:00
Cameron Steffen
34cbe72780
Change to Ty::is_inhabited_from
2022-11-20 19:04:11 -06:00
Matthias Krüger
820a41580e
Rollup merge of #104564 - RalfJung:either, r=oli-obk
...
interpret: use Either over Result when it is not representing an error condition
r? `@oli-obk`
2022-11-20 18:21:48 +01:00
Ralf Jung
09a887cebf
review feedback
2022-11-18 14:24:48 +01:00
Ralf Jung
4101889786
interpret: use Either over Result when it is not representing an error condition
2022-11-18 10:18:32 +01:00
Deadbeef
bc51f8783c
rename to string_deref_patterns
2022-11-18 06:16:20 +00:00
Cameron Steffen
9cf6ce070d
Remove more PlaceBuilder clones
2022-11-17 19:01:05 -06:00
Cameron Steffen
105abe39c0
Replace into_place with to_place
2022-11-17 19:01:05 -06:00
Cameron Steffen
be5b7778c8
Replace try_upvars_resolved with try_to_place
2022-11-17 19:01:05 -06:00
Cameron Steffen
1c819792a7
Introduce PlaceBuilder::resolve_upvar by ref
2022-11-17 19:01:05 -06:00
Deadbeef
b2cb42d6a7
Minimal implementation of implicit deref patterns
2022-11-17 12:46:43 +00:00
bors
7c75fe4c85
Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead
...
Record `LocalDefId` in HIR nodes instead of a side table
This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840 ), by controlling how `def_id` information is accessed.
This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.
2022-11-17 07:42:27 +00:00
Maybe Waffle
94470f4efd
Use as_deref
in compiler (but only where it makes sense)
2022-11-16 21:58:58 +00:00
Matthias Krüger
5763fa74f0
Rollup merge of #104349 - rustaceanclub:master, r=oli-obk
...
fix some typos in comments
2022-11-14 19:26:18 +01:00
Camille GILLOT
607d0c2a14
Store a LocalDefId in hir::AnonConst.
2022-11-13 14:06:11 +00:00
Camille GILLOT
18482f7b23
Store a LocalDefId in hir::GenericParam.
2022-11-13 14:05:30 +00:00
cui fliter
442f848d74
fix some typos in comments
...
Signed-off-by: cui fliter <imcusg@gmail.com>
2022-11-13 15:26:17 +08:00
Michael Goulet
93921dd16d
Don't ICE with inline const errors during MIR build
2022-11-11 17:21:58 +00:00
Michael Goulet
0f89fb1791
Use const_error_with_guaranteed more
2022-11-10 05:39:15 +00:00
Jakob Degen
ba359d8a51
Add support for custom MIR parsing
2022-11-08 23:13:15 -08:00
Matthias Krüger
b101f3a865
Rollup merge of #103984 - V0ldek:103974-refactor-mk_const, r=BoxyUwU
...
Refactor tcx mk_const parameters.
Unroll the `ty::ConstS` parameter to `TyCtxt::mk_const` into separate `ty::ConstKind` and `Ty` parameters.
Signature change is in:
c97fd8183a/compiler/rustc_middle/src/ty/context.rs (L2234)
and
c97fd8183a/compiler/rustc_middle/src/ty/context.rs (L2572-L2575)
the rest is callsites.
Closes #103974
r? `@oli-obk`
2022-11-05 00:02:06 +01:00
Mateusz
c97fd8183a
Refactor tcx mk_const parameters.
2022-11-04 20:33:32 +00:00
Cameron Steffen
e7bae89a3c
Cleanup bind_pattern args
2022-11-03 19:33:59 -05:00
Dylan DPC
94241e7eaf
Rollup merge of #103584 - ouz-a:issue-102303, r=oli-obk
...
Remove bounds check when array is indexed by enum
As the title says, this reverts the behavior introduced with 1.64.
Fixes #102303
r? `@oli-obk`
2022-11-01 14:12:25 +05:30
Yuki Okushi
2a6a8f4d30
Rollup merge of #103749 - est31:reduce_irrefutable_let_else_span, r=cjgillot
...
Reduce span of let else irrefutable_let_patterns warning
Huge spans aren't good for IDE users as they underline constructs that are possibly multiline.
Similar PR to #90761 which did the same for the `unused_macros` lint.
2022-11-01 12:03:41 +09:00
ouz-a
a1672ad5b8
Remove bounds check with enum cast
2022-10-31 14:10:37 +03:00
est31
7b55d17a2f
Reduce span of let else irrefutable_let_patterns warning
...
Huge spans aren't good for IDE users as they underline constructs that
are possibly multiline.
2022-10-30 05:05:21 +01:00
Matthias Krüger
2bff9e2193
Rollup merge of #103726 - TaKO8Ki:avoid-&str-to-string-conversions, r=compiler-errors
...
Avoid unnecessary `&str` to `String` conversions
2022-10-30 00:09:26 +02:00
Takayuki Maeda
a3a3f4d840
avoid unnecessary &str
to String
conversions
2022-10-29 17:14:44 +09:00
Maybe Waffle
a17ccfa621
Accept TyCtxt
instead of TyCtxtAt
in Ty::is_*
functions
...
Functions in answer:
- `Ty::is_freeze`
- `Ty::is_sized`
- `Ty::is_unpin`
- `Ty::is_copy_modulo_regions`
2022-10-27 15:06:08 +04:00
Michael Goulet
6e6fe30d0f
Comment why normalization is needed for debug assertions
2022-10-23 17:23:35 +00:00
Cameron Steffen
2928e9ef2c
Introduce InhabitedPredicate
2022-10-22 13:20:06 -05:00
bors
b15e2c129e
Auto merge of #101832 - compiler-errors:dyn-star-plus, r=eholk
...
Make `dyn*` casts into a coercion, allow `dyn*` upcasting
I know that `dyn*` is likely not going to be a feature exposed to surface Rust, but this makes it slightly more ergonomic to write tests for these types anyways. ... and this was just fun to implement anyways.
1. Make `dyn*` into a coercion instead of a cast
2. Enable `dyn*` upcasting since we basically get it for free
3. Simplify some of the cast checking code since we're using the coercion path now
r? `@eholk` but feel free to reassign
cc `@nikomatsakis` and `@tmandry` who might care about making `dyn*` casts into a coercion
2022-10-15 07:36:38 +00:00
Dylan DPC
7cf09c57a2
Rollup merge of #103031 - est31:match_guard_irrefutable_let, r=oli-obk
...
Suppress irrefutable let patterns lint for prefixes in match guards
In match guards, irrefutable prefixes might use the bindings created by the match pattern. Ideally, we check for this, but we can do the next best thing and just not lint for irrefutable prefixes in match guards.
Fixes #98361
2022-10-14 16:19:16 +05:30
Dylan DPC
77064b7f0a
Rollup merge of #103018 - Rageking8:more-dupe-word-typos, r=TaKO8Ki
...
More dupe word typos
I only picked those changes (from the regex search) that I am pretty certain doesn't change meaning and is just a typo fix. Do correct me if any fix is undesirable and I can revert those. Thanks.
2022-10-14 16:19:15 +05:30
Rageking8
7122abaddf
more dupe word typos
2022-10-14 12:57:56 +08:00
Michael Goulet
76386bd65e
Make dyn* cast into a coercion
2022-10-14 04:27:01 +00:00
est31
eab41a136a
Suppress irrefutable let patterns lint for prefixes in match guards
...
In match guards, irrefutable prefixes might use the bindings created
by the match pattern. Ideally, we check for this, but we can do the
next best thing and just not lint for irrefutable prefixes in match
guards.
2022-10-14 02:16:40 +02:00
Gary Guo
de0396c718
Ensure enum cast moves
2022-10-13 16:44:47 +01:00
Dylan DPC
5a09b72156
Rollup merge of #102853 - cjgillot:skip-opaque-cast, r=jackh726
...
Skip chained OpaqueCast when building captures.
Fixes https://github.com/rust-lang/rust/issues/102089
2022-10-10 13:43:42 +05:30
Camille GILLOT
e828ce53b9
Skip chained OpaqueCast when building captures.
2022-10-09 16:18:16 +00:00
Eric Huss
be1c7aad72
Show let-else suggestion on stable.
2022-10-08 14:39:25 -07:00
Matthias Krüger
c731646d6a
Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk
...
Remove `mir::CastKind::Misc`
As discussed in #97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.
r? ````@oli-obk````
2022-10-08 14:38:18 +02:00
Cameron Steffen
283abbf0e7
Change InferCtxtBuilder from enter to build
2022-10-07 07:10:40 -05:00
Cameron Steffen
349415d1c6
Remove TypeckResults from InferCtxt
2022-10-07 07:06:19 -05:00
ouz-a
d59c7ff000
Remove mir::CastKind::Misc
2022-10-06 15:32:41 +03:00
bors
0152393048
Auto merge of #99324 - reez12g:issue-99144, r=jyn514
...
Enable doctests in compiler/ crates
Helps with https://github.com/rust-lang/rust/issues/99144
2022-10-06 03:01:57 +00:00
bors
c97d02cdb5
Auto merge of #102394 - dingxiangfei2009:issue-102317, r=oli-obk
...
Fix unwind drop glue for if-then scopes
cc `@est31`
Fix #102317
Fix #99852
This PR fixes the drop glue for unwinding from a panic originated in a drop while breaking out for the else block in an `if-then` scope.
MIR validation does not fail for the synchronous versions of the test program, because `StorageDead` statements are skipped over in the unwinding process. It is only becoming a problem when it is inside a generator where `StorageDead` must be kept around.
2022-10-05 20:47:39 +00:00
Ding Xiang Fei
565c35aa5c
fix doc and dedup diverge_cleanup
2022-10-05 22:24:12 +08: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
a8f7e244b7
Refactor rustc lint API
2022-10-01 10:03:06 +00:00
X
fb52dc7c3b
apply suggestion
...
Co-authored-by: SafariMonkey <charlton.rodda@gmail.com>
2022-09-30 21:03:08 +08: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
Oli Scherer
f22f149dbd
Some path updates
2022-09-29 09:33:30 +00:00
reez12g
9a4c5abe45
Remove from compiler/ crates
2022-09-29 16:49:04 +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
Ding Xiang Fei
4a2c1a12b6
fix unwind drop glue for if-then scopes
2022-09-28 18:45:11 +08:00
lcnr
1fc86a63f4
rustc_typeck to rustc_hir_analysis
2022-09-27 10:37:23 +02:00
bors
1d1f142660
Auto merge of #102257 - cjgillot:let-else-lint, r=dingxiangfei2009
...
Fix lint scoping for let-else.
The scoping for let-else is inconsistent with HIR nesting. This creates cases, in `ui/let-else/let-else-allow-unused.rs` for instance, where an `allow` lint attribute does not apply to the bindings created by `let-else`.
This PR is an attempt to correct this.
As there is no lint that currently relies on this, the test for this behaviour is https://github.com/rust-lang/rust/pull/101500 .
cc `@dingxiangfei2009` as you filed https://github.com/rust-lang/rust/pull/101894
2022-09-26 17:17:07 +00:00
Pietro Albini
3975d55d98
remove cfg(bootstrap)
2022-09-26 10:14:45 +02:00
Camille GILLOT
73c52bc4dc
Fix scoping for let-else.
2022-09-25 11:30:49 +02:00
b-naber
a705e65605
rename Unevaluated to UnevaluatedConst
2022-09-23 14:27:34 +02:00
b-naber
9f3784df89
introduce mir::Unevaluated
2022-09-22 12:35:28 +02: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
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
bors
2019147c56
Auto merge of #101894 - dingxiangfei2009:let-else-avoid-duplicate-storage-live, r=oli-obk
...
Avoid duplicating StorageLive in let-else
cc `@est31`
Fix #101867
Fix #101932
#101410 introduced directives to activate storages of bindings in let-else earlier. However, since it is using the machinery of `match` and friends for pattern matching and binding, those storages are activated for the second time. This PR adjusts this behavior and avoid the duplicated activation for let-else statements.
2022-09-19 17:27:30 +00:00
Oli Scherer
1905f8c441
Document projection condition
2022-09-19 15:33:36 +00:00
lcnr
526856768d
ctfe, const_to_op
only for mir constants
2022-09-19 16:17:33 +02:00
lcnr
647052fc04
remove the Subst
trait, always use EarlyBinder
2022-09-19 11:37:27 +02:00
Ding Xiang Fei
48c1c1d190
avoid duplicating StorageLive in let-else
2022-09-18 12:10:53 +08: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
Oli Scherer
dab1074b91
Only generate OpaqueCast
for opaque types
2022-09-16 11:37:50 +00:00
Oli Scherer
40e2de8c41
Revert "Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank""
...
This reverts commit 4a742a691e
.
2022-09-16 11:36:39 +00:00
Oli Scherer
5d664f7a8f
Merge two arguments into one
2022-09-16 11:36:09 +00:00
est31
173eb6f407
Only enable the let_else feature on bootstrap
...
On later stages, the feature is already stable.
Result of running:
rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
est31
5633e863bd
Remove feature gate from let else suggestion
...
The let else suggestion added by 0d92752b8a
does not need a feature gate any more.
2022-09-15 21:06:45 +02:00
Ding Xiang Fei
4a5d2a561c
add diagram to explain the MIR structure
2022-09-15 10:08:14 +08:00
Ding Xiang Fei
c7d1c9b66f
add explanatory note
2022-09-15 10:08:13 +08:00
Ding Xiang Fei
34f0c4502f
supplement for the missing or incomplete comments
2022-09-15 10:08:11 +08:00
Ding Xiang Fei
1b87ce0d40
reorder nesting scopes and declare bindings without drop schedule
2022-09-15 10:07:54 +08:00
bors
6153d3cbe6
Auto merge of #101212 - eholk:dyn-star, r=compiler-errors
...
Initial implementation of dyn*
This PR adds extremely basic and incomplete support for [dyn*](https://smallcultfollowing.com/babysteps//blog/2022/03/29/dyn-can-we-make-dyn-sized/ ). The goal is to get something in tree behind a flag to make collaboration easier, and also to make sure the implementation so far is not unreasonable. This PR does quite a few things:
* Introduce `dyn_star` feature flag
* Adds parsing for `dyn* Trait` types
* Defines `dyn* Trait` as a sized type
* Adds support for explicit casts, like `42usize as dyn* Debug`
* Including const evaluation of such casts
* Adds codegen for drop glue so things are cleaned up properly when a `dyn* Trait` object goes out of scope
* Adds codegen for method calls, at least for methods that take `&self`
Quite a bit is still missing, but this gives us a starting point. Note that this is never intended to become stable surface syntax for Rust, but rather `dyn*` is planned to be used as an implementation detail for async functions in dyn traits.
Joint work with `@nikomatsakis` and `@compiler-errors.`
r? `@bjorn3`
2022-09-14 18:10:51 +00:00
b-naber
6af8fb7936
address review again
2022-09-14 17:30:25 +02:00
Camille GILLOT
f3a37ed574
Shrink some visibilities.
2022-09-13 19:18:24 +02:00
Camille GILLOT
af128b0144
Also compute implicit params in THIR.
2022-09-13 19:18:24 +02:00
Camille GILLOT
445841cda3
Compute explicit MIR params on THIR.
2022-09-13 19:18:23 +02:00
Camille GILLOT
f76594a0bc
Simplify MIR building entry.
2022-09-13 19:18:23 +02:00
Camille GILLOT
1f370d9437
Use tcx.hir() utils for spans in MIR building.
...
This corrects the `span_with_body` in the case of closures, which was
incorrectly shortened to the `def_span`.
2022-09-13 19:18:23 +02:00
Camille GILLOT
ffe20d61d6
Only keep one version of ImplicitSelfKind.
2022-09-13 19:18:23 +02:00
b-naber
a4bbb8db5c
use ty::Unevaluated<'tcx, ()> in type system
2022-09-13 17:40:59 +02:00
Eric Holk
c5441acf67
Call destructors when dyn* object goes out of scope
2022-09-12 16:55:57 -07:00
Eric Holk
549c105bb3
dyn* through more typechecking and MIR
2022-09-12 16:55:56 -07:00
bors
2e44c17c12
Auto merge of #100968 - cjgillot:mir-upvar-vec, r=wesleywiser
...
Only compute captures once when building MIR.
2022-09-10 12:07:29 +00:00
Camille Gillot
bcbd183ca3
Remove unused temp.
...
Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2022-09-10 12:10:04 +02:00
bors
24d6992020
Auto merge of #101467 - nnethercote:shrink-hir-Ty-Pat, r=spastorino
...
Shrink `hir::Ty` and `hir::Pat`
r? `@ghost`
2022-09-08 13:11:57 +00:00
Dylan DPC
0d61a507f5
Rollup merge of #101399 - cjgillot:borrowck-binding-span, r=estebank
...
Shrink span for bindings with subpatterns.
Bindings with nested patterns (`binding @ pat` syntax) currently point to the full pattern. This PR proposes to shrink the span to stop before the ````@`.``` This makes the diagnostics for move/mutability conflicts clearer, as they not point to the `binding` only, instead of the full pat.
r? ```@estebank```
2022-09-08 11:55:06 +05:30
Nicholas Nethercote
e67f39f8bc
Introduce DotDotPos
.
...
This shrinks `hir::Pat` from 88 to 72 bytes.
2022-09-08 15:25:50 +10:00
Camille GILLOT
5d94d42485
Shrink span for bindings with subpatterns.
2022-09-06 20:57:44 +02:00
Guillaume Gomez
d13aefdc65
Rollup merge of #101357 - compiler-errors:variant-sugg-tweak, r=oli-obk
...
Include enum path in variant suggestion
(except for `Result` and `Option`, which we should have via the prelude)
Fixes #101356
2022-09-06 17:00:25 +02:00
Takayuki Maeda
fea1c5f5c8
refactor: remove unnecessary variables
2022-09-05 22:31:02 +09:00
Takayuki Maeda
87c6da363f
separate the receiver from arguments in HIR
2022-09-05 22:25:49 +09:00
Michael Goulet
be53bd8380
Include enum path in variant suggestion
2022-09-03 08:11:17 +00:00
Nicholas Nethercote
43a0268f3a
Use boxed slices in PatKind
.
...
To shrink it a little more.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
a40124e01c
Box CanonicalUserTypeAnnotation::CanonicalUserType
.
...
This shrinks `Ascription`, which shrinks `PatKind::AscribeUserType`,
which shrinks `Pat`.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
2c4c8eb1a3
Box PatKind::Range
.
...
Because it's the biggest variant. Also, make `PatRange` non-`Copy`,
because it's 104 bytes, which is pretty big.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
bd1e6836a0
Avoid some clones.
...
`Builder::expr_into_pattern` has a single call site. Currently the
`pattern` argument at the call site is always cloned.
This commit changes things so that we instead do a clone within
`expr_into_pattern`, but only if the pattern has the
`PatKind::AscribeUserType` kind, and we only clone the annotation within
the pattern instead of the entire pattern.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
053874eecc
Clean up THIR patterns.
...
`thir::Pat::kind` is a `Box<PatKind>`, which doesn't follow the usual
pattern in AST/HIR/THIR which is that the "kind" enum for a node is
stored inline within the parent struct.
This commit makes the `PatKind` directly inline within the `Pat`. This
requires using `Box<Pat>` in all the types that hold a `Pat.
Ideally, `Pat` would be stored in `Thir` like `Expr` and `Stmt` and
referred to with a `PatId` rather than `Box<Pat>`. But this is hard to
do because lots of `Pat`s get created after the destruction of the `Cx`
that does normal THIR building. But this does get us a step closer to
`PatId`, because all the `Box<Pat>` occurrences would be replaced with
`PatId` if `PatId` ever happened.
At 128 bytes, `Pat` is large. Subsequent commits will shrink it.
2022-09-02 07:26:17 +10:00
Oli Scherer
1fc9ef1edd
tracing::instrument cleanup
2022-09-01 14:54:27 +00:00
Oli Scherer
ee3c835018
Always import all tracing macros for the entire crate instead of piecemeal by module
2022-09-01 14:54:27 +00:00
Oli Scherer
d3b22c7267
Directly use the instrument
macro instead of its full path
2022-09-01 14:53:46 +00:00
Dezhi Wu
b1430fb7ca
Fix a bunch of typo
...
This PR will fix some typos detected by [typos].
I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.
[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Nilstrieb
d1ef8180f9
Revert let_chains stabilization
...
This reverts commit 3266460749
.
This is the revert against master, the beta revert was already done in #100538 .
2022-08-29 19:34:11 +02:00
Matthias Krüger
d182081de1
Rollup merge of #99027 - tmiasko:basic-blocks, r=oli-obk
...
Replace `Body::basic_blocks()` with field access
Since the refactoring in #98930 , it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.
Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
2022-08-29 06:34:43 +02:00
Tomasz Miąsko
b48870b451
Replace Body::basic_blocks()
with field access
2022-08-26 14:27:08 +02:00
bors
8a13871b69
Auto merge of #100944 - nnethercote:shrink-thir-Expr, r=cjgillot
...
Shrink `thir::Expr`
r? `@cjgillot`
2022-08-26 10:00:27 +00:00
Yuki Okushi
b3f178350a
Rollup merge of #99954 - dingxiangfei2009:break-out-let-else-higher-up, r=oli-obk
...
let-else: break out to one scope higher for let-else
```@est31``` This PR follows up with #99518 which is to break out to the last remainder scope. It breaks to the out-most `region_scope` of the block if the first statement is a `let-else`.
2022-08-25 08:50:55 +09:00
Nicholas Nethercote
e3755c1d54
Rename thir::Adt
as thir::AdtExpr
.
...
This matches the naming scheme used elsewhere, e.g. in the AST, and
avoids name clashes with the `ExprKind::Closure` variant.
2022-08-24 15:06:50 +10:00
Nicholas Nethercote
e57ac764b8
Box thir::ExprKind::InlineAsm
.
...
This shrinks `thir::Expr`.
2022-08-24 15:06:50 +10:00
Nicholas Nethercote
b3245a8dff
Box thir::ExprKind::Closure
.
...
This shrinks `thir::Expr`.
2022-08-24 15:06:50 +10:00
Nicholas Nethercote
2df805fc7a
Store blocks in Thir
.
...
Like expressions, statements, and match arms. This shrinks `thir::Stmt`
and is a precursor to further shrinking `thir::Expr`.
2022-08-24 15:06:44 +10:00
Nicholas Nethercote
e7c25c3a97
Box user_ty
fields in thir::ExprKind
.
...
This shrinks several large variants of `ExprKind`.
2022-08-24 14:16:09 +10:00
Camille GILLOT
389c6041a4
Only compute captures once when building MIR.
2022-08-23 22:24:43 +02:00
Nicholas Nethercote
6087dc2054
Remove the symbol from ast::LitKind::Err
.
...
Because it's never used meaningfully.
2022-08-23 16:56:24 +10:00
bors
a785176741
Auto merge of #100881 - Dylan-DPC:rollup-q9rr658, r=Dylan-DPC
...
Rollup of 8 pull requests
Successful merges:
- #98200 (Expand potential inner `Or` pattern for THIR)
- #99770 (Make some const prop mir-opt tests `unit-test`s)
- #99957 (Rework Ipv6Addr::is_global to check for global reachability rather than global scope - rebase)
- #100331 (Guarantee `try_reserve` preserves the contents on error)
- #100336 (Fix two const_trait_impl issues)
- #100713 (Convert diagnostics in parser/expr to SessionDiagnostic)
- #100820 (Use pointer `is_aligned*` methods)
- #100872 (Add guarantee that Vec::default() does not alloc)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-22 17:46:57 +00:00
Dylan DPC
56ba13ac7f
Rollup merge of #98200 - ouz-a:issue-98177, r=oli-obk
...
Expand potential inner `Or` pattern for THIR
Code assumed there wouldn't be a deeper `Or` pattern inside expanded `PatStack` this fixes it by looking for the `Or` pattern inside expanded `PatStack`.
A more ideal solution would be recursively doing this but I haven't found a good way to do that.
_fixes #97898_
2022-08-22 20:34:08 +05:30
Nilstrieb
135c24102c
Fix span for consts in mir builder
2022-08-22 14:06:55 +02:00
Dylan DPC
2fe2975391
Rollup merge of #100081 - RalfJung:unused-unsafe-in-unsafe-fn, r=jackh726
...
never consider unsafe blocks unused if they would be required with deny(unsafe_op_in_unsafe_fn)
Judging from https://github.com/rust-lang/rust/issues/71668#issuecomment-1200317370 the consensus nowadays seems to be that we should never consider an unsafe block unused if it was required with `deny(unsafe_op_in_unsafe_fn)`, no matter whether that lint is actually enabled or not. So let's adjust rustc accordingly.
The first commit does the change, the 2nd does some cleanup.
2022-08-19 12:26:40 +05:30
Mark Rousskov
154a09dd91
Adjust cfgs
2022-08-12 16:28:15 -04:00
Dylan DPC
561ea0a746
Rollup merge of #99110 - audunhalland:match_has_guard_from_candidate, r=pnkfelix
...
Determine match_has_guard from candidates instead of looking up thir table again
Currently looking through mir build of matches because of interest in deref patterns. Finding some micro-optimizable things.
2022-08-11 22:46:57 +05:30