Commit graph

156137 commits

Author SHA1 Message Date
Matthias Krüger
36db658796
Rollup merge of #88707 - sylvestre:split_example, r=yaahc
String.split_terminator: Add an example when using a slice of chars
2021-10-09 11:55:58 +02:00
Tim McNamara
020ec0a039
Remove unnecessary hyphen
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-10-09 21:44:07 +13:00
Alessandro Decina
8683d36042 Fix min LLVM version for bpf-types test
Closes #89689
2021-10-09 19:18:37 +11:00
Tim McNamara
fa5a212896
Simplify wording
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-10-09 20:51:36 +13:00
Jacob Hoffman-Andrews
586a9cea75 Move template initialization into its own file. 2021-10-08 23:28:42 -07:00
John Kugelman
2ec7588aa1
Update library/core/src/num/mod.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-10-09 02:05:03 -04:00
Jacob Hoffman-Andrews
7a938005e1 Add template for print_item
Add print_item.html and the code in print_item.rs to use it.
2021-10-08 23:02:12 -07:00
Gary Guo
7275cfa47c Explicit PlaceAncestryRelation::SamePlace and handle like Descendant 2021-10-09 06:49:47 +01:00
bors
910692de74 Auto merge of #89582 - jkugelman:optimize-file-read-to-end, r=joshtriplett
Optimize File::read_to_end and read_to_string

Reading a file into an empty vector or string buffer can incur unnecessary `read` syscalls and memory re-allocations as the buffer "warms up" and grows to its final size. This is perhaps a necessary evil with generic readers, but files can be read in smarter by checking the file size and reserving that much capacity.

`std::fs::read` and `std::fs::read_to_string` already perform this optimization: they open the file, reads its metadata, and call `with_capacity` with the file size. This ensures that the buffer does not need to be resized and an initial string of small `read` syscalls.

However, if a user opens the `File` themselves and calls `file.read_to_end` or `file.read_to_string` they do not get this optimization.

```rust
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
```

I searched through this project's codebase and even here are a *lot* of examples of this. They're found all over in unit tests, which isn't a big deal, but there are also several real instances in the compiler and in Cargo. I've documented the ones I found in a comment here:

https://github.com/rust-lang/rust/issues/89516#issuecomment-934423999

Most telling, the documentation for both the `Read` trait and the `Read::read_to_end` method both show this exact pattern as examples of how to use readers. What this says to me is that this shouldn't be solved by simply fixing the instances of it in this codebase. If it's here it's certain to be prevalent in the wider Rust ecosystem.

To that end, this commit adds specializations of `read_to_end` and `read_to_string` directly on `File`. This way it's no longer a minor footgun to start with an empty buffer when reading a file in.

A nice side effect of this change is that code that accesses a `File` as `impl Read` or `dyn Read` will benefit. For example, this code from `compiler/rustc_serialize/src/json.rs`:

```rust
pub fn from_reader(rdr: &mut dyn Read) -> Result<Json, BuilderError> {
    let mut contents = Vec::new();
    match rdr.read_to_end(&mut contents) {
```

Related changes:

- I also added specializations to `BufReader` to delegate to `self.inner`'s methods. That way it can call `File`'s optimized  implementations if the inner reader is a file.

- The private `std::io::append_to_string` function is now marked `unsafe`.

- `File::read_to_string` being more efficient means that the performance note for `io::read_to_string` can be softened. I've added `@camelid's` suggested wording from https://github.com/rust-lang/rust/issues/80218#issuecomment-936806502.

r? `@joshtriplett`
2021-10-09 05:24:47 +00:00
John Kugelman
54d807cfc7 Add #[must_use] to string/char transformation methods
These methods could be misconstrued as modifying their arguments instead
of returning new values.

Where possible I made the note recommend a method that does mutate in
place.
2021-10-09 01:01:40 -04:00
John Kugelman
e27bfb6e23 Add #[must_use] to stdin/stdout/stderr locks 2021-10-08 23:31:57 -04:00
Nicholas-Baron
8a4085d370 Move read2_abbreviated function into read2.rs 2021-10-08 15:12:21 -07:00
Devin Ragotzy
14338786fd Add feature gate to non_exhaustive_omitted_patterns lint
Actually add the feature to the lints ui test
Add tracking issue to the feature declaration
Rename feature gate to non_exhaustive_omitted_patterns_lint
Add more omitted_patterns lint feature gate
2021-10-08 17:40:39 -04:00
bors
f8751436ff Auto merge of #89683 - GuillaumeGomez:rollup-q2mjd9m, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #86506 (Don't normalize xform_ret_ty during method candidate assembly )
 - #89538 (Make rustdoc not highlight `->` and `=>` as operators)
 - #89649 (clippy::complexity fixes)
 - #89668 (Cfg hide more conditions for core and alloc)
 - #89669 (Remove special-casing of never primitive in rustdoc-json-types)
 - #89672 (Remove unwrap_or! macro)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-08 21:13:27 +00:00
asquared31415
4a565e5110 Fix asm docs typo 2021-10-08 16:50:35 -04:00
Guillaume Gomez
cda07c740c
Rollup merge of #89672 - klensy:unwrap-or-macro, r=jackh726
Remove unwrap_or! macro

Removes `unwrap_or!` macro and replaces it with `match`.

It's kinda cleanup, as rustc_ast not the best place for this macro and this is used only in 2 places anyway.
2021-10-08 22:30:43 +02:00
Guillaume Gomez
4adc8ea2ac
Rollup merge of #89669 - Urgau:json-remove-type-never, r=GuillaumeGomez
Remove special-casing of never primitive in rustdoc-json-types

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

r? `@GuillaumeGomez`
2021-10-08 22:30:42 +02:00
Guillaume Gomez
1c35968773
Rollup merge of #89668 - Urgau:core-cfg-hide, r=GuillaumeGomez
Cfg hide more conditions for core and alloc

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

Before:
![image](https://user-images.githubusercontent.com/3616612/136572816-a7844ac7-dc2f-4d79-87b4-7f9766421a83.png)

After:
![image](https://user-images.githubusercontent.com/3616612/136572745-7d890726-8efd-4d74-83ac-ed06f4687741.png)

*Same for alloc*

r? ``@GuillaumeGomez``
2021-10-08 22:30:41 +02:00
Guillaume Gomez
836597a881
Rollup merge of #89649 - matthiaskrgr:clippycompl, r=jyn514
clippy::complexity fixes
2021-10-08 22:30:40 +02:00
Guillaume Gomez
0cc123cbb3
Rollup merge of #89538 - notriddle:notriddle/arrow-highlight, r=GuillaumeGomez
Make rustdoc not highlight `->` and `=>` as operators

It was marking them up as `<span class="op">=</span><span class="op">&gt;</span>`,
which is bloaty and wrong (at least, I think `<=` and `=>` should probably be different colors, since they're so different and yet made from the same symbols).

Before:

![image](https://user-images.githubusercontent.com/1593513/135939748-f49b0f9e-6a7d-4d65-935a-e31cdf688a81.png)

After:

![image](https://user-images.githubusercontent.com/1593513/135940063-5ef1f6b1-7e03-4227-b46b-572b063aba05.png)
2021-10-08 22:30:39 +02:00
Guillaume Gomez
32502404e5
Rollup merge of #86506 - b-naber:gen_trait_impl_inconsistent, r=jackh726
Don't normalize xform_ret_ty during method candidate assembly

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

Normalizing the return type of a method candidate together with the expected receiver type of the method can lead to valid method candidates being rejected during probing. Specifically in the example of the fixed issue we have a `self_ty` of the form `&A<&[Coef]>` whereas the `impl_ty` of the method would be `&A<_>`, if we normalize the projection in the return type we unify the inference variable with `Cont`, which will lead us to reject the candidate in the sup type check in `consider_probe`. Since we don't actually need the normalized return type during candidate assembly, we postpone the normalization until we consider candidates in `consider_probe`.
2021-10-08 22:30:38 +02:00
Marcelo Diop-Gonzalez
82c974dab5 Fix minor std::thread documentation typo
callers of spawn_unchecked() need to make sure that the thread
not outlive references in the passed closure, not the other way around.
2021-10-08 15:29:04 -04:00
bors
54bb4fec68 Auto merge of #89666 - rusticstuff:disable_new_llvm_pass_manager_on_s390x_take_two, r=nagisa
Default to disabling the new pass manager for the s390x arch targets.

This hack disables the new LLVM pass manager by default for s390x arch targets until the performance issues are fixed (see #89609). The command line option `-Z new-llvm-pass-manager=(yes|no)` continues to take precedence over this default.
2021-10-08 18:12:50 +00:00
Matthias Krüger
e6f77a1787 clippy::complexity fixes 2021-10-08 20:07:44 +02:00
Eliza Weisman
84fc5db59b
bless warnings
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-08 10:56:08 -07:00
Oli Scherer
49b06a2b60 Directly call relate_types function instead of having a method wrapper 2021-10-08 17:53:41 +00:00
Oli Scherer
597090ee14 Re-use TypeChecker instead of passing around some of its fields 2021-10-08 17:51:56 +00:00
klensy
77fce75ba1 remove unwrap_or! macro 2021-10-08 19:32:16 +03:00
Loïc BRANSTETT
0a03ec4724 Cfg hide more conditions for alloc 2021-10-08 17:11:57 +02:00
rhysd
7b9ddbdcf2 Show detailed expected/found types in error message when trait paths are the same 2021-10-09 00:07:37 +09:00
Loïc BRANSTETT
4891aaf2e9 Remove special-casing of never primitive in rustdoc-json-types 2021-10-08 16:53:39 +02:00
bors
87df4dd70f Auto merge of #89644 - matthiaskrgr:clippy_perf_okt, r=jyn514
some clippy::perf fixes
2021-10-08 14:35:00 +00:00
Loïc BRANSTETT
31b2eb16e3 Cfg hide more conditions for core 2021-10-08 16:13:49 +02:00
Hans Kratz
4593d78e96 Default to disabling the new pass manager for the s390x targets. 2021-10-08 15:05:07 +02:00
bors
e0aaffd8a4 Auto merge of #89576 - tom7980:issue-89275-fix, r=estebank
Prevent error reporting from outputting a recursion error if it finds an ambiguous trait impl during suggestions

Closes #89275

This fixes the compiler reporting a recursion error during another already in progress error by trying to make a conversion method suggestion and encounters ambiguous trait implementations that can convert a the original type into a type that can then be recursively converted into itself via another method in the trait.

Updated OverflowError struct to be an enum so I could differentiate between passes - it's no longer a ZST but I don't think that should be a problem as they only generate when there's an error in compiling code anyway
2021-10-08 11:44:45 +00:00
Caio
85c4a52807 Also cfg flag auxiliar function 2021-10-08 06:40:24 -03:00
bors
44995f7afb Auto merge of #89619 - michaelwoerister:incr-vtables, r=nagisa
Turn vtable_allocation() into a query

This PR removes the untracked vtable-const-allocation cache from the `tcx` and turns the `vtable_allocation()` method into a query.

The change is pretty straightforward and should be backportable without too much effort.

Fixes https://github.com/rust-lang/rust/issues/89598.
2021-10-08 09:04:06 +00:00
b-naber
3215403dde tests 2021-10-08 10:55:48 +02:00
b-naber
cbf91532a7 dont normalize return type during candidate assembly in method probing 2021-10-08 10:55:44 +02:00
Tim McNamara
6a52fb7303 Add documentation to boxed conversions
Among other changes, documents whether allocations are necessary
to complete the type conversion.

Part of #51430

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>

Co-authored-by: Joshua Nelson <github@jyn.dev>
2021-10-08 21:40:25 +13:00
Michael Woerister
61c5a6d644 Create more accurate debuginfo for vtables.
Before this commit all vtables would have the same name "vtable" in
debuginfo. Now they get a name that identifies the implementing type
and the trait that is being implemented.
2021-10-08 10:33:47 +02:00
Hans Kratz
7b5f1b5028 CI: Use mirror for downloads.
Crosstool-ng 1.22 used by those docker dist builds only allows one
mirror for all downloads.
2021-10-08 08:44:40 +02:00
bors
3013b26947 Auto merge of #89659 - workingjubilee:rollup-0vggc69, r=workingjubilee
Rollup of 8 pull requests

Successful merges:

 - #87918 (Enable AutoFDO.)
 - #88137 (On macOS, make strip="symbols" not pass any options to strip)
 - #88772 (Fixed confusing wording on Result::map_or_else.)
 - #89025 (Implement `#[link_ordinal(n)]`)
 - #89082 (Implement #85440 (Random test ordering))
 - #89288 (Wrapper for `-Z gcc-ld=lld` to invoke rust-lld with the correct flavor)
 - #89476 (Correct decoding of foreign expansions during incr. comp.)
 - #89622 (Use correct edition for panic in [debug_]assert!().)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-08 06:16:31 +00:00
Jubilee
30e068f58b
Rollup merge of #89622 - m-ou-se:debug-assert-2021, r=estebank
Use correct edition for panic in [debug_]assert!().

See https://github.com/rust-lang/rust/issues/88638#issuecomment-915472783
2021-10-07 20:26:15 -07:00
Jubilee
aed1801841
Rollup merge of #89476 - cjgillot:expn-id, r=petrochenkov
Correct decoding of foreign expansions during incr. comp.

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

The original issue was due to a wrong assertion in `expn_hash_to_expn_id`.

The secondary issue was due to a mismatch between the encoding and decoding paths for expansions that are created after the TyCtxt is created.
2021-10-07 20:26:14 -07:00
Jubilee
1c1c6eda94
Rollup merge of #89288 - rusticstuff:lld_wrapper, r=Mark-Simulacrum
Wrapper for `-Z gcc-ld=lld` to invoke rust-lld with the correct flavor

This PR adds an `lld-wrapper` tool which is installed as `ld` and `ld64` in `lib\rustlib\<host_target>\bin\gcc-ld` directory and whose sole purpose is to invoke `rust-lld` in the parent directory with the correct flavor. Lld decides which flavor to use from either the first two commandline arguments or from the name of the executable (`ld` for GNU/ld flavor, `ld64` for Darwin/Macos/ld64 flavor and so on). Symbolic links could not be used as they are not supported by rustup and on Windows.

The wrapper replaces full copies of rust-lld which added some significant bloat. On UNIXish operating systems it exec rust-lld, on Windows it spawns it as a child process.

Fixes #88869.

r? ```@Mark-Simulacrum```
cc ```@nagisa``` ```@petrochenkov``` ```@1000teslas```
2021-10-07 20:26:13 -07:00
Jubilee
37f17bca7c
Rollup merge of #89082 - smoelius:master, r=kennytm
Implement #85440 (Random test ordering)

This PR adds `--shuffle` and `--shuffle-seed` options to `libtest`. The options are similar to the [`-shuffle` option](c894b442d1/src/testing/testing.go (L1482-L1499)) that was recently added to Go.

Here are the relevant parts of the help message:
```
        --shuffle       Run tests in random order
        --shuffle-seed SEED
                        Run tests in random order; seed the random number
                        generator with SEED
...
By default, the tests are run in alphabetical order. Use --shuffle or set
RUST_TEST_SHUFFLE to run the tests in random order. Pass the generated
"shuffle seed" to --shuffle-seed (or set RUST_TEST_SHUFFLE_SEED) to run the
tests in the same order again. Note that --shuffle and --shuffle-seed do not
affect whether the tests are run in parallel.
```
Is an RFC needed for this?
2021-10-07 20:26:12 -07:00
Jubilee
6c17601a2e
Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoerister
Implement `#[link_ordinal(n)]`

Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name.  As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL.

Part of #58713.
2021-10-07 20:26:11 -07:00
Jubilee
2b6d7f75f7
Rollup merge of #88772 - orlp:result-map-or-else-docfix, r=yaahc
Fixed confusing wording on Result::map_or_else.

Fixes https://github.com/rust-lang/rust/issues/88195.
2021-10-07 20:26:11 -07:00
Jubilee
cbb561fdab
Rollup merge of #88137 - joshtriplett:osx-strip-symbols-no-option, r=michaelwoerister
On macOS, make strip="symbols" not pass any options to strip

This makes the output with `strip="symbols"` match the result of just
calling `strip` on the output binary, minimizing the size of the binary.
2021-10-07 20:26:10 -07:00