Yuki Okushi [Tue, 10 Aug 2021 19:18:34 +0000 (04:18 +0900)]
Rollup merge of #87636 - Kixiron:unzip-option, r=scottmcm
Added the `Option::unzip()` method
* Adds the `Option::unzip()` method to turn an `Option<(T, U)>` into `(Option<T>, Option<U>)` under the `unzip_option` feature
* Adds tests for both `Option::unzip()` and `Option::zip()`, I noticed that `.zip()` didn't have any
* Adds `#[inline]` to a few of `Option`'s methods that were missing it
bors [Mon, 9 Aug 2021 08:19:19 +0000 (08:19 +0000)]
Auto merge of #87820 - elichai:patch-2, r=kennytm
Replace read_to_string with read_line in Stdin example
The current example results in infinitely reading from stdin, which can confuse newcomers trying to read from stdin.
(`@razmag` encountered this while learning the language from the docs)
unknown [Sun, 16 May 2021 03:28:16 +0000 (13:28 +1000)]
Add the aarch64-unknown-uefi target
* This commit adds the aarch64-unknown-uefi target and also adds it into
the supported targets list under the tier-3 target table.
* Uses the small code model by default
bors [Mon, 9 Aug 2021 01:08:52 +0000 (01:08 +0000)]
Auto merge of #87465 - audunhalland:refactor_typeck_primary_body_of, r=eddyb
Simplify typeck/primary_body_of, fix comment to match return signature
Hi, new contributor here! I'm carefully reading through the various modules just to learn. I noticed this function, `primary_body_of`, which has gone through a couple of refactors over time, adding new `Option`s to its returned tuple. Observations:
1. the `fn`'s documentation was not all up to date with the the current return signature.
2. `FnHeader` and `FnDecl` are always both `Some` or `None`. So I figured it might just return a reference to the full `hir::FnSig`, for simplicity and more precise typing. It's a pure refactor.
I'm learning better by working with code than just reading it, so here goes! If you want to avoid pure refactor PRs that don't really fix anything, I can revert the code change to only update the comment instead.
bors [Sun, 8 Aug 2021 13:11:09 +0000 (13:11 +0000)]
Auto merge of #87827 - eddyb:wrapperless-mem-replace, r=m-ou-se
Avoid using the `copy_nonoverlapping` wrapper through `mem::replace`.
This is a much simpler way to achieve the pre-#86003 behavior of `mem::replace` not needing dynamically-sized `memcpy`s (at least before inlining), than re-doing #81238 (which needs #86699 or something similar).
I didn't notice it until recently, but `ptr::write` already explicitly avoided using the wrapper, while `ptr::read` just called the wrapper (and was the reason for us observing any behavior change from #86003 in Rust-GPU).
<hr/>
The codegen test I've added fails without the change to `core::ptr::read` like this (ignore the `v0` mangling, I was using a worktree with it turned on by default, for this):
```llvm
13: ; core::intrinsics::copy_nonoverlapping::<u8>
14: ; Function Attrs: inlinehint nonlazybind uwtable
15: define internal void `@_RINvNtCscK5tvALCJol_4core10intrinsics19copy_nonoverlappinghECsaS4X3EinRE8_25mem_replace_direct_memcpy(i8*` %src, i8* %dst, i64 %count) unnamed_addr #0 {
16: start:
17: %0 = mul i64 %count, 1
18: call void `@llvm.memcpy.p0i8.p0i8.i64(i8*` align 1 %dst, i8* align 1 %src, i64 %0, i1 false)
not:17 !~~~~~~~~~~~~~~~~~~~~~ error: no match expected
19: ret void
20: }
```
With the `core::ptr::read` change, `core::intrinsics::copy_nonoverlapping` doesn't get instantiated and the test passes.
bors [Sun, 8 Aug 2021 10:23:17 +0000 (10:23 +0000)]
Auto merge of #87836 - tsoutsman:master, r=petrochenkov
Change proc_macro::Diagnostics docs
With Rust 1.54 attributes can invoke function-like macros. This allows functions generated by macros to have non-generic documentation. This pull request changes the documentation of `proc_macro::Diagnostics` to be more specific and include a link to the level.
## Example
Before:
```markdown
Adds a new child diagnostic message to `self` with the level
identified by this method’s name with the given `message`.
```
After:
```markdown
Adds a new child diagnostic message to self with the [`Level::Error`]
level, and the given `message`.
```
bors [Sun, 8 Aug 2021 07:15:48 +0000 (07:15 +0000)]
Auto merge of #87815 - BoxyUwU:cec-generics-of-ice, r=eddyb
encode `generics_of` for fields and ty params
Fixes #87674
Fixes #87603
ICE was caused by calling `generics_of` on a `DefId` without any `generics_of` results. This was happening when we call `generics_of` on parent `DefId`s of an unevaluated const when we evaluate it.
bors [Sun, 8 Aug 2021 01:52:32 +0000 (01:52 +0000)]
Auto merge of #86744 - ijackson:sink-default, r=dtolnay
impl Default, Copy, Clone for std::io::Sink and Empty
The omission of `Sink: Default` is causing me a slight inconvenience in a test harness. There seems little reason for this and `Empty` not to be `Clone` and `Copy` too.
I have made all three of these insta-stable, because:
AIUI `Copy` can only be derived, and I was not able to find any examples of how to unstably derive it. I think it is probably not possible.
I hunted through the git history for precedent and found
bors [Sat, 7 Aug 2021 23:24:15 +0000 (23:24 +0000)]
Auto merge of #87772 - npmccallum:naked_abi, r=Amanieu
Move naked function ABI check to its own lint
This check was previously categorized under the lint named
`UNSUPPORTED_NAKED_FUNCTIONS`. That lint is future incompatible and will
be turned into an error in a future release. However, as defined in the
Constrained Naked Functions RFC, this check should only be a warning.
This is because it is possible for a naked function to be implemented in
such a way that it does not break even the undefined ABI. For example, a
`jmp` to a `const`.
Therefore, this patch defines a new lint named
`UNDEFINED_NAKED_FUNCTION_ABI` which contains just this single check.
Unlike `UNSUPPORTED_NAKED_FUNCTIONS`, `UNDEFINED_NAKED_FUNCTION_ABI`
will not be converted to an error in the future.
bors [Sat, 7 Aug 2021 20:43:25 +0000 (20:43 +0000)]
Auto merge of #87743 - cuviper:opaque-calls, r=nikic
Prepare call/invoke for opaque pointers
Rather than relying on `getPointerElementType()` from LLVM function
pointers, we now pass the function type explicitly when building `call`
or `invoke` instructions.
Yuki Okushi [Sat, 7 Aug 2021 16:13:45 +0000 (01:13 +0900)]
Rollup merge of #87842 - steffahn:hidden_broken_intra_doc, r=dtolnay
Fix intra doc link in hidden doc of Iterator::__iterator_get_unchecked
Recently, I edited the import list of the `core::iter::traits::iterator` module (in #85874). This results in a broken intra doc link in a hidden documentation with the effect that `RUSTDOCFLAGS='--document-private-items --document-hidden-items' x doc library/std` fails. (This can be worked around by adding `-Arustdoc::broken-intra-doc-links`; still, it’s a broken link so let’s fix it.)
Yuki Okushi [Sat, 7 Aug 2021 16:13:44 +0000 (01:13 +0900)]
Rollup merge of #87838 - jetomit:add-readdir-note, r=dtolnay
Document that fs::read_dir skips . and ..
Hi,
I think this is worth noting in the docs since it differs from POSIX `readdir`. I didn’t put it under platform-specific notes because it seems to be consistent across platforms, and changing this behavior in the future could cause pretty nasty bugs.
Yuki Okushi [Sat, 7 Aug 2021 16:13:43 +0000 (01:13 +0900)]
Rollup merge of #87833 - m-rsha:patch-1, r=Aaron1011
Fix typo -- "The" -> "They"
I was reading through source code to try to learn more about the language and how to make the most of it when I ran into a small typo, so I figured I'd offer up a fix! I'm pretty new now, but hopefully I can offer up more substantial changes later. :D
Yuki Okushi [Sat, 7 Aug 2021 16:13:42 +0000 (01:13 +0900)]
Rollup merge of #87789 - tmiasko:panik, r=Mark-Simulacrum
Make vec-shrink-panic test compatible with v0 mangling
The v0 mangling includes an instantiating crate in a mangled name,
which crates a false positive match for a word `panic`.
Rename crate name / test case to avoid the issue.
Yuki Okushi [Sat, 7 Aug 2021 16:13:41 +0000 (01:13 +0900)]
Rollup merge of #87744 - Smittyvb:xpy-test-force-rerun, r=Mark-Simulacrum
Add x.py option to --force-rerun compiletest tests
This can be used like `./x.py test src/test/ui/abi/ --force-rerun`, and is useful when verifying that newly blessed tests don't change between test runs (such as due to being dependent on the current time or memory layout or RNG), without needing to change the test file or find the right file in `build` to remove.
bors [Sat, 7 Aug 2021 01:26:15 +0000 (01:26 +0000)]
Auto merge of #87408 - kornelski:try_reserve_error, r=yaahc
Hide allocator details from TryReserveError
I think there's [no need for TryReserveError to carry detailed information](https://github.com/rust-lang/rust/issues/48043#issuecomment-825139280), but I wouldn't want that issue to delay stabilization of the `try_reserve` feature.
So I'm proposing to stabilize `try_reserve` with a `TryReserveError` as an opaque structure, and if needed, expose error details later.
This PR moves the `enum` to an unstable inner `TryReserveErrorKind` that lives under a separate feature flag. `TryReserveErrorKind` could possibly be left as an implementation detail forever, and the `TryReserveError` get methods such as `allocation_size() -> Option<usize>` or `layout() -> Option<Layout>` instead, or the details could be dropped completely to make try-reserve errors just a unit struct, and thus smaller and cheaper.
await Marsha [Fri, 6 Aug 2021 23:40:36 +0000 (18:40 -0500)]
Fix typo -- "The" -> "They"
I was reading through source code to try to learn more about the language and how to make the most of it when I ran into a small typo, so I figured I'd offer up a fix! I'm pretty new now, but hopefully I can offer up more substantial changes later. :D
bors [Fri, 6 Aug 2021 18:23:14 +0000 (18:23 +0000)]
Auto merge of #87822 - JohnTitor:rollup-kxojii0, r=JohnTitor
Rollup of 7 pull requests
Successful merges:
- #85807 (bootstrap: Disable initial-exec TLS model on powerpc)
- #87761 (Fix overflow in rustc happening if the `err_count()` is reduced in a stage.)
- #87775 (Add hint for unresolved associated trait items if the trait has a single item)
- #87779 (Remove special case for statement `NodeId` assignment)
- #87787 (Use `C-unwind` ABI for `__rust_start_panic` in `panic_abort`)
- #87809 (Fix typo in the ptr documentation)
- #87816 (Sync rustc_codegen_cranelift)
Yuki Okushi [Fri, 6 Aug 2021 16:46:37 +0000 (01:46 +0900)]
Rollup merge of #87816 - bjorn3:sync_cg_clif-2021-08-06, r=bjorn3
Sync rustc_codegen_cranelift
05677b6bd6c938ed760835d9b1f6514992654ae3 removes two assertions that should have been removed in https://github.com/rust-lang/rust/pull/87515. They are no longer correct and trigger while compiling the sysroot.
Yuki Okushi [Fri, 6 Aug 2021 16:46:35 +0000 (01:46 +0900)]
Rollup merge of #87787 - hyd-dev:c-unwind, r=RalfJung
Use `C-unwind` ABI for `__rust_start_panic` in `panic_abort`
The function originally has `C` ABI but is called using `C-unwind` ABI in `std`:
https://github.com/rust-lang/rust/blob/d4ad1cfc63ba5824196bfb2370451ddb5af2e020/library/std/src/panicking.rs#L49-L54
Which might be [problematic](https://github.com/rust-lang/miri/pull/1745#discussion_r596096876) and triggers this [Miri error](https://github.com/rust-lang/rust/issues/87778#issuecomment-893306222):
```
error: Undefined Behavior: calling a function with ABI C using caller ABI C-unwind
--> /home/hyd-dev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panicking.rs:672:9
|
672 | __rust_start_panic(obj)
| ^^^^^^^^^^^^^^^^^^^^^^^ calling a function with ABI C using caller ABI C-unwind
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
```
Changing the ABI of the function to `C-unwind` fixes the error above.
Yuki Okushi [Fri, 6 Aug 2021 16:46:33 +0000 (01:46 +0900)]
Rollup merge of #87775 - Kobzol:single-associated-item-hint, r=oli-obk
Add hint for unresolved associated trait items if the trait has a single item
This PR introduces a special-cased hint for unresolved trait items paths. It is shown if:
- the path was not resolved to any existing trait item
- and no existing trait item's name was reasonably close with regard to edit distance
- and the trait only has a single item in the corresponding namespace
I didn't know where I should put tests, therefore so far I just managed to bless two existing tests. I would be glad for hints where should tests for a hint like this be created, how should they be named (with reference to the original issue?) and what tests should I create (is it enough to test it just for types? or create separate tests also for functions and constants?).
It could also be turned into a machine applicable suggestion I suppose.
This is my first `rustc` PR, so please go easy on me :)
Yuki Okushi [Fri, 6 Aug 2021 16:46:32 +0000 (01:46 +0900)]
Rollup merge of #87761 - rusticstuff:rustc_error_overflow, r=Mark-Simulacrum
Fix overflow in rustc happening if the `err_count()` is reduced in a stage.
This can happen if stashed diagnostics are removed or replaced with fewer errors. The semantics stay the same if built without overflow checks. Fixes #84219.
Background: I came across this independently by running `RUSTFLAGS="-C overflow-checks=on" ./x.py test`. Fixing this will allow us to move on and find further overflow errors with testing or fuzzing.
bors [Fri, 6 Aug 2021 15:35:01 +0000 (15:35 +0000)]
Auto merge of #87784 - rusticstuff:bootstrap_config_overflow_checks, r=Mark-Simulacrum
Add config.toml options for enabling overflow checks in rustc and std
The names are `overflow-checks` and `overflow-checks-std` and they work similar to `debug-assertions` and `debug-assertions-std`. Once added we can measure how big the performance impact actually is and maybe enable them for CI tests.
Enabling them already makes two ui tests fail:
```
failures:
[ui] ui/parser/item-free-const-no-body-semantic-fail.rs
[ui] ui/parser/item-free-static-no-body-semantic-fail.rs
```
(See #84219 and #87761.)
bors [Fri, 6 Aug 2021 12:11:30 +0000 (12:11 +0000)]
Auto merge of #87777 - the8472:fix-mir-max-rss, r=oli-obk,joshtriplett
Use zeroed allocations in the mir interpreter instead eagerly touching the memory
#86255 introduced a 30% regression in [page faults](https://perf.rust-lang.org/compare.html?start=64ae15ddd3f3cca7036ab2b2f3a6b130b62af4da&end=39e20f1ae5f13451eb35247808d6a2527cb7d060&stat=faults
) and a 3% regression in [max-rss](https://perf.rust-lang.org/index.html?start=2021-07-01&end=&absolute=false&stat=max-rss) in the ctfe-stress benchmarks.
That's most likely happened because it separated allocation from initialization of the vec which defeats the zero-optimization.
Currently there's no allocation API that is fallible, zeroing and returns a slice, so this PR introduces one and then uses that to solve the problem. In principle `vec.resize(len, 0)` could be optimized to use `alloc::grow_zeroed` where appropriate but that would require new specializations and new plumbing in `RawVec`.
bors [Fri, 6 Aug 2021 05:02:35 +0000 (05:02 +0000)]
Auto merge of #87808 - JohnTitor:rollup-qqp79xs, r=JohnTitor
Rollup of 9 pull requests
Successful merges:
- #87561 (thread set_name haiku implementation.)
- #87715 (Add long error explanation for E0625)
- #87727 (explicit_generic_args_with_impl_trait: fix min expected number of generics)
- #87742 (Validate FFI-safety warnings on naked functions)
- #87756 (Add back -Zno-profiler-runtime)
- #87759 (Re-use std::sealed::Sealed in os/linux/process.)
- #87760 (Promote `aarch64-apple-ios-sim` to Tier 2)
- #87770 (permit drop impls with generic constants in where clauses)
- #87780 (alloc: Use intra doc links for the reserve function)
Yuki Okushi [Fri, 6 Aug 2021 02:21:35 +0000 (11:21 +0900)]
Rollup merge of #87770 - BoxyUwU:cec-drop-impl, r=lcnr
permit drop impls with generic constants in where clauses
Fixes #79248
`==` is not sufficient to check for equality between unevaluated consts which causes the above issue because the const in `[(); N - 1]:` on the impl and the const in `[(); N - 1]:` on the struct def are not seen as equal. Any predicate that can contain an unevaluated const cant use `==` here as it will cause us to incorrectly emit an error.
I dont know much about chalk but it seems like we ought to be relating the `TypeWellFormedFromEnv` instead of `==` as it contains a `Ty` so I added that too...
Yuki Okushi [Fri, 6 Aug 2021 02:21:32 +0000 (11:21 +0900)]
Rollup merge of #87756 - Amanieu:no_profiler_runtime, r=jackh726
Add back -Zno-profiler-runtime
This was removed by #85284 in favor of `-Zprofiler-runtime=<name>`.However the suggested `-Zprofiler-runtime=None` doesn't work because`None` is treated as a crate name.
Yuki Okushi [Fri, 6 Aug 2021 02:21:31 +0000 (11:21 +0900)]
Rollup merge of #87742 - npmccallum:naked_ffi, r=Amanieu
Validate FFI-safety warnings on naked functions
Test that FFI-safety warnings don't get accidentally dropped on naked
functions. The big picture is that if you implement a naked function
with the Rust ABI you'll get a warning. Further, if you implement a
naked function with a standardized ABI, but use non-FFI-safe types you
will still get a warning.
rust-lang/rfcs#2774
rust-lang/rfcs#2972
cc ``````@joshtriplett`````` ``````@Amanieu`````` ``````@haraldh``````
Yuki Okushi [Fri, 6 Aug 2021 02:21:30 +0000 (11:21 +0900)]
Rollup merge of #87727 - SkiFire13:fix-87718, r=jackh726
explicit_generic_args_with_impl_trait: fix min expected number of generics
Fixes #87718
The problem was that `synth_type_param_count` was already subtracted from `named_type_param_count`, so this ended up being subtracted again. This caused `expected_min` to overflow, and ultimately resulting in weird and wrong behaviour.
I've also added another test not present in the original issue but caused by the same bug.
In the example (mostly in the `x` function), `other_module::Trait`, `Foo`, `other_module::Whatever`, `bar` and `some_method` are now links (and `other_module` at the top too).
In case there is a type coming from another crate, it'll link to its documentation page and not its definition (but you can then click on `[src]` so I guess it's fine).
Another important detail: I voluntarily didn't add links for primitive types. I think we can discuss about adding links on them or not in a later PR (adding the support for them would require only a few lines).
Here is a video summing up everything I wrote above:
So, on my computer, the performance remains more or less the same (which is quite surprising but that's a nice surprise). Here are the numbers:
Without the option:
* core: 1m 21s
* alloc: 26.78s
* std: 27.30s
* proc_macro: 4.50s
With source to definition links generation (I enabled by default the option):
* core: 1m 25s
* alloc: 25.76s
* std: 27.07s
* proc_macro: 4.66s
So no real change here (again, I'm very surprised by this fact).
For the size of the generated source files (only taking into account the `src` folder here since it's the only one impacted) by running `du -shc .` (when I am in the source folder).
Without the option: 11.939 MB
With the option: 12.611 MB
So not a big change here either. In all those docs, I ran `grep -nR '<a class=' . | wc -l` and got 43917. So there are quite a lot of links added. :)