Commit graph

2150 commits

Author SHA1 Message Date
Nicholas Nethercote
056d48a2c9 Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Nicholas Nethercote
8cddcd39ba Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Matthias Krüger
4e7497bda0
Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm
Stabilize `iter::zip`

Hello all!

As the tracking issue (#83574) for `iter::zip` completed the final commenting period without any concerns being raised, I hereby submit this stabilization PR on the issue.

As the pull request that introduced the feature (#82917) states, the `iter::zip` function is a shorter way to zip two iterators. As it's generally a quality-of-life/ergonomic improvement, it has been integrated into the codebase without any trouble, and has been
used in many places across the rust compiler and standard library since March without any issues.

For more details, I would refer to `@cuviper's` original PR, or the [function's documentation](https://doc.rust-lang.org/std/iter/fn.zip.html).
2021-12-15 01:28:08 +01:00
Matthias Krüger
272188eecd
Rollup merge of #90939 - estebank:wg-af-polish, r=tmandry
Tweak errors coming from `for`-loop, `?` and `.await` desugaring

 * Suggest removal of `.await` on non-`Future` expression
 * Keep track of obligations introduced by desugaring
 * Remove span pointing at method for obligation errors coming from desugaring
 * Point at called local sync `fn` and suggest making it `async`

```
error[E0277]: `()` is not a future
  --> $DIR/unnecessary-await.rs:9:10
   |
LL |     boo().await;
   |     -----^^^^^^ `()` is not a future
   |     |
   |     this call returns `()`
   |
   = help: the trait `Future` is not implemented for `()`
help: do not `.await` the expression
   |
LL -     boo().await;
LL +     boo();
   |
help: alternatively, consider making `fn boo` asynchronous
   |
LL | async fn boo () {}
   | +++++
```

Fix #66731.
2021-12-15 01:28:04 +01:00
PFPoitras
304ede6bcc Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
Chase Wilson
2af02abd93
Minor cleanup 2021-12-14 13:40:16 -06:00
Michael Goulet
f29fb4792b Make TyS::is_suggestable more structual 2021-12-14 11:32:06 -08:00
Chase Wilson
2b46c7c906
Added -Z layout_seed for allowing user-defined randomization seeds 2021-12-14 12:48:41 -06:00
Aaron Hill
4d1d66b812
Use tcx.def_path_hash in ExistentialPredicate.stable_cmp
This avoids a needless query invocation
2021-12-14 11:27:41 -05:00
lcnr
023b56572f add some comments 2021-12-14 13:32:42 +01:00
lcnr
992efa68b7 replace DefId with D in SimplifiedType 2021-12-14 13:32:42 +01:00
lcnr
dcd716fee2 extend simplify_type 2021-12-14 13:32:42 +01:00
Matthias Krüger
97e844a032 fix clippy::single_char_pattern perf findings 2021-12-14 12:40:28 +01:00
b-naber
399ab40dbd get rid of normalize_generic_arg... queries 2021-12-13 23:05:25 +01:00
Esteban Kuber
f640438b40 Keep info on pre-desugaring expression for better "incorrect .await" suggestion
Keep the `HirId` of `.await`ed expressions so in the case of a `fn` call
on on a sync `fn`, we can suggest maybe turning it into an `async fn`.
2021-12-13 17:09:16 +00:00
Esteban Kuber
caf0c1bb1c Reduce verbosity for ? on non-Try expressions 2021-12-13 17:09:15 +00:00
Esteban Kuber
75b62757e4 Reduce verbosity when calling for-loop on non-Iterator expression 2021-12-13 17:09:15 +00:00
Esteban Kuber
7227a87371 When .await is called on a non-Future expression, suggest removal
Keep track of the origin of a `T: Future` obligation when caused by an
`.await` expression.

Address #66731.
2021-12-13 17:09:15 +00:00
Alan Egerton
5920a1d948
Avoid cloning refcounted types during folding 2021-12-13 14:27:26 +00:00
bors
22f8bde876 Auto merge of #91549 - fee1-dead:const_env, r=spastorino
Eliminate ConstnessAnd again

Closes #91489.
Closes #89432.

Reverts #91491.
Reverts #89450.

r? `@spastorino`
2021-12-12 22:15:32 +00:00
bors
753e569c9c Auto merge of #90207 - BoxyUwU:stabilise_cg_defaults, r=lcnr
Stabilise `feature(const_generics_defaults)`

`feature(const_generics_defaults)` is complete implementation wise and has a pretty extensive test suite so I think is ready for stabilisation.

needs stabilisation report and maybe an RFC 😅

r? `@lcnr`
cc `@rust-lang/project-const-generics`
2021-12-12 14:24:23 +00:00
Deadbeef
83587e8d30
Small performance tweaks 2021-12-12 12:35:01 +08:00
Deadbeef
17b53b9645
Remap more env constness for queries 2021-12-12 12:35:00 +08:00
Deadbeef
42963f4d50
Query modifier 2021-12-12 12:35:00 +08:00
Deadbeef
84b1d859c8
Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"
This reverts commit ff2439b7b9, reversing
changes made to 2a9e0831d6.
2021-12-12 12:34:46 +08:00
Deadbeef
5166f68754
Fix #91489 2021-12-12 12:09:27 +08:00
bors
229d0a9412 Auto merge of #91769 - estebank:type-trait-bound-span-2, r=oli-obk
Tweak assoc type obligation spans

* Point at RHS of associated type in obligation span
* Point at `impl` assoc type on projection error
* Reduce verbosity of recursive obligations
* Point at source of binding lifetime obligation
* Tweak "required bound" note
* Tweak "expected... found opaque (return) type" labels
* Point at set type in impl assoc type WF errors

r? `@oli-obk`

This is a(n uncontroversial) subset of #85799.
2021-12-11 21:57:19 +00:00
bors
928783de66 Auto merge of #91799 - matthiaskrgr:rollup-b38xx6i, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #83174 (Suggest using a temporary variable to fix borrowck errors)
 - #89734 (Point at capture points for non-`'static` reference crossing a `yield` point)
 - #90270 (Make `Borrow` and `BorrowMut` impls `const`)
 - #90741 (Const `Option::cloned`)
 - #91548 (Add spin_loop hint for RISC-V architecture)
 - #91721 (Minor improvements to `future::join!`'s implementation)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-11 18:56:59 +00:00
Matthias Krüger
7bba5c163c
Rollup merge of #89734 - estebank:issue-72312, r=nikomatsakis
Point at capture points for non-`'static` reference crossing a `yield` point

```
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
  --> $DIR/issue-72312.rs:10:24
   |
LL |     pub async fn start(&self) {
   |                        ^^^^^ this data with an anonymous lifetime `'_`...
...
LL |         require_static(async move {
   |         -------------- ...is required to live as long as `'static` here...
LL |             &self;
   |             ----- ...and is captured here
   |
note: `'static` lifetime requirement introduced by this trait bound
  --> $DIR/issue-72312.rs:2:22
   |
LL | fn require_static<T: 'static>(val: T) -> T {
   |                      ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0759`.
```

Fix #72312.
2021-12-11 17:35:23 +01:00
Matthias Krüger
433a13b473
Rollup merge of #83174 - camelid:borrow-help, r=oli-obk
Suggest using a temporary variable to fix borrowck errors

Fixes #77834.

In Rust, nesting method calls with both require `&mut` access to `self`
produces a borrow-check error:

    error[E0499]: cannot borrow `*self` as mutable more than once at a time
     --> src/lib.rs:7:14
      |
    7 |     self.foo(self.bar());
      |     ---------^^^^^^^^^^-
      |     |    |   |
      |     |    |   second mutable borrow occurs here
      |     |    first borrow later used by call
      |     first mutable borrow occurs here

That's because Rust has a left-to-right evaluation order, and the method
receiver is passed first. Thus, the argument to the method cannot then
mutate `self`.

There's an easy solution to this error: just extract a local variable
for the inner argument:

    let tmp = self.bar();
    self.foo(tmp);

However, the error doesn't give any suggestion of how to solve the
problem. As a result, new users may assume that it's impossible to
express their code correctly and get stuck.

This commit adds a (non-structured) suggestion to extract a local
variable for the inner argument to solve the error. The suggestion uses
heuristics that eliminate most false positives, though there are a few
false negatives (cases where the suggestion should be emitted but is
not). Those other cases can be implemented in a future change.
2021-12-11 17:35:23 +01:00
Matthias Krüger
7083f8edfd
Rollup merge of #91640 - cjgillot:in-band-collect, r=oli-obk
Simplify collection of in-band lifetimes

Split from https://github.com/rust-lang/rust/pull/91403

r? ````@oli-obk````
2021-12-11 16:02:46 +01:00
Matthias Krüger
1de7815ebb
Rollup merge of #91617 - nnethercote:improve-List-readability, r=lcnr
Improve the readability of `List<T>`.

This commit does the following.
- Expands on some of the things already mentioned in comments.
- Describes the uniqueness assumption, which is critical but wasn't
  mentioned at all.
- Rewrites `empty()` into a clearer form, as provided by Daniel
  Henry-Mantilla on Zulip.
- Reorders things slightly so that more important things
  are higher up, and incidental things are lower down, which makes
  reading the code easier.

r? ````@lcnr````
2021-12-11 16:02:45 +01:00
Esteban Kuber
5e1972eba7 Tweak assoc type obligation spans
* Point at RHS of associated type in obligation span
* Point at `impl` assoc type on projection error
* Reduce verbosity of recursive obligations
* Point at source of binding lifetime obligation
* Tweak "required bound" note
* Tweak "expected... found opaque (return) type" labels
* Point at set type in impl assoc type WF errors
2021-12-11 02:32:15 +00:00
Noah Lev
e27315268b Suggest using a temporary variable to fix borrowck errors
In Rust, nesting method calls with both require `&mut` access to `self`
produces a borrow-check error:

    error[E0499]: cannot borrow `*self` as mutable more than once at a time
     --> src/lib.rs:7:14
      |
    7 |     self.foo(self.bar());
      |     ---------^^^^^^^^^^-
      |     |    |   |
      |     |    |   second mutable borrow occurs here
      |     |    first borrow later used by call
      |     first mutable borrow occurs here

That's because Rust has a left-to-right evaluation order, and the method
receiver is passed first. Thus, the argument to the method cannot then
mutate `self`.

There's an easy solution to this error: just extract a local variable
for the inner argument:

    let tmp = self.bar();
    self.foo(tmp);

However, the error doesn't give any suggestion of how to solve the
problem. As a result, new users may assume that it's impossible to
express their code correctly and get stuck.

This commit adds a (non-structured) suggestion to extract a local
variable for the inner argument to solve the error. The suggestion uses
heuristics that eliminate most false positives, though there are a few
false negatives (cases where the suggestion should be emitted but is
not). Those other cases can be implemented in a future change.
2021-12-10 14:34:00 -08:00
Ellen
69d2d735bc remove feature gate and cleanup code 2021-12-10 19:20:31 +00:00
Esteban Kuber
10a74ac2e0 Use a more accurate Span for 'static obligation from return type 2021-12-10 03:08:24 +00:00
Nicholas Nethercote
769a707269 Improve the readability of List<T>.
This commit does the following.
- Expands on some of the things already mentioned in comments.
- Describes the uniqueness assumption, which is critical but wasn't
  mentioned at all.
- Rewrites `empty()` into a clearer form, as provided by Daniel
  Henry-Mantilla on Zulip.
- Reorders things slightly so that more important things
  are higher up, and incidental things are lower down, which makes
  reading the code easier.
2021-12-09 15:20:58 +11:00
est31
15de4cbc4b Remove redundant [..]s 2021-12-09 00:01:29 +01:00
Matthias Krüger
317f750ff7
Rollup merge of #91551 - b-naber:const-eval-normalization-ice, r=oli-obk
Allow for failure of subst_normalize_erasing_regions in const_eval

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

Using associated types that cannot be normalized previously resulted in an ICE. We now allow for normalization failure and return a "TooGeneric" error in that case.

r? ```@RalfJung``` maybe?
2021-12-08 16:08:07 +01:00
Camille GILLOT
8576ab45e4 Store impl_trait_fn inside OpaqueTyOrigin. 2021-12-07 21:30:45 +01:00
bors
0fb1c371d4 Auto merge of #91279 - scottmcm:small-refactor, r=nagisa
Small mir-opt refactor

Hopefully-non-controversial changes from some not-ready-yet work that I'd figured I'd submit on their own.
2021-12-06 13:04:18 +00:00
b-naber
61cab770bd allow for failure of subst_normalize_erasing_regions in const_eval 2021-12-05 12:43:39 +01:00
bors
bdaa901049 Auto merge of #91475 - ecstatic-morse:mir-pass-manager3, r=oli-obk
Add a MIR pass manager (Taylor's Version)

The final draft of #91386 and #77665.

While the compile-time constraints in #91386 are cool, I decided on a more minimal approach for now. I want to explore phase constraints and maybe relative-ordering constraints in the future, though. This should preserve existing behavior **exactly** (please let me know if it doesn't) while making the following changes to the way we organize things today:

- Each `MirPhase` now corresponds to a single MIR pass. `run_passes` is not responsible for listing the correct MIR phase.
- `run_passes` no longer silently skips passes if the declared MIR phase is greater than or equal to the body's. This has bitten me multiple times. If you want this behavior, you can always branch on `body.phase` yourself.
- If your pass is solely to emit errors, you can use the `MirLint` interface instead, which gets a shared reference to `Body` instead of a mutable one. By differentiating the two, I hope to make it clearer in the short term where lints belong in the pipeline. In the long term perhaps we could enforce this at compile-time?
- MIR is no longer dumped for passes that aren't enabled, or for lints.

I tried to check that `-Zvalidate` still works correctly, since the MIR phase is now updated as soon as the associated pass is done, instead of at the end of all the passes in `run_passes`. However, it looks like `-Zvalidate` is broken with current nightlies anyways 😢 (it spits out a bunch of errors).

cc `@oli-obk` `@wesleywiser`

r? rust-lang/wg-mir-opt
2021-12-05 03:41:18 +00:00
Matthias Krüger
23012b5200
Rollup merge of #91355 - alexcrichton:stabilize-thread-local-const, r=m-ou-se
std: Stabilize the `thread_local_const_init` feature

This commit is intended to follow the stabilization disposition of the
FCP that has now finished in #84223. This stabilizes the ability to flag
thread local initializers as `const` expressions which enables the macro
to generate more efficient code for accessing it, notably removing
runtime checks for initialization.

More information can also be found in #84223 as well as the tests where
the feature usage was removed in this PR.

Closes #84223
2021-12-05 00:38:00 +01:00
Matthias Krüger
0311cfa88c
Rollup merge of #90519 - estebank:issue-84003, r=petrochenkov
Keep spans for generics in `#[derive(_)]` desugaring

Keep the spans for generics coming from a `derive`d Item, so that errors
and suggestions have better detail.

Fix #84003.
2021-12-04 10:42:20 +01:00
bors
887999d163 Auto merge of #88439 - cynecx:unwind_asm, r=Amanieu
Unwinding support for inline assembly

r? `@Amanieu`
2021-12-04 05:59:16 +00:00
Matthias Krüger
f99cd4022a
Rollup merge of #90538 - camelid:doc-recur-ty, r=estebank
Document how recursion is handled for `ty::Ty`

Based on this forum discussion:
https://internals.rust-lang.org/t/recursive-type-representation-in-rustc/15235/4

cc `@estebank`
2021-12-04 02:26:20 +01:00
Amanieu d'Antras
940b2eabad Add initial AST and MIR support for unwinding from inline assembly 2021-12-03 23:51:46 +01:00
Noah Lev
9931782a38 Document how recursion is handled for ty::Ty
Based on this forum discussion:
https://internals.rust-lang.org/t/recursive-type-representation-in-rustc/15235/4
2021-12-03 11:30:28 -08:00
Esteban Kuber
962b2197a5 Annotate derived spans and move span suggestion code
* Annotate `derive`d spans from the user's code with the appropciate context
* Add `Span::can_be_used_for_suggestion` to query if the underlying span
  at the users' code
2021-12-03 18:41:40 +00:00
Santiago Pastorino
85b723c4e6
Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"
This reverts commit 18bb8c61a9, reversing
changes made to d9baa36190.
2021-12-03 10:11:21 -03:00
Matthias Krüger
f056f0d1b4
Rollup merge of #91462 - b-naber:use-try-normalize-erasing-regions, r=jackh726
Use try_normalize_erasing_regions in needs_drop

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

r? ``@jackh726``
2021-12-03 06:24:17 +01:00
Matthias Krüger
570dc70a2b
Rollup merge of #90854 - sanxiyn:unsized-and-uninhabited, r=estebank
Type can be unsized and uninhabited

Fix #88150.
2021-12-03 06:24:12 +01:00
Dylan MacKenzie
c1a501b131 Implement a pass manager 2021-12-02 17:31:38 -08:00
b-naber
a11994e423 use try_normalize_erasing_regions in needs_drop 2021-12-02 23:27:08 +01:00
bors
ff23ad3179 Auto merge of #91469 - matthiaskrgr:rollup-xom3j55, r=matthiaskrgr
Rollup of 12 pull requests

Successful merges:

 - #89954 (Fix legacy_const_generic doc arguments display)
 - #91321 (Handle placeholder regions in NLL type outlive constraints)
 - #91329 (Fix incorrect usage of `EvaluatedToOk` when evaluating `TypeOutlives`)
 - #91364 (Improve error message for incorrect field accesses through raw pointers)
 - #91387 (Clarify and tidy up explanation of E0038)
 - #91410 (Move `#![feature(const_precise_live_drops)]` checks earlier in the pipeline)
 - #91435 (Improve diagnostic for missing half of binary operator in `if` condition)
 - #91444 (disable tests in Miri that take too long)
 - #91457 (Add additional test from rust issue number 91068)
 - #91460 (Document how `last_os_error` should be used)
 - #91464 (Document file path case sensitivity)
 - #91466 (Improve the comments in `Symbol::interner`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-02 21:58:48 +00:00
Matthias Krüger
39641319ad
Rollup merge of #91410 - ecstatic-morse:const-precise-live-drops-take-2, r=oli-obk
Move `#![feature(const_precise_live_drops)]` checks earlier in the pipeline

Should mitigate the issues found during MCP on #73255.

Once this is done, we should clean up the queries a bit, since I think `mir_drops_elaborated_and_const_checked` can be merged back into `mir_promoted`.

Fixes #90770.

cc ``@rust-lang/wg-const-eval``
r? ``@nikomatsakis`` (since they reviewed #71824)
2021-12-02 22:16:13 +01:00
bors
acbe4443cc Auto merge of #91318 - eggyal:reduce-boilerplate-around-infallible-folders, r=jackh726
Reduce boilerplate around infallible folders

Further to https://github.com/rust-lang/rust/pull/91230#issuecomment-981059666

r? `@jackh726`
2021-12-02 19:12:00 +00:00
Alan Egerton
cf683e644f
Rename TypeFolderFallible to FallibleTypeFolder 2021-12-02 16:14:18 +00:00
eggyal
d79e17daf0
Update compiler/rustc_middle/src/ty/fold.rs
Co-authored-by: lcnr <rust@lcnr.de>
2021-12-02 16:14:16 +00:00
Alan Egerton
bfc434b6d0
Reduce boilerplate around infallible folders 2021-12-02 16:14:16 +00:00
bors
e5038e2099 Auto merge of #91455 - matthiaskrgr:rollup-gix2hy6, r=matthiaskrgr
Rollup of 4 iffy pull requests

Successful merges:

 - #89234 (Disallow non-c-like but "fieldless" ADTs from being casted to integer if they use arbitrary enum discriminant)
 - #91045 (Issue 90702 fix: Stop treating some crate loading failures as fatal errors)
 - #91394 (Bump stage0 compiler)
 - #91411 (Enable svh tests on msvc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-02 14:53:20 +00:00
Matthias Krüger
d96ce3ea8e
Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbini
Bump stage0 compiler

r? `@pietroalbini` (or anyone else)
2021-12-02 15:52:03 +01:00
bors
18bb8c61a9 Auto merge of #91354 - fee1-dead:const_env, r=spastorino
Cleanup: Eliminate ConstnessAnd

This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature.

We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`.

This is a continuation of https://github.com/rust-lang/rust/pull/90274.

r? `@oli-obk`

cc `@spastorino` `@ecstatic-morse`
2021-12-02 11:48:58 +00:00
Gary Guo
f7ef1c9f41 Disallow non-c-like but "fieldless" ADTs from being casted to integer...
... if they use arbitrary enum discriminant. Code like

```rust
enum Enum {
    Foo = 1,
    Bar(),
    Baz{}
}
```

seems to be unintentionally allowed so we couldn't disallow them now,
but we could disallow them if arbitrary enum discriminant is used before
1.56 hits stable.
2021-12-01 19:59:15 +00:00
Deadbeef
6b07cec05c
Cache with consistent env and bound 2021-12-01 23:22:42 +08:00
bors
f04a2f4b8e Auto merge of #91255 - b-naber:normalization-ice, r=jackh276
Implement version of normalize_erasing_regions that allows for normalization failure

Fixes https://github.com/rust-lang/rust/issues/59324
Fixes https://github.com/rust-lang/rust/issues/67684
Fixes https://github.com/rust-lang/rust/issues/69398
Fixes https://github.com/rust-lang/rust/issues/71113
Fixes https://github.com/rust-lang/rust/issues/82079
Fixes #85103
Fixes https://github.com/rust-lang/rust/issues/88856
Fixes #91231
Fixes https://github.com/rust-lang/rust/issues/91234

Previously we called `normalize_erasing_regions` inside `layout_of`. `normalize_erasing_regions` assumes that the normalization succeeds. Since some `layout_of` calls happen before typecheck has finished, we introduce a new variant that allows for returning an error.
2021-12-01 13:33:33 +00:00
b-naber
6952470095 rebase 2021-12-01 13:15:59 +01:00
b-naber
4d9a0bf21b address review 2021-12-01 12:12:40 +01:00
b-naber
84bcd40927 fix query description 2021-12-01 12:12:40 +01:00
b-naber
0b32cf3a8d remove static_assert_size on InterpError 2021-12-01 12:12:39 +01:00
b-naber
ff448cfcee implement version of normalize_erasing_regions that doesn't assume value is normalizable 2021-12-01 12:12:38 +01:00
Matthias Krüger
d93df5775c
Rollup merge of #91207 - richkadel:rk-bump-coverage-version, r=tmandry
Add support for LLVM coverage mapping format versions 5 and 6

This PR cherry-pick's Swatinem's initial commit in unsubmitted PR #90047.

My additional commit augments Swatinem's great starting point, but adds full support for LLVM
Coverage Mapping Format version 6, conditionally, if compiling with LLVM 13.

Version 6 requires adding the compilation directory when file paths are
relative, and since Rustc coverage maps use relative paths, we should
add the expected compilation directory entry.

Note, however, that with the compilation directory, coverage reports
from `llvm-cov show` can now report file names (when the report includes
more than one file) with the full absolute path to the file.

This would be a problem for test results, but the workaround (for the
rust coverage tests) is to include an additional `llvm-cov show`
parameter: `--compilation-dir=.`
2021-12-01 10:50:20 +01:00
Dylan MacKenzie
d707707364 Add "is" methods for projections to a given index 2021-11-30 17:17:14 -08:00
Matthias Krüger
dc78cd4c61
Rollup merge of #91294 - cjgillot:process-elem, r=jackh726
Visit type in process_projection_elem.

Instead of reimplementing it for each visitor.
2021-11-30 23:43:31 +01:00
Mark Rousskov
971c549ca3 re-format with new rustfmt 2021-11-30 13:08:41 -05:00
bors
90912e68ab Auto merge of #91330 - cjgillot:no-ee-features, r=Aaron1011
Remove eval_always for lib_features.

r? `@Aaron1011`
2021-11-30 07:40:08 +00:00
Alex Crichton
a0c959750a std: Stabilize the thread_local_const_init feature
This commit is intended to follow the stabilization disposition of the
FCP that has now finished in #84223. This stabilizes the ability to flag
thread local initializers as `const` expressions which enables the macro
to generate more efficient code for accessing it, notably removing
runtime checks for initialization.

More information can also be found in #84223 as well as the tests where
the feature usage was removed in this PR.

Closes #84223
2021-11-29 07:23:46 -08:00
bors
6db0a0e9a4 Auto merge of #91299 - cjgillot:expect-ldid, r=petrochenkov
Take a LocalDefId in expect_*item.

Items and item-likes are always HIR owners.
When trying to find such nodes, there is no ambiguity, the `LocalDefId` and the `HirId::owner` always match.
In such cases, `local_def_id_to_hir_id` does not carry any meaningful information, so we can just skip calling it altogether.
2021-11-29 15:02:01 +00:00
Deadbeef
8710a2e169
Reformat everything 2021-11-29 21:19:51 +08:00
Deadbeef
fdf5322169
Fix tools 2021-11-29 21:19:50 +08:00
Oli Scherer
f394bb57bb
Always use const param envs for const eval.
Nothing else makes sense, and there is no "danger" in doing so, as it only does something if there are const bounds, which are unstable. This used to happen implicitly via the inferctxt before, which was much more fragile.
2021-11-29 21:19:50 +08:00
Oli Scherer
a9a79f657c
Completely remove ConstnessAnd 2021-11-29 21:19:49 +08:00
Oli Scherer
a848c4ba3f
Avoid storing the ImplPolarity and Constness next to a TraitRef and use TraitPredicate instead 2021-11-29 21:19:49 +08:00
Oli Scherer
d161cc2071
Replace ConstnessAnd<TraitRef> with TraitPredicate which conveys the same information 2021-11-29 21:19:48 +08:00
Oli Scherer
b16c811f1c
Prefer TraitPredicate over ConstnessAnd<TraitRef> 2021-11-29 21:19:48 +08:00
Oli Scherer
e37947f097
Re-use constness_for_typeck instead of rolling it ourselves 2021-11-29 21:19:46 +08:00
Oli Scherer
721ffd14c3
Add constness to ParamEnv
This now causes a lot of queries to be executed twice, as reveal_all forces NotConst
2021-11-29 21:19:46 +08:00
Oli Scherer
22eeff700e
Prepare for more ParamEnv flags 2021-11-29 21:19:42 +08:00
Camille GILLOT
06b2e659d3 Remove unused root_parent. 2021-11-28 21:48:28 +01:00
Camille GILLOT
877b2d79d9 Remove eval_always for lib_features. 2021-11-28 21:13:36 +01:00
Camille GILLOT
5fb4648757 Take a LocalDefId in expect_*item. 2021-11-28 21:09:45 +01:00
Camille GILLOT
29b30a9bd2 Visit type in process_projection_elem. 2021-11-27 17:39:27 +01:00
Alan Egerton
51e15ac709
Remove erroneous merge conflict 2021-11-27 11:53:00 +00:00
Scott McMurray
b215a32af3 Small mir-opt refactor
Hopefully-non-controversial changes from some not-ready-yet work that I'd figured I'd submit on their own.
2021-11-26 18:18:14 -08:00
LeSeulArtichaut
30bf20a692
Unwrap the results of type folders
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:38:25 +00:00
LeSeulArtichaut
6dc3dae46f
Adapt TypeFolder implementors to return a Result
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:25:16 +00:00
LeSeulArtichaut
6e3fa20b00
Make TypeFoldable implementors short-circuit on error
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:17:59 +00:00
LeSeulArtichaut
c5f0d0ebb4
Make TypeFolder::fold_* return Result 2021-11-26 06:53:35 +00:00
bors
dd549dcab4 Auto merge of #90580 - cjgillot:no-ee-upvar, r=Aaron1011
Remove eval_always from upvars.

Split off https://github.com/rust-lang/rust/pull/86056
r? `@ghost`
2021-11-25 19:43:56 +00:00
Matthias Krüger
5fff1d77e7
Rollup merge of #91162 - RalfJung:miri-shift-truncation, r=oli-obk
explain why CTFE/Miri perform truncation on shift offset

Closes https://github.com/rust-lang/miri/issues/1920
2021-11-25 15:05:39 +01:00
Matthias Krüger
6970cf5a23
Rollup merge of #91096 - compiler-errors:elaborate_opaque_trait, r=estebank
Print associated types on opaque `impl Trait` types

This PR generalizes #91021, printing associated types for all opaque `impl Trait` types instead of just special-casing for future.

before:
```
error[E0271]: type mismatch resolving `<impl Iterator as Iterator>::Item == u32`
```

after:
```
error[E0271]: type mismatch resolving `<impl Iterator<Item = usize> as Iterator>::Item == u32`
```

---

Questions:
1. I'm kinda lost in binders hell with this one. Is all of the `rebind`ing necessary?
2. Is there a map collection type that will give me a stable iteration order? Doesn't seem like TraitRef is Ord, so I can't just sort later..
3. I removed the logic that suppresses printing generator projection types. It creates outputs like this [gist](https://gist.github.com/compiler-errors/d6f12fb30079feb1ad1d5f1ab39a3a8d). Should I put that back?
4. I also added spaces between traits, `impl A+B` -> `impl A + B`. I quite like this change, but is there a good reason to keep it like that?

r? ````@estebank````
2021-11-25 15:05:37 +01:00
bors
c6a7ca196a Auto merge of #90579 - cjgillot:no-ee-ii, r=Aaron1011
Remove eval_always for inherent_impls.

Split off https://github.com/rust-lang/rust/pull/86056
r? `@ghost`
2021-11-24 12:51:19 +00:00
Ralf Jung
5f6ccf6121 document BinOp behavior quirks in the corresponding enum 2021-11-23 20:30:26 -05:00
Arpad Borsos
566ad8da45 Update CoverageMappingFormat Support to Version6
Version 5 adds Branch Regions which are a prerequisite for branch coverage.
Version 6 can use the zeroth filename as prefix for other relative files.
2021-11-23 15:49:03 -08:00
Michael Goulet
9cc117930b Fix printing unit return ty, don't elaborate FnOnce unless we see it 2021-11-23 11:05:07 -08:00
Michael Goulet
471334e996 Suppress noisy generator associated type 2021-11-23 10:34:16 -08:00
Michael Goulet
ce182d17f8 Elaborate trait generics and associated types 2021-11-23 10:34:16 -08:00
Michael Goulet
c969b1dea0 Add supertraits method to rustc_middle 2021-11-23 10:34:16 -08:00
Michael Goulet
8756d0701e Derive Ord and PartialOrd for TraitRef 2021-11-23 10:34:16 -08:00
Matthias Krüger
e52e3a4bb3
Rollup merge of #91148 - jhpratt:use-default-enum, r=petrochenkov
Use `derive_default_enum` in the compiler

Let's get this feature some real-world love.

``@rustbot`` label: +C-cleanup +S-waiting-on-review
2021-11-23 19:28:11 +01:00
Matthias Krüger
68a44c8228
Rollup merge of #90856 - ken-matsui:suggestion-to-wrap-vec-allocator-api-in-tuple, r=davidtwco
Suggestion to wrap inner types using 'allocator_api' in tuple

This PR provides a suggestion to wrap the inner types in tuple when being along with 'allocator_api'.

Closes https://github.com/rust-lang/rust/issues/83250

```rust
fn main() {
    let _vec: Vec<u8, _> = vec![]; //~ ERROR use of unstable library feature 'allocator_api'
}
```

```diff
 error[E0658]: use of unstable library feature 'allocator_api'
   --> $DIR/suggest-vec-allocator-api.rs:2:23
    |
 LL |     let _vec: Vec<u8, _> = vec![];
-   |                       ^
+   |                   ----^
+   |                   |
+   |                   help: consider wrapping the inner types in tuple: `(u8, _)`
    |
    = note: see issue #32838 <https://github.com/rust-lang/rust/issues/32838> for more information
    = help: add `#![feature(allocator_api)]` to the crate attributes to enable
```
2021-11-23 19:28:06 +01:00
Ken Matsui
57494f7c75
Suggestion to wrap inner types using allocator_api in tuple 2021-11-24 00:24:13 +09:00
Jacob Pratt
7b103e7dd2
Use derive_default_enum in the compiler 2021-11-22 20:17:53 -05:00
Cameron Steffen
9c83f8c4d1 Simplify for loop desugar 2021-11-21 08:15:21 -06:00
Michael Goulet
8805e934af Add space in opaque impl Trait 2021-11-20 17:02:38 -08:00
Matthias Krüger
3379721a30
Rollup merge of #91021 - compiler-errors:print_future_output, r=estebank
Elaborate `Future::Output` when printing opaque `impl Future` type

I would love to see the `Output =` type when printing type errors involving opaque `impl Future`.

[Test code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a800b481edd31575fbcaf5771a9c3678)

Before (cut relevant part of output):
```
note: while checking the return type of the `async fn`
 --> /home/michael/test.rs:5:19
  |
5 | async fn bar() -> usize {
  |                   ^^^^^ checked the `Output` of this `async fn`, found opaque type
  = note:     expected type `usize`
          found opaque type `impl Future`
```

After:
```
note: while checking the return type of the `async fn`
 --> /home/michael/test.rs:5:19
  |
5 | async fn bar() -> usize {
  |                   ^^^^^ checked the `Output` of this `async fn`, found opaque type
  = note:     expected type `usize`
          found opaque type `impl Future<Output = usize>`
```

Note the "found opaque type `impl Future<Output = usize>`" in the new output.

----

Questions:
1. We skip printing the output type when it's a projection, since I have been seeing some types like `impl Future<Output = <[static generator@/home/michael/test.rs:2:11: 2:21] as Generator<ResumeTy>>::Return>` which are not particularly helpful and leak implementation detail.
    * Am I able to normalize this type within `rustc_middle::ty::print::pretty`? Alternatively, can we normalize it when creating the diagnostic? Otherwise, I'm fine with skipping it and falling back to the old output.
    * Should I suppress any other types? I didn't encounter anything other than this generator projection type.
2. Not sure what the formatting of this should be. Do I include spaces in `Output = `?
2021-11-20 10:21:16 +01:00
Matthias Krüger
cf69f9e220
Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obk
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types

The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do.

The new helper methods will also be needed for https://github.com/rust-lang/miri/issues/1912.

r? ``````@oli-obk``````
2021-11-20 01:09:41 +01:00
bors
18fa4342fc Auto merge of #90996 - the8472:obligation-hashes2, r=matthewjasper
Optimize `impl Hash for ObligationCauseData` by not hashing `ObligationCauseCode` variant fields

Split out from #90913 since it's a [clear performance win](https://perf.rust-lang.org/compare.html?start=ad442399756573dccacb314b6bf8079964bcc72a&end=223f5e877fe93b5f437c2d703f883797913cd2b7) and should be easier to review.

It speeds up hashing for `Obligation` [deduplication](c9c4b5d727/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2355-L2356)) by only hashing the discriminant of the `ObligationCauseCode` enum instead of its contents. That shouldn't affect hash quality much since there are several other fields in `Obligation` which should be unique enough, especially the predicate itself which is hashed as an interned pointer.
2021-11-19 11:50:51 +00:00
Yuki Okushi
1576a7cc81
Rollup merge of #90990 - nnethercote:arenas-cleanup, r=oli-obk
Arenas cleanup

I was looking closely at the arenas code and here are some small improvement to readability.
2021-11-19 13:06:38 +09:00
Michael Goulet
f6392a1614 Print output ty for opaque future ty 2021-11-18 13:19:18 -08:00
Nicholas Nethercote
0a89598dbd Add some comments.
Also use `Default::default()` in one `TypedArena::default()`, for
consistency with `DroplessArena::default()`.
2021-11-19 07:52:59 +11:00
Ralf Jung
2f1a1f530b fix CTFE/Miri simd_insert/extract on array-style repr(simd) types 2021-11-18 09:10:35 -05:00
Vadim Petrochenkov
91e02177a1 rustc: Remove #[rustc_synthetic]
This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.
2021-11-18 14:32:29 +08:00
Nicholas Nethercote
552073701f Remove unnecessary lifetime argument from arena macros.
Because it's always `'tcx`. In fact, some of them use a mixture of
passed-in `$tcx` and hard-coded `'tcx`, so no other lifetime would even
work.

This makes the code easier to read.
2021-11-17 09:38:30 +11:00
bors
d914f17ca7 Auto merge of #90919 - nnethercote:rm-DropArena, r=Mark-Simulacrum
Remove `DropArena`.

Most arena-allocate types that impl `Drop` get their own `TypedArena`, but a
few infrequently used ones share a `DropArena`. This sharing adds complexity
but doesn't help performance or memory usage. Perhaps it was more effective in
the past prior to some other improvements to arenas.

This commit removes `DropArena` and the sharing of arenas via the `few`
attribute of the `arena_types` macro. This change removes over 100 lines of
code and nine uses of `unsafe` (one of which affects the parallel compiler) and
makes the remaining code easier to read.
2021-11-16 11:48:37 +00:00
Yuki Okushi
6d9c3a1b97
Rollup merge of #90910 - RalfJung:const-discriminant-empty-enum, r=petrochenkov
fix getting the discriminant of a zero-variant enum

Fixes https://github.com/rust-lang/rust/issues/89765
2021-11-16 15:59:41 +09:00
Nicholas Nethercote
fb80c73fb3 Remove DropArena.
Most arena-allocate types that impl `Drop` get their own `TypedArena`, but a
few infrequently used ones share a `DropArena`. This sharing adds complexity
but doesn't help performance or memory usage. Perhaps it was more effective in
the past prior to some other improvements to arenas.

This commit removes `DropArena` and the sharing of arenas via the `few`
attribute of the `arena_types` macro. This change removes over 100 lines of
code and nine uses of `unsafe` (one of which affects the parallel compiler) and
makes the remaining code easier to read.
2021-11-15 18:33:43 +11:00
The8472
78b5f2d2fa Simplify ObligationCauseData hash to skip ObligationCauseCode
selection deduplicates obligations through a hashset at some point, computing the hashes for ObligationCauseCode
appears to dominate the hashing cost. bodyid + span + discriminant hash hopefully will sufficiently unique
unique enough.
2021-11-14 23:49:57 +01:00
Ralf Jung
eebf676bf8 fix getting the discriminant of a zero-variant enum 2021-11-14 13:29:21 -05:00
Seo Sanghyeon
34b75664ee Type can be unsized and uninhabited 2021-11-13 15:06:22 +09:00
Matthew Jasper
ba518ffdd3 Use associated_item_def_ids more 2021-11-11 23:15:57 +00:00
bors
3d29b68077 Auto merge of #90648 - matthewjasper:assoc-item-cleanup, r=cjgillot
Assoc item cleanup

This removes some fields from ObligationCauseCode

Split out of #90639
2021-11-11 15:15:15 +00:00
bors
1d34cb4efc Auto merge of #89550 - lcnr:coherence-specialization, r=nikomatsakis
do not emit overlap errors for impls failing the orphan check

this should finally allow us to merge #86986, see https://github.com/rust-lang/rust/pull/86986#discussion_r716059345 for more details.

r? `@nikomatsakis` cc `@eddyb`
2021-11-11 05:47:37 +00:00
Matthias Krüger
0a9c1be100
Rollup merge of #90742 - est31:add_assign, r=davidtwco
Use AddAssign impl
2021-11-10 18:52:29 +01:00
lcnr
1296719c06 no overlap errors after failing the orphan check 2021-11-10 15:10:19 +01:00
inquisitivecrystal
9a987b0466 Add ty::Visibility::is_public() 2021-11-09 18:35:00 -08:00
est31
9afb241af5 Use AddAssign impl 2021-11-09 23:47:36 +01:00
Matthias Krüger
610b4e503c
Rollup merge of #90035 - SparrowLii:rfc2528, r=jackh726
implement rfc-2528 type_changing-struct-update

This PR implement rfc2528-type_changing-struct-update.
The main change process is as follows:
1. Move the processing part of `base_expr` into `check_expr_struct_fields` to avoid returning `remaining_fields` (a relatively complex hash table)
2. Before performing the type consistency check(`check_expr_has_type_or_error`), if the `type_changing_struct_update` feature is set, enter a different processing flow, otherwise keep the original flow
3. In the case of the same structure definition, check each field in `remaining_fields`. If the field in `base_expr` is not the suptype of the field in `adt_ty`, an error(`FeildMisMatch`) will be reported.

The MIR part does not need to be changed, because only the items contained in `remaining_fields` will be extracted from `base_expr` when MIR is generated. This means that fields with different types in `base_expr` will not be used
Updates #86618
cc `@nikomatsakis`
2021-11-09 19:00:41 +01:00
Matthias Krüger
fd74c93403
Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis
Type inference for inline consts

Fixes #78132
Fixes #78174
Fixes #81857
Fixes #89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `````@spastorino````` `````@lcnr`````
r? `````@nikomatsakis`````

`````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-09 19:00:40 +01:00
Joshua Nelson
0ac13bd430 Don't abort compilation after giving a lint error
The only reason to use `abort_if_errors` is when the program is so broken that either:
1. later passes get confused and ICE
2. any diagnostics from later passes would be noise

This is never the case for lints, because the compiler has to be able to deal with `allow`-ed lints.
So it can continue to lint and compile even if there are lint errors.
2021-11-08 01:22:28 +00:00
Matthew Jasper
9734c03524 Remove some fields from ObligationCauseCode 2021-11-07 13:20:02 +00:00
Gary Guo
c4103d438f Rename functions reflect that inline const is also "typeck_child" 2021-11-07 04:00:34 +00:00
Gary Guo
468192a9c5 Implement type inference for inline consts
In most cases it is handled in the same way as closures.
2021-11-07 04:00:32 +00:00
Gary Guo
02c1774cd3 Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
bors
089a016919 Auto merge of #90661 - matthiaskrgr:rollup-1umbdlx, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #90487 (Add a chapter on reading Rustdoc output)
 - #90508 (Apply adjustments for field expression even if inaccessible)
 - #90627 (Suggest dereference of `Box` when inner type is expected)
 - #90642 (use matches!() macro in more places)
 - #90646 (type error go brrrrrrrr)
 - #90649 (Run reveal_all on MIR when inlining is activated.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-06 22:55:37 +00:00
Matthias Krüger
43fee0e0a9
Rollup merge of #90646 - BoxyUwU:funky_ice, r=estebank
type error go brrrrrrrr

Fixes #90444

when we relate something like:
`fn(fn((), (), u32))` with `fn(fn((), (), ()))`
we relate the inner fn ptrs:
`fn((), (), u32)` with `fn((), (), ())`
yielding a `TypeError::ArgumentSorts(_, 2)` which we then use as the `TypeError` for the `fn(fn(..))` which later causes the ICE as the `2` does not correspond to any input or output types in `fn(_)`

r? `@estebank`
2021-11-06 23:12:06 +01:00
bors
0727994435 Auto merge of #90655 - the8472:drain-dot-dot, r=jyn514
Replace some uses of vec.drain(..) with vec.into_iter()

IntoIter should optimize better than Drain
2021-11-06 20:14:37 +00:00
The8472
ff87ff962c Replace some uses of vec.drain(..) with vec.into_iter()
IntoIter should optimize better than Drain
2021-11-06 19:04:31 +01:00
Matthias Krüger
0a5640b55f use matches!() macro in more places 2021-11-06 16:13:14 +01:00
Ellen
abb9a9853b type error go brrrrrrrr 2021-11-06 10:39:11 +00:00
bors
18cae2680f Auto merge of #88441 - jackh726:closure_norm, r=nikomatsakis
Normalize obligations for closure confirmation

Based on #90017

Fixes #74261
Fixes #71955
Fixes #88459

r? `@nikomatsakis`
2021-11-06 01:12:39 +00:00
Josh Stone
767471edeb Update LLVM comments around NoAliasMutRef 2021-11-05 12:22:51 -07:00
Matthias Krüger
28ef4169cc clippy::perf fixes 2021-11-04 21:07:56 +01:00
Camille GILLOT
04f011f1b7 Remove eval_always from upvars. 2021-11-04 20:29:47 +01:00
Camille GILLOT
c4d7bebd95 Remove eval_always for inherent_impls. 2021-11-04 20:29:21 +01:00
Wesley Wiser
60bf2f1926 Add a few query descriptions 2021-10-29 11:15:45 -04:00
bors
88a5a984fe Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr
Revert "Add rustc lint, warning when iterating over hashmaps"

Fixes perf regressions introduced in https://github.com/rust-lang/rust/pull/90235 by temporarily reverting the relevant PR.
2021-10-29 04:55:51 +00:00
Mark Rousskov
3215eeb99f
Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
bors
c4ff03f689 Auto merge of #90145 - cjgillot:sorted-map, r=michaelwoerister
Use SortedMap in HIR.

Closes https://github.com/rust-lang/rust/issues/89788
r? `@ghost`
2021-10-28 13:04:40 +00:00
SparrowLii
7bde18a0f3 implement type-changing-struct-update
put the test dir in test/ui/rfcs
2021-10-28 14:17:15 +08:00
bjorn3
f5c3e83013 Avoid a branch on key being local for queries that use the same local and extern providers 2021-10-25 13:36:23 +02:00
bors
41d8c94d45 Auto merge of #89427 - estebank:collect-overlapping-impls, r=jackh726
Point at overlapping impls when type annotations are needed

Address https://github.com/rust-lang/rust/issues/89254.
2021-10-24 22:26:41 +00:00
Esteban Kuber
ef212e7fb3 Point at overlapping impls when type annotations are needed 2021-10-24 18:33:04 +00:00
Matthias Krüger
87822b27ee
Rollup merge of #89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps

r? rust-lang/wg-incr-comp
2021-10-24 15:48:42 +02:00
bors
aa5740c715 Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakis
Implement coherence checks for negative trait impls

The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3).

This feature is necessary to handle the following from impl on box.

```rust
impl From<&str> for Box<dyn Error> { ... }
```

Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile.

We would have this in `alloc`:

```rust
impl From<&str> for Box<dyn Error> {} // A
impl<E> From<E> for Box<dyn Error> where E: Error {} // B
```

and this in `core`:

```rust
trait Error {}
impl !Error for &str {}
```

r? `@nikomatsakis`

This PR was built on top of `@yaahc` PR #85764.

Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-23 12:51:15 +00:00
bors
55ccbd090d Auto merge of #90065 - cjgillot:novalcache, r=Mark-Simulacrum
Do not depend on the stored value when trying to cache on disk.

Having different criteria for loading and saving of query results can lead to saved results that may never be loaded.
Since the on-disk cache is discarded as soon as a compilation error is issued, there should not be any need for an exclusion mecanism based on errors.

As a result, the possibility to condition the storage on the value itself does not appear useful.
2021-10-23 09:21:45 +00:00
bors
01198792a6 Auto merge of #89893 - camsteffen:redundant-dump-enabled, r=matthewjasper
Remove redundant dump_enabled check
2021-10-22 17:32:20 +00:00
Santiago Pastorino
c4c76a4fbd
Document flip polarity 2021-10-22 09:34:36 -03:00
Camille GILLOT
6f6fa8b954 Use SortedMap in HIR. 2021-10-21 23:08:57 +02:00
Camille GILLOT
0a5666b838 Do not depend on the stored value when trying to cache on disk. 2021-10-21 20:00:45 +02:00
Yuki Okushi
afdd0c3ade
Rollup merge of #90071 - cjgillot:no-blocks, r=oli-obk
Remove hir::map::blocks and use FnKind instead

The principal tool is `FnLikeNode`, which is not often used and can be easily implemented using `rustc_hir::intravisit::FnKind`.
2021-10-21 14:11:08 +09:00
Gary Guo
1b7f5a3818 Remove NullOp::Box 2021-10-20 19:42:35 +01:00
Camille GILLOT
b11ec29e28 Address review. 2021-10-20 18:51:15 +02:00
Camille GILLOT
8785b70774 Inline DepNodeParams methods. 2021-10-20 18:46:25 +02:00
Camille GILLOT
bd5c107672 Build jump table at runtime. 2021-10-20 18:32:29 +02:00
Camille GILLOT
602d3cbce3 Invoke callbacks from rustc_middle. 2021-10-20 18:29:33 +02:00
Camille GILLOT
b09de95fab Merge two query callbacks arrays. 2021-10-20 18:29:27 +02:00
Camille GILLOT
dc7143367c Drop has_params. 2021-10-20 18:29:22 +02:00
Camille GILLOT
e53404cca6 Move def_path_hash_to_def_id to rustc_middle. 2021-10-20 18:28:54 +02:00
Camille GILLOT
88c6d3de95 Avoid trivial lambdas. 2021-10-20 18:24:16 +02:00
Santiago Pastorino
85c8fd9c94
Make EvaluationCache consider polarity as cache's key 2021-10-20 12:10:46 -03:00
Santiago Pastorino
8b0bfb0dcb
Consider negative polarity on overlap check 2021-10-20 12:10:45 -03:00
Santiago Pastorino
6975afd141
Add polarity to TraitPredicate 2021-10-20 12:10:41 -03:00
Camille GILLOT
6e98688e68 Replace FnLikeNode by FnKind. 2021-10-19 23:31:51 +02:00
Camille GILLOT
05eb6f36f1 Cleanup dead code in hir::map::blocks. 2021-10-19 23:10:09 +02:00
bors
1af55d19c7 Auto merge of #89933 - est31:let_else, r=michaelwoerister
Adopt let_else across the compiler

This performs a substitution of code following the pattern:

```
let <id> = if let <pat> = ... { identity } else { ... : ! };
```

To simplify it to:

```
let <pat> = ... { identity } else { ... : ! };
```

By adopting the `let_else` feature (cc #87335).

The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet.

Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-19 14:41:39 +00:00
Matthias Krüger
a0724d72b0
Rollup merge of #89988 - tmiasko:unpromote-const-drop, r=oli-obk
Do not promote values with const drop that need to be dropped

Changes from #88558 allowed using `~const Drop` in constants by
introducing a new `NeedsNonConstDrop` qualif.

The new qualif was also used for promotion purposes, and allowed
promotion to happen for values that needs to be dropped but which
do have a const drop impl.

Since for promoted the drop implementation is never executed,
this lead to observable change in behaviour. For example:

```rust

struct Panic();

impl const Drop for Panic {
    fn drop(&mut self) {
        panic!();
    }
}

fn main() {
    let _ = &Panic();
}
```

Restore the use of `NeedsDrop` qualif during promotion to avoid the issue.
2021-10-19 05:40:54 +02:00
Tomasz Miąsko
915a581bcb Do not promote values with const drop that need to be dropped
Changes from #88558 allowed using `~const Drop` in constants by
introducing a new `NeedsNonConstDrop` qualif.

The new qualif was also used for promotion purposes, and allowed
promotion to happen for values that needs to be dropped but which
do have a const drop impl.

Since for promoted the drop implementation is never executed,
this lead to observable change in behaviour. For example:

```rust

struct Panic();

impl const Drop for Panic {
    fn drop(&mut self) {
        panic!();
    }
}

fn main() {
    let _ = &Panic();
}
```

Restore the use of `NeedsDrop` qualif during promotion to avoid the issue.
2021-10-18 21:56:57 +02:00
bors
bd41e09da3 Auto merge of #89124 - cjgillot:owner-info, r=michaelwoerister
Index and hash HIR as part of lowering

Part of https://github.com/rust-lang/rust/pull/88186
~Based on https://github.com/rust-lang/rust/pull/88880 (see merge commit).~

Once HIR is lowered, it is later indexed by the `index_hir` query and hashed for `crate_hash`. This PR moves those post-processing steps to lowering itself. As a side objective, the HIR crate data structure is refactored as an `IndexVec<LocalDefId, Option<OwnerInfo<'hir>>>` where `OwnerInfo` stores all the relevant information for an HIR owner.

r? `@michaelwoerister`
cc `@petrochenkov`
2021-10-18 19:53:05 +00:00
Tomasz Miąsko
171cbc01ef Rename needs_drop to needs_non_const_drop 2021-10-18 20:51:22 +02:00
jackh726
cacc3ee801 Normalize obligations for closure confirmation 2021-10-18 12:35:42 -04:00
Matthias Krüger
2fd765c1d9
Rollup merge of #89990 - petrochenkov:idempty, r=wesleywiser
rustc_span: `Ident::invalid` -> `Ident::empty`

The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s as well.
2021-10-18 08:13:30 +02:00
Vadim Petrochenkov
a6808335d4 rustc_span: Ident::invalid -> Ident::empty
The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s.
2021-10-17 23:20:30 +03:00
Matthias Krüger
0f1ba8d8c7
Rollup merge of #89946 - JohnTitor:fix-89686, r=petrochenkov
Fix an ICE with TAITs and Future

Fixes #89686
2021-10-17 18:18:58 +02:00
Matthias Krüger
59dc2187ad
Rollup merge of #89738 - eddyb:extern-crate-recursion, r=nagisa
ty::pretty: prevent infinite recursion for `extern crate` paths.

Fixes #55779, fixes #87932.

This fix is based on `@estebank's` idea in https://github.com/rust-lang/rust/issues/55779#issuecomment-614758510 - but instead of trying to get `try_print_visible_def_path_recur`'s cycle detection to work in this case, this PR "just" disables the "visible path" feature when printing the path to an `extern crate`, so that the old recursion chain of `try_print_visible_def_path -> print_def_path -> try_print_visible_def_path`, is now impossible.

Both tests have been confirmed to crash `rustc` because of a stack overflow, without the fix.
2021-10-17 18:18:55 +02:00
bors
6f53ddfa74 Auto merge of #89514 - davidtwco:polymorphize-shims-and-predicates, r=lcnr
polymorphization: shims and predicates

Supersedes #75737 and #75414. This pull request includes up some changes to polymorphization which hadn't landed previously and gets stage2 bootstrapping and the test suite passing when polymorphization is enabled. There are still issues with `type_id` and polymorphization to investigate but this should get polymorphization in a reasonable state to work on.

- #75737 and #75414 both worked but were blocked on having the rest of the test suite pass (with polymorphization enabled) with and without the PRs. It makes more sense to just land these so that the changes are in.
- #75737's changes remove the restriction of `InstanceDef::Item` on polymorphization, so that shims can now be polymorphized. This won't have much of an effect until polymorphization's analysis is more advanced, but it doesn't hurt.
- #75414's changes remove all logic which marks parameters as used based on their presence in predicates - given #75675, this will enable more polymorphization and avoid the symbol clashes that predicate logic previously sidestepped.
- Polymorphization now explicitly checks (and skips) foreign items, this is necessary for stage2 bootstrapping to work when polymorphization is enabled.
- The conditional determining the emission of a note adding context to a post-monomorphization error has been modified. Polymorphization results in `optimized_mir` running for shims during collection where that wouldn't happen previously, some errors are emitted during `optimized_mir` and these were considered post-monomorphization errors with the existing logic (more errors and shims have a `DefId` coming from the std crate, not the local crate), adding a note that resulted in tests failing. It isn't particularly feasible to change where polymorphization runs or prevent it from using `optimized_mir`, so it seemed more reasonable to not change the conditional.
- `characteristic_def_id_of_type` was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function - this caused a ICE in a debuginfo test. If partitioning is enabled and the instance needs substitution then this is skipped. That test still fails for me locally, but not with an ICE, but it fails in a fresh checkout too, so 🤷‍♂️.

r? `@lcnr`
2021-10-17 12:33:12 +00:00
Yuki Okushi
b8173c59c6
Rollup merge of #89943 - matthiaskrgr:clpcompl, r=oli-obk
clippy::complexity fixes
2021-10-17 07:52:20 +09:00
Matthias Krüger
c645d3f3b9 clippy::complexity changes 2021-10-16 18:11:16 +02:00
Yuki Okushi
f001e8c519
Fix an ICE with TAITs and Future 2021-10-16 18:30:37 +09:00