Commit graph

233 commits

Author SHA1 Message Date
Dylan DPC
0aed74aa43
Rollup merge of #78502 - matthewjasper:chalkup, r=nikomatsakis
Update Chalk to 0.36.0

This PR updates Chalk and fixes a number of bugs in the chalk integration code.

cc `@rust-lang/wg-traits`
r? `@nikomatsakis`
2020-11-09 19:06:46 +01:00
Dylan DPC
abaa78baeb
Rollup merge of #78748 - fanzier:tuple-assignment, r=petrochenkov
Implement destructuring assignment for tuples

This is the first step towards implementing destructuring assignment (RFC: https://github.com/rust-lang/rfcs/pull/2909, tracking issue: #71126). This PR is the first part of #71156, which was split up to allow for easier review.

Quick summary: This change allows destructuring the LHS of an assignment if it's a (possibly nested) tuple.
It is implemented via a desugaring (AST -> HIR lowering) as follows:
```rust
(a,b) = (1,2)
```
... becomes ...
```rust
{
  let (lhs0,lhs1) = (1,2);
  a = lhs0;
  b = lhs1;
}
```

Thanks to `@varkor` who helped with the implementation, particularly around default binding modes.

r? `@petrochenkov`
2020-11-09 01:13:44 +01:00
Fabian Zaiser
3a7a997323 Implement destructuring assignment for tuples
Co-authored-by: varkor <github@varkor.com>
2020-11-07 13:17:19 +00:00
ankushduacodes
0af959d3a2 Fixing Spelling Typos 2020-11-06 09:25:58 +05:30
Mara Bos
171d29c9c5
Rollup merge of #78739 - hameerabbasi:issue-78654, r=nikomatsakis
Fix ICE on type error in async function

Fixes #78654
2020-11-05 10:29:57 +01:00
bors
0fb00251a5 Auto merge of #78662 - sexxi-goose:add_expr_id_to_delegate, r=nikomatsakis
Provide diagnostic suggestion in ExprUseVisitor Delegate

The [Delegate trait](981346fc07/compiler/rustc_typeck/src/expr_use_visitor.rs (L28-L38)) currently use `PlaceWithHirId` which is composed of Hir `Place` and the
corresponding expression id.

Even though this is an accurate way of expressing how a Place is used,
it can cause confusion during diagnostics.

Eg:

```
let arr : [String; 5];

let [a, ...]     =   arr;
 ^^^ E1 ^^^      =  ^^E2^^
 ```

 Here `arr` is moved because of the binding created E1. However, when we
 point to E1 in diagnostics with the message `arr` was moved, it can be
 confusing.  Rather we would like to report E2 to the user.

 Closes: https://github.com/rust-lang/project-rfc-2229/issues/20

r? `@ghost`
2020-11-04 22:45:15 +00:00
Hameer Abbasi
a70e0c20c3 Fix issue 78654. 2020-11-04 16:04:32 +00:00
Dhruv Jauhar
c9d9359b00 Address Pr comments regarding docstrings 2020-11-04 02:54:00 -05:00
Dhruv Jauhar
1f53754236 Provide diagnostic suggestion in ExprUseVisitor Delegate
The [Delegate
trait](981346fc07/compiler/rustc_typeck/src/expr_use_visitor.rs (L28-L38))
currently use `PlaceWithHirId` which is composed of Hir `Place` and the
corresponding expression id.

Even though this is an accurate way of expressing how a Place is used,
it can cause confusion during diagnostics.

Eg:

```
let arr : [String; 5];

let [a, ...]     =   arr;
 ^^^ E1 ^^^      =  ^^E2^^
 ```

 Here `arr` is moved because of the binding created E1. However, when we
 point to E1 in diagnostics with the message `arr` was moved, it can be
 confusing.  Rather we would like to report E2 to the user.

 Closes: https://github.com/rust-lang/project-rfc-2229/issues/20
2020-11-02 01:31:34 -05:00
kadmin
ab946dd3e7 Add delay_span_bug to no longer ICE 2020-11-01 22:31:19 +00:00
bors
0d033dee3e Auto merge of #78182 - LeSeulArtichaut:ty-visitor-contolflow, r=lcnr,oli-obk
TypeVisitor: use `std::ops::ControlFlow` instead of `bool`

Implements MCP rust-lang/compiler-team#374.

Blocked on FCP in rust-lang/compiler-team#374.
r? `@lcnr` cc `@jonas-schievink`
2020-10-30 22:53:55 +00:00
Matthew Jasper
1f5c655d0c Fix query cycle when tracing explicit_item_bounds 2020-10-30 19:38:46 +00:00
LeSeulArtichaut
9433eb83fe Remove implicit Continue type 2020-10-30 12:27:47 +01:00
LeSeulArtichaut
24e1a7e656 Use ControlFlow::is{break,continue} 2020-10-30 12:27:46 +01:00
LeSeulArtichaut
61f8182cec TypeVisitor: use ControlFlow in rustc_{mir,privacy,traits,typeck} 2020-10-30 12:27:44 +01:00
bors
388ef34904 Auto merge of #78562 - JohnTitor:rollup-otg906u, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #77334 (Reorder benches const variable)
 - #77888 (Simplify a nested bool match)
 - #77921 (f64: Refactor collapsible_if)
 - #78523 (Revert invalid `fn` return type parsing change)
 - #78524 (Avoid BorrowMutError with RUSTC_LOG=debug)
 - #78545 (Make anonymous binders start at 0)
 - #78554 (Improve wording of `core::ptr::drop_in_place` docs)
 - #78556 (Link to pass docs from NRVO module docs)

Failed merges:

 - #78424 (Fix some more clippy warnings)

r? `@ghost`
2020-10-30 10:01:49 +00:00
bors
8df58ae03a Auto merge of #78393 - SNCPlay42:match-if-guard, r=tmandry
Always record reference to binding in match if guards

When encountering a binding from a `match` pattern in its `if` guard when computing a generator's interior types, we must always record the type of a reference to the binding because of how `if` guards are lowered to MIR. This was missed in #75213 because the binding in that test case was autorefed and we recorded that adjusted type anyway.

Fixes #78366
2020-10-30 07:05:57 +00:00
Jack Huey
41ce397990 Make anonymous binders start at 0 2020-10-29 18:50:23 -04:00
bors
2eb4fc800a Auto merge of #78323 - est31:smaller_list_overlap, r=varkor
Iterate over the smaller list

If there are two lists of different sizes,
iterating over the smaller list and then
looking up in the larger list is cheaper
than vice versa, because lookups scale
sublinearly.
2020-10-28 03:58:32 +00:00
Dylan DPC
1a64e570c6
Rollup merge of #78365 - lcnr:const-eval-obj-safety, r=oli-obk
check object safety of generic constants

As `Self` can only be effectively used in constants with `const_evaluatable_checked` this should not matter outside of it.

Implements the first item of #72219

> Object safety interactions with constants

r? @oli-obk for now cc @nikomatsakis
2020-10-28 01:21:21 +01:00
Dylan DPC
86a4a38177
Rollup merge of #78297 - estebank:match-semicolon-2, r=oli-obk
Suggest calling await on method call and field access

When encountering a failing method or field resolution on a `Future`,
look at the `Output` and try the same operation on it. If successful,
suggest calling `.await` on the `Future`.

This had already been introduced in #72784, but at some point they
stopped working.

Built on top of #78214, only last commit is relevant.

r? @oli-obk
2020-10-28 01:21:10 +01:00
Santiago Pastorino
89eac50a87
Hide outermost_fn_param_pat, it's an internal detail 2020-10-27 14:45:40 -03:00
Santiago Pastorino
497ee0e1ff
param -> parameter, pat -> pattern 2020-10-27 14:45:39 -03:00
Santiago Pastorino
bdd1b85f95
Rename within_fn_param to outermost_fn_param_pat 2020-10-27 14:45:39 -03:00
Santiago Pastorino
ca41681bf0
Do not use unsized_fn_params in patterns 2020-10-27 14:45:38 -03:00
Santiago Pastorino
58018d438b
Properly restore within_fn_param value to the previous state 2020-10-27 14:45:38 -03:00
Santiago Pastorino
708fc3b1a2
Add unsized_fn_params feature 2020-10-27 14:45:02 -03:00
bors
824f900a96 Auto merge of #77317 - varkor:break-diverging-value, r=nikomatsakis
Fix control flow check for breaking with diverging values

Fixes https://github.com/rust-lang/rust/issues/77156.
2020-10-27 07:10:55 +00:00
Yuki Okushi
46b8e46fe1
Rollup merge of #78396 - josephlr:ermsb, r=petrochenkov
Add compiler support for LLVM's x86_64 ERMSB feature

This change is needed for compiler-builtins to check for this feature
when implementing memcpy/memset. See:
  https://github.com/rust-lang/compiler-builtins/pull/365

Without this change, the following code compiles, but does nothing:
```rust
#[cfg(target_feature = "ermsb")]
pub unsafe fn ermsb_memcpy() { ... }
```

The change just does compile-time detection. I think that runtime
detection will have to come in a follow-up CL to std-detect.

Like all the CPU feature flags, this just references #44839

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-27 08:45:24 +09:00
Esteban Küber
28f02fbf3e Suggest calling await on method call and field access
When encountering a failing method or field resolution on a `Future`,
look at the `Output` and try the same operation on it. If successful,
suggest calling `.await` on the `Future`.

This had already been introduced in #72784, but at some point they
stopped working.
2020-10-26 08:11:43 -07:00
Joe Richey
ad552bc17e
Add compiler support for LLVM's x86 ERMSB feature
This change is needed for compiler-builtins to check for this feature
when implementing memcpy/memset. See:
  https://github.com/rust-lang/compiler-builtins/pull/365

The change just does compile-time detection. I think that runtime
detection will have to come in a follow-up CL to std-detect.

Like all the CPU feature flags, this just references #44839

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-26 03:46:54 -07:00
SNCPlay42
8bf9abbb7b always record reference to binding in match if guards 2020-10-26 09:29:50 +00:00
bors
b9a94c919b Auto merge of #78324 - RalfJung:uninhabited-statics, r=oli-obk
ensure that statics are inhabited

Fixes https://github.com/rust-lang/rust/issues/74840

r? `@oli-obk`
2020-10-26 09:11:34 +00:00
bors
1cd97cad6e Auto merge of #78387 - Dylan-DPC:rollup-ch0st6z, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #74477 (`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm)
 - #77836 (transmute_copy: explain that alignment is handled correctly)
 - #78126 (Properly define va_arg and va_list for aarch64-apple-darwin)
 - #78137 (Initialize tracing subscriber in compiletest tool)
 - #78161 (Add issue template link to IRLO)
 - #78214 (Tweak match arm semicolon removal suggestion to account for futures)
 - #78247 (Fix #78192)
 - #78252 (Add codegen test for #45964)
 - #78268 (Do not try to report on closures to avoid ICE)
 - #78295 (Add some regression tests)

Failed merges:

r? `@ghost`
2020-10-26 04:34:46 +00:00
Dylan DPC
083a5cd9a2
Rollup merge of #78214 - estebank:match-semicolon, r=oli-obk
Tweak match arm semicolon removal suggestion to account for futures

* Tweak and extend "use `.await`" suggestions
* Suggest removal of semicolon on prior match arm
* Account for `impl Future` when suggesting semicolon removal
* Silence some errors when encountering `await foo()?` as can't be certain what the intent was

*Thanks to https://twitter.com/a_hoverbear/status/1318960787105353728 for pointing this out!*
2020-10-26 03:09:06 +01:00
bors
16e9ed0b1c Auto merge of #77283 - estebank:if-let-sugg, r=Mark-Simulacrum
Tweak `if let` suggestion to be more liberal with suggestion and to not ICE

Fix #77218. Fix #77238.
2020-10-26 01:53:51 +00:00
Esteban Küber
cabf6d0523 Tweak if let suggestion to be more liberal with suggestion and to not ICE
Fix #77218. Fix #77238.
2020-10-25 15:21:14 -07:00
est31
6c9b8ada0c Precompute the associated items
The associated_items(def_id) call
allocates internally.
Previously, we'd have called it for
each pair, so we'd have had O(n^2)
many calls. By precomputing the
associated items, we avoid
repeating so many allocations.

The only instance where this precomputation
would be a regression is if there's only
one inherent impl block for the type,
as the inner loop then doesn't run.
In that instance, we just early return.

Also, use SmallVec to avoid doing an
allocation at all if the number is small
(the case for most impl blocks out there).
2020-10-25 22:50:48 +01:00
Bastian Kauschke
9dadcf8370 warn -> debug in collect 2020-10-25 18:05:18 +01:00
bors
3e0dd24a6c Auto merge of #77546 - lcnr:impl-trait-closure, r=eddyb
fix def collector for impl trait

fixes #77329

We now consistently make `impl Trait` a hir owner, requiring some special casing for synthetic generic params.

r? `@eddyb`
2020-10-25 07:03:58 +00:00
Ralf Jung
5d624929cf
fix typo
Co-authored-by: BlackHoleFox <blackholefoxdev@gmail.com>
2020-10-24 20:39:04 +02:00
Ralf Jung
1333206eb3 ensure that statics are inhabited 2020-10-24 16:15:42 +02:00
est31
a21c2eb121 Iterate over the smaller list
If there are two lists of different sizes,
iterating over the smaller list and then
looking up in the larger list is cheaper
than vice versa, because lookups scale
sublinearly.
2020-10-24 15:57:42 +02:00
Esteban Küber
c5485115dc Add more .await suggestions on E0308 2020-10-23 08:06:41 -07:00
Esteban Küber
62ba365195 Review comments: use newtype instead of bool 2020-10-23 08:06:41 -07:00
Esteban Küber
671d7c4afb Account for possible boxable impl Future in semicolon removal suggestions 2020-10-23 08:06:13 -07:00
Esteban Küber
a4ee3ca1e4 Suggest semicolon removal on prior match arm 2020-10-23 08:02:58 -07:00
Esteban Küber
86df9039b2 Tweak "use .await" suggestion 2020-10-23 08:02:57 -07:00
Yuki Okushi
7ba519ec50
Rollup merge of #78255 - dtolnay:match, r=lcnr
Reduce diagram mess in 'match arms have incompatible types' error

I noticed this wild diagram in https://twitter.com/a_hoverbear/status/1318960787105353728 which I think does not benefit from the big outer vertical span.

This PR shrinks the outer span to cover just the `match` keyword and scrutinee expression *if* at least one of the highlighted match arms involved in the error is multiline.

**Before:**

<pre>
<b>error[E0308]: `match` arms have incompatible types</b>
   <b>--&gt;</b> src/topology/builder.rs:141:35
    <b>|</b>
<b>120 |</b>             let transform = match transform {
    <b>|    _________________________-</b>
<b>121 |   |</b>             Transform::Function(t) =&gt; {
    <b>|  _|_______________________________________-</b>
<b>122 | | |</b>                 filter_event_type(input_rx, input_type).compat().flat_map(|v| {
<b>123 | | |</b>                     futures::stream::iter(match v {
<b>124 | | |</b>                         Err(e) =&gt; {
<b>...   | |</b>
<b>139 | | |</b>                 .compat();
<b>140 | | |</b>             }
    <b>| |_|_____________- this is found to be of type `()`</b>
<b>141 |   |</b>             Transform::Task(t) =&gt; t
    <b>|  _|___________________________________^</b>
<b>142 | | |</b>                 .transform(filter_event_type(input_rx, input_type))
<b>143 | | |</b>                 .forward(output)
<b>144 | | |</b>                 .map(|_| debug!("Finished"))
<b>145 | | |</b>                 .compat(),
    <b>| |_|_________________________^ expected `()`, found struct `futures::compat::Compat01As03`</b>
<b>146 |   |</b>         };
    <b>|   |_________- `match` arms have incompatible types</b>
    <b>|</b>
    <b>= note:</b> expected type `<b>()</b>`
             found struct `<b>futures::compat::Compat01As03&lt;futures::Map&lt;futures::stream::Forward&lt;std::boxed::Box&lt;dyn futures::Stream&lt;Error = (), Item = event::Event&gt; + std::marker::Send&gt;, topology::fanout::Fanout&gt;, [closure@src/topology/builder.rs:144:22: 144:44]&gt;&gt;</b>`
</pre>

**After:**

<pre>
<b>error[E0308]: `match` arms have incompatible types</b>
   <b>--&gt;</b> src/topology/builder.rs:141:35
    <b>|</b>
<b>120 |</b>             let transform = match transform {
    <b>|                             --------------- `match` arms have incompatible types</b>
<b>121 |</b>                 Transform::Function(t) =&gt; {
    <b>|  _________________________________________-</b>
<b>122 | |</b>                   filter_event_type(input_rx, input_type).compat().flat_map(|v| {
<b>123 | |</b>                       futures::stream::iter(match v {
<b>124 | |</b>                           Err(e) =&gt; {
<b>...   |</b>
<b>139 | |</b>                   .compat();
<b>140 | |</b>               }
    <b>| |_______________- this is found to be of type `()`</b>
<b>141 |</b>                 Transform::Task(t) =&gt; t
    <b>|  _____________________________________^</b>
<b>142 | |</b>                   .transform(filter_event_type(input_rx, input_type))
<b>143 | |</b>                   .forward(output)
<b>144 | |</b>                   .map(|_| debug!("Finished"))
<b>145 | |</b>                   .compat(),
    <b>| |___________________________^ expected `()`, found struct `futures::compat::Compat01As03`</b>
    <b>|</b>
    <b>= note:</b> expected type `<b>()</b>`
             found struct `<b>futures::compat::Compat01As03&lt;futures::Map&lt;futures::stream::Forward&lt;std::boxed::Box&lt;dyn futures::Stream&lt;Error = (), Item = event::Event&gt; + std::marker::Send&gt;, topology::fanout::Fanout&gt;, [closure@src/topology/builder.rs:144:22: 144:44]&gt;&gt;</b>`
</pre>

FYI @Hoverbear
2020-10-23 18:26:40 +09:00
Yuki Okushi
3f462c22b5
Rollup merge of #78235 - Aaron1011:closure-ret-infer, r=varkor
Explain where the closure return type was inferred

Fixes #78193
2020-10-23 18:26:39 +09:00