Michael Goulet
a6b5f95fb0
Make ClosureOutlivesRequirement not rely on an unresolved type
2022-10-19 17:10:59 +00:00
lcnr
e8150fa60c
mir constants: type traversing bye bye
2022-10-17 10:54:01 +02:00
bors
11432fe952
Auto merge of #102080 - yanchen4791:issue-99824-fix, r=cjgillot
...
Fix missing explanation of where the borrowed reference is used when the same borrow occurs multiple times due to loop iterations
Fix #99824 .
Problem of the issue:
If a borrow occurs in a loop, the borrowed reference could be invalidated at the same place at next iteration of the loop. When this happens, the point where the borrow occurs is the same as the intervening point that might invalidate the reference in the loop. This causes a problem for the current code finding the point where the resulting reference is used, so that the explanation of the cause will be missing. As the second point of "explain all errors in terms of three points" (see [leveraging intuition framing errors in terms of points"](https://rust-lang.github.io/rfcs/2094-nll.html#leveraging-intuition-framing-errors-in-terms-of-points ), this explanation is very helpful for user to understand the error.
In the current implementation, the searching region for finding the location where the borrowed reference is used is limited to between the place where the borrow occurs and the place where the reference is invalidated. If those two places happen to be the same, which indicates that the borrow and invalidation occur at the same place in a loop, the search will fail.
One solution to the problem is when these two places are the same, find the terminator of the loop, and then use the location of the loop terminator instead of the location of the borrow for the region to find the place where the borrowed reference is used.
2022-10-16 07:40:56 +00:00
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
Oli Scherer
1dc2119c03
Require lifetime bounds for opaque types in order to allow hidden types to capture said lifetimes
2022-10-14 08:15:51 +00:00
Rageking8
7122abaddf
more dupe word typos
2022-10-14 12:57:56 +08:00
bors
60bd3f9677
Auto merge of #102700 - oli-obk:0xDEAD_TAIT, r=compiler-errors
...
Check hidden types in dead code
fixes #99490
r? `@compiler-errors`
best reviewed commit by commit
2022-10-13 22:39:05 +00:00
Dylan DPC
5e04567ac7
Rollup merge of #102187 - b-naber:inline-const-source-info, r=eholk
...
Use correct location for type tests in promoted constants
Previously we forgot to remap the location in a type test collected when visiting the body of a promoted constant back to the usage location, causing an ICE when trying to get span information for that type test.
Fixes https://github.com/rust-lang/rust/issues/102117
2022-10-12 11:11:24 +05:30
Michael Howell
bf37054b1f
Rollup merge of #99818 - aliemjay:fix-closure-normalize, r=jackh726
...
don't ICE when normalizing closure input tys
We were ICEing while rendering diagnostics because `universe_causes` is expected to track every universe created in the typeck's infcx.
`normalize_and_add_constraints` doesn't update `universe_causes`
when creating new universes, causing an ICE. Remove it!
Add spans to better track normalization constraints.
Fix couple places where `universe_causes` is not updated correctly to
track newly added universes.
Fixes #102800
~Fixess #99665~ (UPDATE: no longer true; the issue has a different failure path than when this PR was created and should be fixed by #101708 , but the changes in this PR are still correct and should prevent potential future ICEs)
2022-10-08 18:14:59 -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
Ali MJ Al-Nasrawy
fc3d7eb91d
don't ICE when normalizing closure input tys
...
`normalize_and_add_constraints` doesn't add entries in `universe_causes`
when creating new universes, causing an ICE. Remove it!
Add spans to track normalization constraints.
Fix couple places where `universe_causes` is not updated correctly to
track newly added universes.
2022-10-08 04:56:25 +03:00
Oli Scherer
70d39abbc2
Remap hidden types from typeck before storing them in the TypeckResult
2022-10-07 19:43:46 +00:00
Oli Scherer
9eb69e82e0
Move ReverseMapper logic onto OpaqueHiddenType
2022-10-07 19:43:46 +00:00
Oli Scherer
d643ae1bbf
Remove some dead code
2022-10-07 19:36:32 +00: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
Cameron Steffen
4a68373217
Introduce TypeErrCtxt
...
TypeErrCtxt optionally has a TypeckResults so that InferCtxt doesn't
need to.
2022-10-07 07:06:16 -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
Oli Scherer
c7b6ebdf7c
It's not about types or consts, but the lack of regions
2022-10-04 14:10:44 +00:00
reez12g
ebcec30182
Remove 'E0312' from 'compile_fail,E0312' statement temporarily
2022-10-02 11:00:43 +09:00
Michael Goulet
c1c3dacc78
Generate synthetic impl region even in closure body in associated fn
2022-09-29 22:32:28 +00:00
reez12g
cf31a29492
Mark ignore on error code docs in compiler/rustc_borrowck/src/region_infer/mod.rs
2022-09-29 16:49:16 +09:00
reez12g
c2ad8d2551
Mark ignore on error code docs in compiler/rustc_borrowck/src/diagnostics/region_errors.rs
2022-09-29 16:49:15 +09:00
reez12g
9a4c5abe45
Remove from compiler/ crates
2022-09-29 16:49:04 +09:00
Yan Chen
b3bf931aa2
Fix missing explanation of where borrowed reference is used when the borrow occurs in loop iteration
2022-09-28 15:27:56 -07:00
bors
e1d7dec558
Auto merge of #102051 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
...
Update bootstrap compiler to 1.65.0
This PR updates the bootstrap compiler to Rust 1.65.0, removing the various `cfg(bootstrap)`s.
r? `@Mark-Simulacrum`
2022-09-26 14:22:43 +00:00
bors
84946fe241
Auto merge of #102184 - chenyukang:fix-102087-add-binding-sugg, r=nagisa
...
Suggest Default::default() when binding isn't initialized
Fixes #102087
2022-09-26 11:41:58 +00:00
Pietro Albini
3975d55d98
remove cfg(bootstrap)
2022-09-26 10:14:45 +02:00
yukang
672e3f4d77
fix #102087 , Suggest Default::default() when binding isn't initialized
2022-09-26 07:56:26 +08: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
fee1-dead
084029f39d
Rollup merge of #101431 - compiler-errors:move-place-ty-for-move-place-sugg, r=cjgillot
...
Look at move place's type when suggesting mutable reborrow
Not sure why we are looking at the use site's ty instead of the move site's ty in order to suggest reborrowing the move site, but it was suppressing a perfectly valid reborrow suggestion.
r? `@estebank` who i think touched this last in 520461f1fb
, though that was quite a while ago so feel free to reassign.
2022-09-25 22:06:37 +08: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
b-naber
72b3347d00
use correct location for type tests in promoted consts
2022-09-23 14:03:49 +02: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
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
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
lcnr
647052fc04
remove the Subst
trait, always use EarlyBinder
2022-09-19 11:37:27 +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
Jack Huey
e7ca6e1b47
Use Predicate ConstraintCategory when normalizing
2022-09-17 11:46:05 -04: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
Jack Huey
e09242d5b8
Final bits
2022-09-16 17:47:53 -04:00
Jack Huey
f1767dbb42
Add ExtraConstraintInfo
2022-09-16 17:33:12 -04:00
Jack Huey
ec17be2656
Add outlives_constraint to BlameConstraint
2022-09-16 17:08:35 -04:00
Jack Huey
6075877c89
Pass ConstraintCategory thorough a few more places
2022-09-16 16:44:18 -04:00
Jack Huey
a46376e247
Make QueryOutlivesConstraint contain a ConstraintCategory
2022-09-16 16:15:41 -04:00
Jack Huey
92b759f517
Revert "Better errors for implied static bound"
...
This reverts commit c75817b0a7
.
2022-09-16 09:47:07 -04:00
Jack Huey
bba514b7b4
Revert "Use Predicate ConstraintCategory when normalizing"
...
This reverts commit aae37f8763
.
2022-09-16 09:01:28 -04: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
Deadbeef
5ead742e18
remap ParamEnv with obligation
2022-09-16 12:08:46 +08:00
Deadbeef
08aeb1aa9b
unconditionally remap to nonconst in borrowck
2022-09-16 12:08:46 +08:00
Deadbeef
f8813cf10e
do const trait method bounds check later in rustc_const_eval
2022-09-16 11:48:43 +08:00
b-naber
d77248e6d2
nits
2022-09-15 22:27:41 +02: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
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
Jack Huey
aae37f8763
Use Predicate ConstraintCategory when normalizing
2022-09-13 20:18:49 -04:00
Jack Huey
c75817b0a7
Better errors for implied static bound
2022-09-13 20:18:04 -04:00
Jack Huey
ff623ffc39
Cleanup retrieve_closure_constraint_info
2022-09-13 19:58:53 -04:00
Jack Huey
2be6301857
Remove unused body args
2022-09-13 19:58:53 -04:00
Camille GILLOT
494af379c4
Use def_span for external requirements.
2022-09-13 19:18:24 +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
bea0a6dc84
address review
2022-09-13 17:44:53 +02:00
b-naber
372c4fd67f
remove visit_const from mir visitors
2022-09-13 17:44:52 +02:00
b-naber
2554fa1c8e
renumber regions in mir constants correctly
2022-09-13 17:41:02 +02:00
b-naber
a4bbb8db5c
use ty::Unevaluated<'tcx, ()> in type system
2022-09-13 17:40:59 +02:00
Michael Goulet
b2ed2dcaae
Rename some variants
2022-09-12 16:55:59 -07:00
Eric Holk
549c105bb3
dyn* through more typechecking and MIR
2022-09-12 16:55:56 -07:00
KaDiWa
66211d83f9
Avoid Iterator::last
2022-09-11 17:23:00 +02:00
bors
2287107588
Auto merge of #98559 - jackh726:remove-reempty, r=oli-obk
...
Remove ReEmpty
r? rust-lang/types
2022-09-10 20:54:01 +00:00
Camille GILLOT
05812df603
Handle generic parameters.
2022-09-09 01:31:46 +00:00
Jack Huey
1ca9eb8ec3
Remove ReEmpty
2022-09-08 20:55:55 -04:00
Jack Huey
e7e5feb637
In ReverseMapper, don't fallback to ReEmpty, instead ReStatic
2022-09-08 17:57:34 -04:00
Jack Huey
f29c91bf12
Create VarValue::Empty
2022-09-08 17:57:32 -04:00
Dylan DPC
720a82dd52
Rollup merge of #101545 - TaKO8Ki:remove-unnecessary-partialord-ord, r=oli-obk
...
Remove unnecessary `PartialOrd` and `Ord`
2022-09-08 20:48:38 +05:30
Takayuki Maeda
bdc865d8f7
remove unnecessary PartialOrd
and Ord
2022-09-08 06:15:33 +09:00
Oli Scherer
a0130e62ec
Check all operands, they may contain indirections in their place
2022-09-06 15:32:35 +00:00
Oli Scherer
b7413511dc
Generalize the Assume intrinsic statement to a general Intrinsic statement
2022-09-06 14:18:32 +00:00
Oli Scherer
3f07645120
Lower the assume intrinsic to a MIR statement
2022-09-06 14:18:32 +00:00
bors
6c358c67d4
Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot
...
`BindingAnnotation` refactor
* `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`)
* `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)`
* Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}`
One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`.
I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.
2022-09-06 03:16:29 +00:00
bors
b44197abb0
Auto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-hir, r=cjgillot
...
Separate the receiver from arguments in HIR
Related to #100232
cc `@cjgillot`
2022-09-05 16:21:40 +00:00
Takayuki Maeda
9cde34e180
use propagate_through_exprs
instead of propagate_through_expr
...
fix `ExprKind` static_assert_size
fix hir-stats
2022-09-05 23:11:34 +09:00
bors
2dc703fd6e
Auto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petrochenkov
...
Simplify `hir::PathSegment`
r? `@petrochenkov`
2022-09-05 13:36:54 +00: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
7e226e6d3f
Look at move place's type when suggesting mutable reborrow
2022-09-05 05:00:33 +00:00
Michael Goulet
41d4ea2314
Don't suggest reborrow if usage is inside a closure
2022-09-05 04:27:07 +00:00
Nicholas Nethercote
bb0ae3c446
Make hir::PathSegment::hir_id
non-optional.
2022-09-05 14:20:25 +10:00
Cameron Steffen
02ba216e3c
Refactor and re-use BindingAnnotation
2022-09-02 12:55:05 -05:00
Matthias Krüger
1bafe0b020
Rollup merge of #101285 - TaKO8Ki:do-not-suggest-adding-move-when-closure-is-already-marked-as-move, r=oli-obk
...
Do not suggest adding `move` to closure when `move` is already used
Fixes #101227
2022-09-01 21:37:21 +02: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
Takayuki Maeda
78e9bea598
do not suggest adding move
to closure when move
is already used
2022-09-01 23:50:51 +09:00
bors
a0d07093f8
Auto merge of #100812 - Nilstrieb:revert-let-chains-nightly, r=Mark-Simulacrum
...
Revert let_chains stabilization
This is the revert against master, the beta revert was already done in #100538 .
Bumps the stage0 compiler which already has it reverted.
2022-08-30 05:48:22 +00:00
Matthias Krüger
7b84298f1b
Rollup merge of #101146 - jackh726:borrowck-logging, r=compiler-errors
...
Various changes to logging of borrowck-related code
Cleanups found when doing other changes
r? `@compiler-errors`
2022-08-29 21:12:59 +02: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
Jack Huey
8033c3c27d
Various changes to logging of borrowck-related code
2022-08-29 10:59:21 -04: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
Matthias Krüger
c5770219f2
Rollup merge of #101002 - estebank:hashmap-idx, r=davidtwco
...
Provide structured suggestion for `hashmap[idx] = val`
2022-08-28 09:35:18 +02:00
Tomasz Miąsko
b48870b451
Replace Body::basic_blocks()
with field access
2022-08-26 14:27:08 +02:00
AndyJado
622217da59
diag-mig
2022-08-26 10:32:59 +08:00
Esteban Küber
752902957b
Provide structured suggestion for hashmap[idx] = val
2022-08-25 08:44:36 -07:00
Matthias Krüger
75b1b69171
Rollup merge of #100940 - TaKO8Ki:do-not-suggest-adding-bound-to-opaque-type, r=fee1-dead
...
Do not suggest adding a bound to a opaque type
fixes #100442
2022-08-24 18:20:20 +02:00
Matthias Krüger
95135bed61
Rollup merge of #100906 - ChayimFriedman2:map-index-mut, r=davidtwco
...
Suggest alternatives when trying to mutate a `HashMap`/`BTreeMap` via indexing
The error can be quite confusing to newcomers.
Fixes #100873 .
I'm not so sure about the message, open to wording suggestions.
2022-08-24 18:20:13 +02:00
Matthias Krüger
1c0f60f904
Rollup merge of #100901 - TaKO8Ki:make-some-methods-private, r=sanxiyn
...
Make some methods private
2022-08-24 18:20:12 +02:00
Takayuki Maeda
3855e039a2
do not suggest adding a bound to a opaque type
2022-08-24 11:34:14 +09:00
Chayim Refael Friedman
b0255a1849
Suggest alternatives when trying to mutate a HashMap
/BTreeMap
via indexing
...
The error can be quite confusing to newcomers.
2022-08-23 15:15:34 +00:00
SparrowLii
5d9e4d07fc
get rid of RefCell
in TransitiveRelation
2022-08-22 18:08:46 +08:00
Takayuki Maeda
000dc80221
make some methods private
2022-08-22 18:12:18 +09:00
Matthias Krüger
9cf3bacfb2
Rollup merge of #100761 - lcnr:mir-typeck-cleanup, r=compiler-errors
...
some general mir typeck cleanup
this pr contains the parts of #95763 which already work correctly.
the remaining commits of that PR have some issues which are more complex to fix.
r? types
2022-08-21 16:54:04 +02:00
Xiretza
7f3a6fd7f6
Replace #[lint/warning/error] with #[diag]
2022-08-21 09:17:43 +02:00
Matthias Krüger
3cca14093a
Rollup merge of #100186 - compiler-errors:or-as_mut, r=fee1-dead
...
Mention `as_mut` alongside `as_ref` in borrowck error message
Kinda fixes #99426 but I guess that really might be better staying open to see if we could make it suggest `as_mut` in a structured way. Not sure how to change borrowck to know that info tho.
2022-08-20 07:08:57 +02:00
lcnr
56b5ec83f2
move type_check_internal
into type_check
2022-08-19 16:41:48 +02:00
lcnr
7d2083c58e
small mir typeck cleanup
2022-08-19 16:38:26 +02:00
Michael Goulet
e37565d2db
Make as_ref suggestion a note
2022-08-16 03:02:04 +00:00
Yan Chen
15713e1717
Fix #95079 by adding help and suggestion for missing move in nested closure
2022-08-15 11:20:32 -07:00
Michael Goulet
84ba2289fd
Suggest as_ref or as_mut
2022-08-14 20:23:52 +00:00
Michael Goulet
75dfe55a5d
TypeError can be Copy
2022-08-14 19:58:46 +00:00
Mark Rousskov
154a09dd91
Adjust cfgs
2022-08-12 16:28:15 -04:00
Michael Goulet
a2b6744af0
Use &mut Diagnostic instead of &mut DiagnosticBuilder unless needed
2022-08-10 03:45:42 +00:00
lcnr
f25cb83296
don't normalize wf predicates
...
this allows us to soundly use unnormalized projections for wf
2022-08-09 12:54:32 +02:00
Matthias Krüger
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
Matthias Krüger
6b938c8491
Rollup merge of #100093 - wcampbell0x2a:unused-parens-for-match-arms, r=petrochenkov
...
Enable unused_parens for match arms
Fixes: https://github.com/rust-lang/rust/issues/92751
Currently I can't get the `stderr` to work with `./x.py test`, but this should fix the issue. Help would be appreciated!
2022-08-04 22:25:02 +02:00
wcampbell
8dd44f1af4
Enable unused_parens for match arms
2022-08-04 07:16:39 -04:00
bors
caee496150
Auto merge of #100120 - matthiaskrgr:rollup-g6ycykq, r=matthiaskrgr
...
Rollup of 6 pull requests
Successful merges:
- #98771 (Add support for link-flavor rust-lld for iOS, tvOS and watchOS)
- #98835 (relate `closure_substs.parent_substs()` to parent fn in NLL)
- #99746 (Use `TraitEngine` in more places that don't specifically need `FulfillmentContext::new_in_snapshot`)
- #99786 (Recover from C++ style `enum struct`)
- #99795 (Delay a bug when failed to normalize trait ref during specialization)
- #100029 (Prevent ICE for `doc_alias` on match arm, statement, expression)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-04 03:52:29 +00:00
klensy
0548e8ed06
fix trailing whitespace in error message
2022-08-03 15:46:34 +03:00
Ali MJ Al-Nasrawy
78adc0139c
cosmetic changes
2022-08-03 12:46:04 +03:00
Jack Huey
e21624dc80
Add bound_predicates_of and bound_explicit_predicates_of
2022-08-02 22:44:08 -04:00
Ali MJ Al-Nasrawy
f74d06c2d1
NLL: relate closure to parent fn
2022-08-02 15:20:57 +03:00
Obei Sideg
86dd457e6a
Improve cannot move out of
error message
2022-07-31 21:06:43 +03:00
Dylan DPC
403c1b3802
Rollup merge of #99186 - camsteffen:closure-localdefid, r=cjgillot
...
Use LocalDefId for closures more
2022-07-31 17:36:40 +05:30
Cameron Steffen
cf2433a74f
Use LocalDefId for closures more
2022-07-30 15:59:17 -05:00
Miguel Guarniz
0c609a4c1f
Change enclosing_body_owner to return LocalDefId
...
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:26:10 -04:00
Miguel Guarniz
25bdc8965e
Change maybe_body_owned_by to take local def id
...
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:25:58 -04:00
bors
7dfdd64433
Auto merge of #99667 - ouz-a:some_branch, r=oli-obk
...
Optimize `UnDerefer`
Addresses the performance [issues](https://github.com/rust-lang/rust/pull/98145#issuecomment-1183548597 ) faced here.
r? `@oli-obk`
2022-07-29 07:11:50 +00:00
bors
ada80a13b9
Auto merge of #99725 - lcnr:dedup-region_bound_pairs, r=compiler-errors
...
use `FxIndexSet` for `region_bound_pairs`
should help with #99217 and might generally be a perf improvement.
r? types
2022-07-27 22:02:14 +00:00
Guillaume Gomez
c37ee1a7e0
Rollup merge of #99728 - cjgillot:ast-lifetimes-anon-clean, r=petrochenkov
...
Clean up HIR-based lifetime resolution
Based on https://github.com/rust-lang/rust/pull/97313 .
Fixes #98932 .
r? `@petrochenkov`
2022-07-27 17:55:07 +02:00
Yuki Okushi
3b780fc279
Rollup merge of #99079 - compiler-errors:issue-99073, r=oli-obk
...
Check that RPITs constrained by a recursive call in a closure are compatible
Fixes #99073
Adapts a similar visitor pattern to `find_opaque_ty_constraints` (that we use to check TAITs), but with some changes:
0. Only walk the "OnlyBody" children, instead of all items in the RPIT's defining scope
1. Only walk through the body's children if we found a constraining usage
2. Don't actually do any inference, just do a comparison and error if they're mismatched
----
r? `@oli-obk` -- you know all this impl-trait stuff best... is this the right approach? I can explain the underlying issue better if you'd like, in case that might reveal a better solution. Not sure if it's possible to gather up the closure's defining usages of the RPIT while borrowck'ing the outer function, that might be a better place to put this check...
2022-07-27 19:05:32 +09:00
Camille GILLOT
10be0dd8df
Replace LifetimeRes::Anonymous by LifetimeRes::Infer.
2022-07-26 19:00:31 +02:00
Camille GILLOT
ab63591f00
Remove the distinction between LifetimeName::Implicit and LifetimeName::Underscore.
2022-07-26 19:00:31 +02:00
Dylan DPC
ad32667bc8
Rollup merge of #99748 - compiler-errors:better-impl-trait-printing, r=fee1-dead
...
Use full type name instead of just saying `impl Trait` in "captures lifetime" error
I think this is very useful, especially when there's >1 `impl Trait`, and it just means passing around a bit more info that we already have access to.
2022-07-26 14:27:00 +05:30
Michael Goulet
90939e6bce
Revert "Do not allow typeck children items to constrain outer RPITs"
...
This reverts commit e8d9f38141
.
2022-07-26 07:46:30 +00:00
Michael Goulet
82ad5c95b6
Revert "use opaque_ty_origin_unchecked instead of destructuring HIR"
...
This reverts commit 5a4601fea5
.
2022-07-26 07:46:30 +00:00
Michael Goulet
d3492ca852
Use real opaque type instead of just saying impl Trait
2022-07-26 06:19:58 +00:00