Commit graph

275 commits

Author SHA1 Message Date
mendess 888055eb4c Swap note for help 2020-11-24 11:05:55 +00:00
Jonas Schievink 064c3c146a
Rollup merge of #79337 - LingMan:map, r=jyn514
Use Option::map instead of open coding it

r?  `@jonas-schievink` since you're frequently sniping these minor cleanups anyway.
`@rustbot` modify labels +C-cleanup  +T-compiler
2020-11-23 15:25:53 +01:00
LingMan cd8973250d Use Option::map instead of open coding it 2020-11-23 04:58:21 +01:00
Jonas Schievink ee6f42ba94 Thread Constness through selection 2020-11-22 02:13:53 +01:00
Dylan DPC 5a58b50698
Rollup merge of #78961 - CraftSpider:22565, r=oli-obk
Make bad "rust-call" arguments no longer ICE

The simplest of bad rust-call definitions will no longer cause an ICE. There is a FIXME added for future work, as I wanted to get this easy fix in before trying to either add a hack or mess with the whole obligation system

fixes #22565
2020-11-19 16:26:19 +01:00
Rune Tynan e8426a617b
Remove unnecessary abi import 2020-11-17 15:49:40 -05:00
Rune Tynan c825c74dc9
Move change to check_fn, fix up overloaded-calls-nontuple 2020-11-17 14:42:29 -05:00
Mara Bos b6f52410bb
Rollup merge of #79072 - oli-obk:byte_str_pat, r=estebank
Fix exhaustiveness in case a byte string literal is used at slice type

fixes #79048
2020-11-17 16:13:53 +01:00
bors e0ef0fc392 Auto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk
Introduce `TypeVisitor::BreakTy`

Implements MCP rust-lang/compiler-team#383.
r? `@ghost`
cc `@lcnr` `@oli-obk`

~~Blocked on FCP in rust-lang/compiler-team#383.~~
2020-11-17 12:24:34 +00:00
oli a1cdf722f4 Fix exhaustiveness in case a byte string literal is used at slice type 2020-11-17 09:07:23 +00:00
bors b5c37e86ff Auto merge of #78801 - sexxi-goose:min_capture, r=nikomatsakis
RFC-2229: Implement Precise Capture Analysis

### This PR introduces
- Feature gate for RFC-2229 (incomplete) `capture_disjoint_field`
- Rustc Attribute to print out the capture analysis `rustc_capture_analysis`
- Precise capture analysis

### Description of the analysis
1. If the feature gate is not set then all variables that are not local to the closure will be added to the list of captures. (This is for backcompat)
2. The rest of the analysis is based entirely on how the captured `Place`s are used within the closure. Precise information (i.e. projections) about the `Place` is maintained throughout.
3. To reduce the amount of information we need to keep track of, we do a minimization step. In this step, we determine a list such that no Place within this list represents an ancestor path to another entry in the list.  Check rust-lang/project-rfc-2229#9 for more detailed examples.
4. To keep the compiler functional as before we implement a Bridge between the results of this new analysis to existing data structures used for closure captures. Note the new capture analysis results are only part of MaybeTypeckTables that is the information is only available during typeck-ing.

### Known issues
- Statements like `let _ = x` will make the compiler ICE when used within a closure with the feature enabled. More generally speaking the issue is caused by `let` statements that create no bindings and are init'ed using a Place expression.

### Testing
We removed the code that would handle the case where the feature gate is not set, to enable the feature as default and did a bors try and perf run. More information here: #78762

### Thanks
This has been slowly in the works for a while now.
I want to call out `@Azhng` `@ChrisPardy` `@null-sleep` `@jenniferwills` `@logmosier` `@roxelo` for working on this and the previous PRs that led up to this, `@nikomatsakis` for guiding us.

Closes rust-lang/project-rfc-2229#7
Closes rust-lang/project-rfc-2229#9
Closes rust-lang/project-rfc-2229#6
Closes rust-lang/project-rfc-2229#19

r? `@nikomatsakis`
2020-11-17 03:56:03 +00:00
bors 9b2b02a840 Auto merge of #78313 - lcnr:somebody-fold-me, r=nikomatsakis
TypeFoldable: take self by value

Implements https://github.com/rust-lang/compiler-team/issues/371 which is currently still in FCP.

r? `@nikomatsakis`
2020-11-17 01:14:54 +00:00
lcnr a6cbd64dae words 2020-11-16 22:42:09 +01:00
Bastian Kauschke 2bf93bd852 compiler: fold by value 2020-11-16 22:34:57 +01:00
Mara Bos 835faa532f
Rollup merge of #79032 - lcnr:arg-count, r=varkor
improve type const mismatch errors

Doesn't completely remove `check_generic_arg_count` as that would have required some more complex changes but
instead checks type and const params in only one step. Also moved the help added by `@JulianKnodt` in #75611 to `generic_arg_mismatch_err`.

r? `@varkor` cc `@petrochenkov`
2020-11-16 17:26:35 +01:00
Bastian Kauschke 69b43c209c improve error message for const ty param mismatch 2020-11-16 16:07:59 +01:00
Aman Arora 40dfe1eddd Ignore doctest for capture analysis examples 2020-11-15 18:53:03 -05:00
Aman Arora bb8c5e5d8b Fix case when ExprUseVisitor is called after typeck writeback
Clippy uses `ExprUseVisitor` and atleast in some cases it runs
after writeback.

We currently don't writeback the min_capture results of closure
capture analysis since no place within the compiler itself uses it.

In the short term to fix clippy we add a fallback when walking captures
of a closure to check if closure_capture analysis has any entries in it.

Writeback for closure_min_captures will be implemented in
rust-lang/project-rfc-2229#18
2020-11-15 17:09:51 -05:00
Jonas Schievink 00396cb23a
Rollup merge of #79019 - lcnr:generic-arg-validation, r=petrochenkov
astconv: extract closures into a separate trait

Am currently looking into completely removing `check_generic_arg_count` and `create_substs_for_generic_args` was somewhat difficult to understand for me so I moved these closures into a trait.

This should not have changed the behavior of any of these methods
2020-11-15 13:39:50 +01:00
Jonas Schievink 8825942e86
Rollup merge of #77802 - jyn514:bootstrap-specific, r=nikomatsakis
Allow making `RUSTC_BOOTSTRAP` conditional on the crate name

Motivation: This came up in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Require.20users.20to.20confirm.20they.20know.20RUSTC_.E2.80.A6.20compiler-team.23350/near/208403962) for https://github.com/rust-lang/compiler-team/issues/350.
See also https://github.com/rust-lang/cargo/pull/6608#issuecomment-458546258; this implements https://github.com/rust-lang/cargo/issues/6627.
The goal is for this to eventually allow prohibiting setting `RUSTC_BOOTSTRAP` in build.rs (https://github.com/rust-lang/cargo/issues/7088).

## User-facing changes

- `RUSTC_BOOTSTRAP=1` still works; there is no current plan to remove this.
- Things like `RUSTC_BOOTSTRAP=0` no longer activate nightly features. In practice this shouldn't be a big deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone uses `RUSTC_BOOTSTRAP=1` anyway.
- `RUSTC_BOOTSTRAP=x` will enable nightly features only for crate `x`.
- `RUSTC_BOOTSTRAP=x,y` will enable nightly features only for crates `x` and `y`.

## Implementation changes

The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

I'm not sure whether this counts as T-compiler or T-lang; _technically_ RUSTC_BOOTSTRAP is an implementation detail, but it's been used so much it seems like this counts as a language change too.

r? `@joshtriplett`
cc `@Mark-Simulacrum` `@hsivonen`
2020-11-15 13:39:43 +01:00
LeSeulArtichaut 65cdc21f06 Set the default BreakTy to ! 2020-11-14 21:46:39 +01:00
LeSeulArtichaut 23feec3977 Use TypeVisitor::BreakTy in ProhibitOpaqueVisitor 2020-11-14 21:17:17 +01:00
LeSeulArtichaut e0f3119103 Introduce TypeVisitor::BreakTy 2020-11-14 20:25:27 +01:00
Aman Arora c50e57f946 Log closure as well 2020-11-13 16:10:12 -05:00
Bastian Kauschke 06c9c599ed lessen restriction in check_kind_count 2020-11-13 19:12:49 +01:00
Bastian Kauschke 49c0b318df tbh what 2020-11-13 18:56:39 +01:00
Bastian Kauschke 894b1f7d3d extract closures into a separate trait 2020-11-13 15:49:17 +01:00
Rune Tynan 1e9d5c70c1
Minor stylistic / review changes 2020-11-11 20:16:31 -05:00
Rune Tynan 91eabf59d5
Add a sane error for rust-call functions not taking tuples during type checking, and associated UI tests 2020-11-11 18:15:39 -05:00
Nicholas-Baron 261ca04c92 Changed unwrap_or to unwrap_or_else in some places.
The discussion seems to have resolved that this lint is a bit "noisy" in
that applying it in all places would result in a reduction in
readability.

A few of the trivial functions (like `Path::new`) are fine to leave
outside of closures.

The general rule seems to be that anything that is obviously an
allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it
is a 0-sized allocation.
2020-11-10 20:07:47 -08:00
Aman Arora deeb025f39 Address review comments 2 2020-11-10 20:58:58 -05:00
Aman Arora 43423f67a0 Address review comments 2020-11-10 20:58:57 -05:00
Aman Arora abc40040be Remove local testing env var 2020-11-10 20:58:57 -05:00
Roxane Fruytier 825e9e45d1 Reduce verbosity of capture analysis logs
Co-authored-by: Jenny Wills <wills.jenniferg@gmail.com>
Co-authored-by: Aman Arora <me@aman-arora.com>
2020-11-10 20:58:55 -05:00
Aman Arora 8f0c0d656d Initial work for doing minimum capture analysis for RFC-2229
Co-authored-by: Chris Pardy <chrispardy36@gmail.com>
Co-authored-by: Logan Mosier <logmosier@gmail.com>
2020-11-10 20:58:54 -05:00
Aman Arora 145312075f Add helper function for Capture Esclations and expressions
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
2020-11-10 20:58:53 -05:00
Aman Arora 58e8f8fd2c Add initial set of testcases for RFC 2229
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
2020-11-10 20:58:52 -05:00
Aman Arora 88310cc0eb Indroduce feature flag for RFC-2229
Signed-off-by: Aman Arora <me@aman-arora.com>
2020-11-10 20:58:28 -05:00
Aman Arora 127a6ede1d Use Places to express closure/generator Captures
Co-authored-by: Archer Zhang <archer.xn@gmail.com>
2020-11-10 20:44:47 -05:00
Jonas Schievink 105f4b8792
Rollup merge of #78875 - petrochenkov:cleantarg, r=Mark-Simulacrum
rustc_target: Further cleanup use of target options

Follow up to https://github.com/rust-lang/rust/pull/77729.

Implements items 2 and 4 from the list in https://github.com/rust-lang/rust/pull/77729#issue-500228243.

The first commit collapses uses of `target.options.foo` into `target.foo`.

The second commit renames some target options to avoid tautology:
`target.target_endian` -> `target.endian`
`target.target_c_int_width` -> `target.c_int_width`
`target.target_os` -> `target.os`
`target.target_env` -> `target.env`
`target.target_vendor` -> `target.vendor`
`target.target_family` -> `target.os_family`
`target.target_mcount` -> `target.mcount`

r? `@Mark-Simulacrum`
2020-11-10 14:45:21 +01:00
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
Vadim Petrochenkov bf66988aa1 Collapse all uses of target.options.foo into target.foo
with an eye on merging `TargetOptions` into `Target`.

`TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
2020-11-08 17:29:13 +03:00
Joshua Nelson 622c48e4f1 Allow making RUSTC_BOOTSTRAP conditional on the crate name
The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

  There is a user-facing change here: things like `RUSTC_BOOTSTRAP=0` no
  longer active nightly features. In practice this shouldn't be a big
  deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone
  uses `RUSTC_BOOTSTRAP=1` anyway.

- Add tests

  Check against `Cheat`, not whether nightly features are allowed.
  Nightly features are always allowed on the nightly channel.

- Only call `is_nightly_build()` once within a function

- Use booleans consistently for rustc_incremental

  Sessions can't be passed through threads, so `read_file` couldn't take a
  session. To be consistent, also take a boolean in `write_file_header`.
2020-11-07 13:45:11 -05: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