Commit graph

9722 commits

Author SHA1 Message Date
Jakub Beránek ac08f13948
Remove sort from hashing hashset, treeset and treemap 2021-12-13 16:11:28 +01:00
Jakub Beránek 6e33d3ecc2
Use modular arithmetic 2021-12-12 23:48:11 +01:00
Jakub Beránek a5f5f6b689
Avoid sorting in hash map stable hashing 2021-12-12 20:57:24 +01:00
bors 58457bbfd3 Auto merge of #89404 - Kobzol:hash-stable-sort, r=Mark-Simulacrum
Slightly optimize hash map stable hashing

I was profiling some of the `rustc-perf` benchmarks locally and noticed that quite some time is spent inside the stable hash of hashmaps. I tried to use a `SmallVec` instead of a `Vec` there, which helped very slightly.

Then I tried to remove the sorting, which was a bottleneck, and replaced it with insertion into a binary heap. Locally, it yielded nice improvements in instruction counts and RSS in several benchmarks for incremental builds. The implementation could probably be much nicer and possibly extended to other stable hashes, but first I wanted to test the perf impact properly.

Can I ask someone to do a perf run? Thank you!
2021-12-12 03:50:30 +00:00
bors e70e4d499d Auto merge of #91813 - matthiaskrgr:rollup-nryyeyj, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #90081 (Make `intrinsics::write_bytes` const)
 - #91643 (asm: Allow using r9 (ARM) and x18 (AArch64) if they are not reserved by the current target)
 - #91737 (Make certain panicky stdlib functions behave better under panic_immediate_abort)
 - #91750 (rustdoc: Add regression test for Iterator as notable trait on &T)
 - #91764 (Do not ICE when suggesting elided lifetimes on non-existent spans.)
 - #91780 (Remove hir::Node::hir_id.)
 - #91797 (Fix zero-sized reference to deallocated memory)
 - #91806 (Make `Unique`s methods `const`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-12 00:58:30 +00:00
Matthias Krüger bd46953f0b
Rollup merge of #91780 - cjgillot:localize, r=Mark-Simulacrum
Remove hir::Node::hir_id.

Small cleanup.
2021-12-11 23:31:53 +01:00
Matthias Krüger 72b6a91fe7
Rollup merge of #91764 - cjgillot:elide-anyway, r=jackh726
Do not ICE when suggesting elided lifetimes on non-existent spans.

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

r? `@jackh726`
2021-12-11 23:31:52 +01:00
Matthias Krüger 443ed7c620
Rollup merge of #91643 - Amanieu:r9x18, r=joshtriplett
asm: Allow using r9 (ARM) and x18 (AArch64) if they are not reserved by the current target

This supersedes https://github.com/rust-lang/rust/pull/88879.

cc `@Skirmisher`

r? `@joshtriplett`
2021-12-11 23:31:49 +01:00
Matthias Krüger 9383a49cd4
Rollup merge of #90081 - woppopo:const_write_bytes, r=oli-obk
Make `intrinsics::write_bytes` const

This is required to constify `MaybeUninit::zeroed` and `(*mut T)::write_bytes`.

Tracking issue: #86302
2021-12-11 23:31:48 +01: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 bc0269dbed
Rollup merge of #91718 - RalfJung:unaligned_references, r=nagisa
give more help in the unaligned_references lint

Cc https://github.com/rust-lang/rust/issues/82523#issuecomment-988138440 ``@kaisq``
2021-12-11 16:02:49 +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
Camille GILLOT 9a68003742 Do not ICE when suggesting elided lifetimes on non-existent spans. 2021-12-11 11:08:46 +01:00
Camille GILLOT d9e997d9eb Remove useless variant. 2021-12-11 11:08:46 +01:00
Matthias Krüger 7e18b79c77
Rollup merge of #91426 - eggyal:idfunctor-panic-safety, r=lcnr
Make IdFunctor::try_map_id panic-safe

Addresses FIXME comment created in #78313

r? ```@lcnr```
2021-12-11 08:22:32 +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
bors 82575a1d6f Auto merge of #91715 - the8472:bump-rmeta-fromat-version, r=Mark-Simulacrum
Bump rmeta version to fix rustc_serialize ICE

#91407 changed the serialization format which leads to ICEs for nightly users such as #91663 and linked issues. The issue can be solved by running `cargo clean`. But bumping the metadata version should lead to the cached files being discarded, avoiding the issue entirely.
2021-12-11 01:00:14 +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
Matthias Krüger 40988591ec
Rollup merge of #91625 - est31:remove_indexes, r=oli-obk
Remove redundant [..]s
2021-12-10 22:40:36 +01:00
Matthias Krüger 6cfe9af6a0
Rollup merge of #91575 - compiler-errors:issue-91556, r=cjgillot
Fix ICE on format string of macro with secondary-label

This generalizes the fix #86104 to also correctly skip `Span::from_inner` for the `secondary_label` of a format macro parsing error as well.

We can alternatively skip the `span_label` diagnostic call for the secondary label as well, since that label probably only makes sense when the _proper_ span is computed.

Fixes #91556
2021-12-10 22:40:35 +01:00
Matthias Krüger b7b4d7742e
Rollup merge of #91470 - wesleywiser:code_coverage_link_error, r=tmandry
code-cov: generate dead functions with private/default linkage

As discovered in #85461, the MSVC linker treats weak symbols slightly
differently than unix-y linkers do. This causes link.exe to fail with
LNK1227 "conflicting weak extern definition" where as other targets are
able to link successfully.

This changes the dead functions from being generated as weak/hidden to
private/default which, as the LLVM reference says:

> Global values with “private” linkage are only directly accessible by
objects in the current module. In particular, linking code into a module
with a private global value may cause the private to be renamed as
necessary to avoid collisions. Because the symbol is private to the
module, all references can be updated. This doesn’t show up in any
symbol table in the object file.

This fixes the conflicting weak symbols but doesn't address the reason
*why* we have conflicting symbols for these dead functions. The test
cases added in this commit contain a minimal repro of the fundamental
issue which is that the logic used to decide what dead code functions
should be codegen'd in the current CGU doesn't take into account that
functions can be duplicated across multiple CGUs (for instance, in the
case of `#[inline(always)]` functions).

Fixing that is likely to be a more complex change (see
https://github.com/rust-lang/rust/issues/85461#issuecomment-985005805).

Fixes #85461
2021-12-10 22:40:32 +01:00
Matthias Krüger 71c1d562ce
Rollup merge of #90407 - pierwill:edit-rustc-incremental-docs, r=cjgillot
Document all public items in `rustc_incremental`

Also:

- Review and edit current docs
- Enforce documentation for the module.
2021-12-10 22:40:28 +01:00
Camille GILLOT 67ada7abef Remove hir::Node::hir_id. 2021-12-10 18:51:19 +01:00
Esteban Kuber d2d9eb3715 fmt 2021-12-10 17:22:33 +00:00
Esteban Kuber da5b0cc851 review comment 2021-12-10 03:18:03 +00:00
Esteban Kuber d33fa135fe Remove field from ErrorValue 2021-12-10 03:08:25 +00:00
Esteban Kuber 9cc7bd7692 Review comments 2021-12-10 03:08:25 +00:00
Esteban Kuber 83ce1aad42 Tweak wording 2021-12-10 03:08:25 +00:00
Esteban Kuber 10a74ac2e0 Use a more accurate Span for 'static obligation from return type 2021-12-10 03:08:24 +00:00
Esteban Kuber ee0fd105d8 Point at return type when it introduces 'static obligation 2021-12-10 03:08:23 +00:00
Esteban Kuber 09dbf37213 Add filtering based on involved required lifetime
More accurate filtering still needed.
2021-12-10 03:08:23 +00:00
Esteban Kuber ab45ab83ac review comments
* take diagnostic logic out of happy-path
* sort/dedup once
* add more comments
2021-12-10 03:08:22 +00:00
Esteban Kuber dd81e98466 Clean up visual output logic 2021-12-10 03:08:22 +00:00
Esteban Kuber d10fe26f39 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-10 03:08:22 +00:00
Amanieu d'Antras 8716f2780e asm: Allow using r9 (ARM) and x18 (AArch64) if they are not reserved by
the current target.
2021-12-10 00:51:39 +00:00
Ralf Jung 7d18a456ca give more help in the unaligned_references lint 2021-12-09 16:48:51 -05:00
Michael Goulet 99bd24e9a3 Fix span calculation on secondary_label as well 2021-12-09 09:09:39 -08:00
The 8472 0696e79f27 Bump rmeta version to fix rustc_serialize ICE
#91407 changed the serialization format which leads to ICEs for nightly users such as #91663 and linked issue.
Bumping the metadata version should lead to the cached files being discarded instead.
2021-12-09 18:00:36 +01:00
bors 600820da45 Auto merge of #91692 - matthiaskrgr:rollup-u7dvh0n, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #87599 (Implement concat_bytes!)
 - #89999 (Update std::env::temp_dir to use GetTempPath2 on Windows when available.)
 - #90796 (Remove the reg_thumb register class for asm! on ARM)
 - #91042 (Use Vec extend instead of repeated pushes on several places)
 - #91634 (Do not attempt to suggest help for overly malformed struct/function call)
 - #91685 (Install llvm tools to sysroot when assembling local toolchain)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-09 07:08:32 +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
Matthias Krüger 8c94b2c375
Rollup merge of #91634 - terrarier2111:fix-recover-from-variant-ice, r=nagisa
Do not attempt to suggest help for overly malformed struct/function call

This fixes: https://github.com/rust-lang/rust/issues/91461
2021-12-09 05:08:33 +01:00
Matthias Krüger 876f9ffde6
Rollup merge of #91042 - Kobzol:vec-extend-cleanup, r=nagisa
Use Vec extend instead of repeated pushes on several places

Inspired by https://github.com/rust-lang/rust/pull/90813, I tried to use a simple regex (`for .*in.*\{\n.*push\(.*\);\n\s+}`) to search for more places that would use `Vec::push` in a loop and replace them with `Vec::extend`.

These probably won't have as much perf. impact as the original PR (if any), but it would probably be better to do a perf run to see if there are not any regressions.
2021-12-09 05:08:33 +01:00
Matthias Krüger 22a1331112
Rollup merge of #90796 - Amanieu:remove_reg_thumb, r=joshtriplett
Remove the reg_thumb register class for asm! on ARM

Also restricts r8-r14 from being used on Thumb1 targets as per #90736.

cc ``@Lokathor``

r? ``@joshtriplett``
2021-12-09 05:08:32 +01:00
Matthias Krüger 3fc5bd7abc
Rollup merge of #87599 - Smittyvb:concat_bytes, r=Mark-Simulacrum
Implement concat_bytes!

This implements the unstable `concat_bytes!` macro, which has tracking issue #87555. It can be used like:
```rust
#![feature(concat_bytes)]

fn main() {
    assert_eq!(concat_bytes!(), &[]);
    assert_eq!(concat_bytes!(b'A', b"BC", [68, b'E', 70]), b"ABCDEF");
}
```
If strings or characters are used where byte strings or byte characters are required, it suggests adding a `b` prefix. If a number is used outside of an array it suggests arrayifying it. If a boolean is used it suggests replacing it with the numeric value of that number. Doubly nested arrays of bytes are disallowed.
2021-12-09 05:08:30 +01:00
bors e250777041 Auto merge of #91691 - matthiaskrgr:rollup-wfommdr, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #91042 (Use Vec extend instead of repeated pushes on several places)
 - #91476 (Improve 'cannot contain emoji' error.)
 - #91568 (Pretty print break and continue without redundant space)
 - #91645 (Implement `core::future::join!`)
 - #91666 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-09 04:04:01 +00:00
Matthias Krüger f82049618d
Rollup merge of #91568 - dtolnay:breakspace, r=nagisa
Pretty print break and continue without redundant space

**Repro:**

```rust
macro_rules! m {
    ($e:expr) => { stringify!($e) };
}
fn main() {
    println!("{:?}", m!(loop { break; }));
    println!("{:?}", m!(loop { break 'a; }));
    println!("{:?}", m!(loop { break false; }));
}
```

**Before:**

- `"loop { break ; }"`
- `"loop { break 'a ; }"`
- `"loop { break false ; }"`

**After:**

- `"loop { break; }"`
- `"loop { break 'a; }"`
- `"loop { break false; }"`

<br>

Notice that `return` and `yield` already follow the same approach as this PR of printing the space *before* each additional piece following the keyword, rather than *after* each thing.

772d51f887/compiler/rustc_ast_pretty/src/pprust/state.rs (L2148-L2154)

772d51f887/compiler/rustc_ast_pretty/src/pprust/state.rs (L2221-L2228)
2021-12-09 05:02:21 +01:00