Commit graph

6265 commits

Author SHA1 Message Date
bors
df89fd2063 Auto merge of #91752 - yaahc:track-caller-result, r=cuviper
Readd track_caller to Result::from_residual

This is a followup on https://github.com/rust-lang/rust/issues/87401 in and an attempt to move the issue towards resolution.

As part of the overhaul of the Try trait we removed the ability for errors to grab location information during propagation via `?` with the builtin `std::result::Result`. The previously linked issue has a fair bit of discussion into the reasons for and against the usage of `#[track_caller]` on the `FromResidual` impl on `Result` that I will do my best to summarize.

---
### For

- https://github.com/rust-lang/rust/issues/87401#issuecomment-915053533: Difficulties with using non `std::result::Result` like types
- https://github.com/rust-lang/rust/issues/87401#issuecomment-978355102: Inconsistency with functionality provided for recoverable (Result) and non-recoverable errors (panic), where panic provides a location and Result does not, pushing some users towards using panic

### Against

- https://github.com/rust-lang/rust/issues/84277#issuecomment-885322833: concern that this will bloat callers that never use this data

---

Personally, I want to quantify the performance / bloat impact of re-adding this attribute, and fully evaluate the pros and cons before deciding if I need to switch `eyre` to have a custom `Result` type, which would also mean I need `try_trait_v2` to be stabilized, cc `@scottmcm.` If the performance impact is minor enough in the general case I think I would prefer that the default `Result` type has the ability to track location information for consistency with `panic` error reporting, and leave it to applications that need particularly high performance to handle the micro optimizations of introducing their own efficient custom Result type or matching manually.

Alternatively, I wonder if the performance penalty on code that doesn't use the location information on `FromResidual` could be mitigated via new optimizations.
2021-12-15 06:34:00 +00:00
Jacob Pratt
d95f749f14
Stabilize destructuring_assignment 2021-12-14 22:38:51 -05:00
bors
195e931b02 Auto merge of #91945 - matthiaskrgr:rollup-jszf9zp, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #90939 (Tweak errors coming from `for`-loop, `?` and `.await` desugaring)
 - #91859 (Iterator::cycle() — document empty iterator special case)
 - #91868 (Use `OutputFilenames` to generate output file for `-Zllvm-time-trace`)
 - #91870 (Revert setting a default for the MACOSX_DEPLOYMENT_TARGET env var for linking)
 - #91881 (Stabilize `iter::zip`)
 - #91882 (Remove `in_band_lifetimes` from `rustc_typeck`)
 - #91940 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-15 03:28:55 +00:00
SparrowLii
a7e48f25bb update stdarch 2021-12-15 10:22:03 +08:00
Ibraheem Ahmed
85f786cc9c add io::Error::other constructor 2021-12-14 20:00:59 -05: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
d6c802ee7a
Rollup merge of #91859 - xkr47:patch-2, r=yaahc
Iterator::cycle() — document empty iterator special case
2021-12-15 01:28:05 +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
bors
d594910a2d Auto merge of #91933 - matthiaskrgr:rollup-cw9qolb, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #89825 (Make split_inclusive() on an empty slice yield an empty output)
 - #91239 (regression test for issue 87490)
 - #91597 (Recover on invalid operators `<>` and `<=>`)
 - #91774 (Fix typo for MutVisitor)
 - #91786 (Return an error when `eval_rvalue_with_identities` fails)
 - #91798 (Avoid suggest adding `self` in visibility spec)
 - #91856 (Looser check for overflowing_binary_op)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-15 00:23:44 +00:00
Scott McMurray
e4c44c5df7 Update comments per review feedback 2021-12-14 15:48:46 -08:00
PFPoitras
304ede6bcc Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
bors
2f4da6243f Auto merge of #91728 - Amanieu:stable_asm, r=joshtriplett
Stabilize asm! and global_asm!

Tracking issue: #72016

It's been almost 2 years since the original [RFC](https://github.com/rust-lang/rfcs/pull/2850) was posted and we're finally ready to stabilize this feature!

The main changes in this PR are:
- Removing `asm!` and `global_asm!` from the prelude as per the decision in #87228.
- Stabilizing the `asm` and `global_asm` features.
- Removing the unstable book pages for `asm` and `global_asm`. The contents are moved to the [reference](https://github.com/rust-lang/reference/pull/1105) and [rust by example](https://github.com/rust-lang/rust-by-example/pull/1483).
  - All links to these pages have been removed to satisfy the link checker. In a later PR these will be replaced with links to the reference or rust by example.
- Removing the automatic suggestion for using `llvm_asm!` instead of `asm!` if you're still using the old syntax, since it doesn't work anymore with `asm!` no longer being in the prelude. This only affects code that predates the old LLVM-style `asm!` being renamed to `llvm_asm!`.
- Updating `stdarch` and `compiler-builtins`.
- Updating all the tests.

r? `@joshtriplett`
2021-12-14 21:15:22 +00:00
Scott McMurray
a0b96902e4 Do array-slice equality via arrays, rather than always via slices
This'll still go via slices eventually for large arrays, but this way slice comparisons to short arrays can use the same memcmp-avoidance tricks.

Added some tests for all the combinations to make sure I didn't accidentally infinitely-recurse something.
2021-12-14 13:15:15 -08:00
Matthias Krüger
50327d2c91
Rollup merge of #89825 - martinvonz:split-inclusive-empty, r=m-ou-se
Make split_inclusive() on an empty slice yield an empty output

`[].split_inclusive()` currently yields a single, empty slice. That's
different from `"".split_inslusive()`, which yields no output at
all. I think that makes the slice version harder to use.

The case where I ran into this bug was when writing code for
generating a diff between two slices of bytes. I wanted to prefix
removed lines with "-" and a added lines with "+". Due to
`split_inclusive()`'s current behavior, that means that my code prints
just a "-" or "+" for empty files. I suspect most existing callers
have similar "bugs" (which would be fixed by this patch).

Closes #89716.
2021-12-14 20:47:26 +01:00
Deadbeef
4f4b2c7271
Constify bool::then{,_some} 2021-12-15 00:11:23 +08:00
Frank Steffahn
a957cefda6 Fix a bunch of typos 2021-12-14 16:40:43 +01:00
bors
404c8471ab Auto merge of #91902 - matthiaskrgr:rollup-hjjyhow, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91529 (add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exact)
 - #91820 (Suggest to specify a target triple when lang item is missing)
 - #91851 (Make `MaybeUninit::zeroed` `const`)
 - #91875 (Use try_normalize_erasing_regions in RevealAllVisitor)
 - #91887 (Remove `in_band_lifetimes` from `rustc_const_eval`)
 - #91892 (Fix HashStable implementation on InferTy)
 - #91893 (Remove `in_band_lifetimes` from `rustc_hir`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-14 11:30:17 +00:00
Anuvrat
90aa8fb3d5 made compiler happy 2021-12-14 16:42:16 +05:30
Matthias Krüger
75e8d65ccd
Rollup merge of #91851 - woppopo:const_maybeuninit_zeroed, r=yaahc
Make `MaybeUninit::zeroed` `const`

Tracking issue: #91850

```rust
// core::mem
impl<T> MaybeUninit<T> {
    pub const fn zeroed() -> MaybeUninit<T>;
}
```
2021-12-14 10:21:04 +01:00
Matthias Krüger
7ec00cd135
Rollup merge of #91529 - TennyZhuang:try_reserve_binary_heap, r=yaahc
add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exact

`try_reserve` of many collections were stablized in https://github.com/rust-lang/rust/pull/87993 in 1.57.0. Add `try_reserve` for the rest collections such as `BinaryHeap` should be not controversial.
2021-12-14 10:21:02 +01:00
bors
83b32f27fc Auto merge of #91766 - scottmcm:more-array-raw-eq, r=yaahc
Allow `memcmp` for more array comparisons

This way comparing `[NonZeroU8; 8]` is just as fast as comparing `[u8; 8]`.
2021-12-14 08:22:31 +00:00
bors
7ca74ea0af Auto merge of #91680 - saethlin:spare_capacity_mut-in-join, r=dtolnay
Use spare_capacity_mut instead of invalid unchecked indexing when joining str

This is a fix for https://github.com/rust-lang/rust/issues/91574

I think in general I'd prefer to see this code implemented with raw pointers or `MaybeUninit::write_slice`, but there's existing code in here based on copying from slice to slice, so converting everything from `&[T]` to `&[MaybeUninit<T>]` is less disruptive.
2021-12-14 04:29:54 +00:00
Andy Russell
4e38807166
core: minor Option doc correction 2021-12-13 22:23:55 -05:00
Esteban Kuber
caf0c1bb1c Reduce verbosity for ? on non-Try expressions 2021-12-13 17:09:15 +00:00
Jonas Berlin
715c562d71
[ReviewFix] Linguistics 2021-12-13 13:52:17 +02:00
Jonas Berlin
7f2f9c60c2
Iterator::cycle() — document empty iterator special case 2021-12-13 13:23:33 +02:00
Konrad Borowski
23e4aeb140 Stabilize const_cstr_unchecked 2021-12-13 08:43:19 +01:00
woppopo
2a5a6680fc Make MaybeUninit::zeroed const 2021-12-13 14:17:35 +09:00
bors
f7fd79ac1d Auto merge of #91841 - matthiaskrgr:rollup-zlhsg5a, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #91086 (Implement `TryFrom<&'_ mut [T]>` for `[T; N]`)
 - #91091 (Stabilize `ControlFlow::{is_break, is_continue}`)
 - #91749 (BTree: improve public descriptions and comments)
 - #91819 (rustbot: Add autolabeling for `T-compiler`)
 - #91824 (Make `(*mut T)::write_bytes` `const`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-13 00:56:18 +00:00
Matthias Krüger
9e662d0c03
Rollup merge of #91824 - woppopo:const_ptr_write_bytes, r=oli-obk
Make `(*mut T)::write_bytes` `const`

Tracking issue: #86302
2021-12-13 00:20:10 +01:00
Matthias Krüger
87cda671e5
Rollup merge of #91749 - ssomers:btree_comments, r=Mark-Simulacrum
BTree: improve public descriptions and comments

BTreeSet has always used the term "value" next to and meaning the same thing as "elements" (in the mathematical sense but also used for key-value pairs in BTreeMap), while in the BTreeMap sense these "values" are known as "keys" and definitely not "values". Today I had enough of that.

r? `@Mark-Simulacrum`
2021-12-13 00:20:08 +01:00
Matthias Krüger
6227d42928
Rollup merge of #91091 - ecstatic-morse:control-flow-enum-is, r=m-ou-se
Stabilize `ControlFlow::{is_break, is_continue}`

The type itself was stabilized in 1.55, but using it is not ergonomic without these helper functions. Stabilize them.

r? rust-lang/libs-api
2021-12-13 00:20:07 +01:00
Matthias Krüger
42f8d4833f
Rollup merge of #91086 - rhysd:issue-91085, r=m-ou-se
Implement `TryFrom<&'_ mut [T]>` for `[T; N]`

Fixes #91085.
2021-12-13 00:20:06 +01: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
Amanieu d'Antras
1c48025685 Address review feedback 2021-12-12 11:26:59 +00:00
Amanieu d'Antras
44a3a66ee8 Stabilize asm! and global_asm!
They are also removed from the prelude as per the decision in
https://github.com/rust-lang/rust/issues/87228.

stdarch and compiler-builtins are updated to work with the new, stable
asm! and global_asm! macros.
2021-12-12 11:20:03 +00:00
Matthias Krüger
955e552d31
Rollup merge of #91814 - japm48:spelling-fix, r=RalfJung
doc: fix typo in comments

`dereferencable -> dereferenceable`

Fixes #91802.
2021-12-12 07:45:30 +01:00
Matthias Krüger
0f3a4c77c4
Rollup merge of #91746 - ssomers:btree_tests, r=Mark-Simulacrum
Btree: assert more API compatibility

Introducing a member such as `BTreeSet::min()` would silently break compatibility if no code calls the existing `BTreeSet::min(set)`. `BTreeSet` is the only btree class silently bringing in stable members, apart from many occurrences of `#[derive(Debug)]` on iterators.

r? `@Mark-Simulacrum`
2021-12-12 07:45:28 +01:00
woppopo
7f5dc0f609 Make (*mut T)::write_bytes const 2021-12-12 14:02:53 +09:00
woppopo
a4b3fe0887 Make PTR::as_ref and similar methods const. 2021-12-12 13:45:27 +09:00
Deadbeef
e22fe4008c
Revert "Auto merge of #89450 - usbalbin:const_try_revert, r=oli-obk"
This reverts commit a8387aef8c, reversing
changes made to 6e12110812.
2021-12-12 12:34:59 +08:00
japm48
0d7b830139 doc: fix typo in comments
dereferencable -> dereferenceable
2021-12-12 00:27:27 +01:00
Matthias Krüger
9031ac4840
Rollup merge of #91806 - woppopo:const_unique, r=dtolnay
Make `Unique`s methods `const`

Tracking issue: None
2021-12-11 23:31:55 +01:00
Matthias Krüger
9aade508d5
Rollup merge of #91797 - the8472:fix-invalid-deref, r=Mark-Simulacrum
Fix zero-sized reference to deallocated memory

fixes #91772

r? `@camelid`
2021-12-11 23:31:54 +01:00
Matthias Krüger
90eb610d14
Rollup merge of #91737 - Manishearth:panic-immediate-stdlib, r=joshtriplett
Make certain panicky stdlib functions behave better under panic_immediate_abort

The stdlib has a `panic_immediate_abort` feature that turns panics into immediate aborts, without any formatting/display logic. This feature was [introduced](https://github.com/rust-lang/rust/pull/55011) primarily for codesize-constrained situations.

Unfortunately, this win doesn't quite propagate to `Result::expect()` and `Result::unwrap()`, while the formatting machinery is reduced, `expect()` and `unwrap()` both call `unwrap_failed("msg", &err)` which has a signature of `fn unwrap_failed(msg: &str, error: &dyn fmt::Debug)` and is `#[inline(never)]`. This means that `unwrap_failed` will unconditionally construct a `dyn Debug` trait object even though the object is never used in the function.

Constructing a trait object (even if you never call a method on it!) forces rust to include the vtable and any dependencies. This means that in `panic_immediate_abort` mode, calling expect/unwrap on a Result will pull in a whole bunch of formatting code for the error type even if it's completely unused.

This PR swaps out the function with one that won't require a trait object such that it won't force the inclusion of vtables in the code. It also gates off `#[inline(never)]` in a bunch of other places where allowing the inlining of an abort may be useful (this kind of thing is already done elsewhere in the stdlib).

I don't know how to write a test for this; we don't really seem to have any tests for `panic_immediate_abort` anyway so perhaps it's fine as is.
2021-12-11 23:31:50 +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
woppopo
34eaf52829 Make Uniques methods const 2021-12-12 04:27:43 +09: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
ed81098fcc
Rollup merge of #91721 - danielhenrymantilla:patch-1, r=joshtriplett
Minor improvements to `future::join!`'s implementation

This is a follow-up from #91645, regarding [some remarks I made](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/join!/near/264293660).

Mainly:
  - it hides the recursive munching through a private `macro`, to avoid leaking such details (a corollary is getting rid of the need to use ``@`` to disambiguate);
  - it uses a `match` binding, _outside_ the `async move` block, to better match the semantics from function-like syntax;
  - it pre-pins the future before calling into `poll_fn`, since `poll_fn`, alone, cannot guarantee that its capture does not move (to clarify: I believe the previous code was sound, thanks to the outer layer of `async`. But I find it clearer / more robust to refactorings this way 🙂).
  - it uses `@ibraheemdev's` very neat `.ready()?`;
  - it renames `Took` to `Taken` for consistency with `Done` (tiny nit 😄).

~~TODO~~Done:

  - [x] Add unit tests to enforce the function-like `:value` semantics are respected.

r? `@nrc`
2021-12-11 17:35:27 +01:00
Matthias Krüger
60b9f3130d
Rollup merge of #91548 - luojia65:hint-spin-loop-riscv, r=Amanieu
Add spin_loop hint for RISC-V architecture

This commit uses the PAUSE instruction (https://github.com/rust-lang/stdarch/pull/1262) to implement RISC-V spin loop, and updates `stdarch` submodule to use the merged PAUSE instruction.
2021-12-11 17:35:26 +01:00
Matthias Krüger
7fbaf33a3c
Rollup merge of #90741 - mbartlett21:patch-4, r=dtolnay
Const `Option::cloned`

This constifies the two `Option::cloned` functions, bounded on `~const Clone`.
2021-12-11 17:35:25 +01:00
Matthias Krüger
40482bb539
Rollup merge of #90270 - woppopo:const_borrow_trait, r=dtolnay
Make `Borrow` and `BorrowMut` impls `const`

Tracking issue: #91522
2021-12-11 17:35:24 +01:00
The 8472
9063b64cff Fix zero-sized reference to deallocated memory
fixes #91772
2021-12-11 17:10:56 +01:00
Martin Fischer
e1c9a88152 Fix since attribute for const_manually_drop feature
const_manually_drop was stabilized in 1.32 as mentioned in
https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1320-2019-01-17
2021-12-11 17:10:03 +01:00
Matthias Krüger
bb23d82e6f
Rollup merge of #91782 - maxwase:is_symlink_since_attribute, r=jyn514
Correct since attribute for `is_symlink` feature

Follow-up from [89677](https://github.com/rust-lang/rust/pull/89677)
2021-12-11 16:02:50 +01:00
Matthias Krüger
94ac197585
Rollup merge of #91711 - andrewbanchich:improve-zip-example, r=Mark-Simulacrum
Improve `std::iter::zip` example

`println!` isn't great for doc comments / tests.
2021-12-11 16:02:48 +01:00
TennyZhuang
2235af1a68 update feature gate 2021-12-11 22:54:17 +08:00
TennyZhuang
d0f8793d89 add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exact
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2021-12-11 20:29:44 +08:00
Maxwase
8fafb77af9 Correct since attribute for feature 2021-12-11 13:47:20 +03:00
Matthias Krüger
5da73311be
Rollup merge of #91553 - devnexen:anc_data_dfbsd, r=yaahc
socket ancillary data implementation for dragonflybsd.
2021-12-11 08:22:33 +01:00
Matthias Krüger
27c791ca86
Rollup merge of #91515 - jethrogb:rsplit_array, r=yaahc
Add rsplit_array variants to slices and arrays

By request: https://github.com/rust-lang/rust/issues/90091#issuecomment-985903239

r? `@yaahc`
2021-12-11 08:22:32 +01:00
Matthias Krüger
2f8e2ff6ba
Rollup merge of #91127 - scottmcm:ptr_to_from_bits, r=dtolnay
Add `<*{const|mut} T>::{to|from}_bits`

Named based on the floating-point methods of the same name, as those are also about returning the *representation* of the value.

Tracking issue: https://github.com/rust-lang/rust/issues/91126

Based on the conversation in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20methods.20as.20more.20specific.20versions.20of.20.60as.60/near/238391074

r? `@joshtriplett`
2021-12-11 08:22:29 +01:00
bors
c185610ebc Auto merge of #91761 - matthiaskrgr:rollup-bjowmvz, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #91668 (Remove the match on `ErrorKind::Other`)
 - #91678 (Add tests fixed by #90023)
 - #91679 (Move core/stream/stream/mod.rs to core/stream/stream.rs)
 - #91681 (fix typo in `intrinsics::raw_eq` docs)
 - #91686 (Fix `Vec::reserve_exact` documentation)
 - #91697 (Delete Utf8Lossy::from_str)
 - #91706 (Add unstable book entries for parts of asm that are not being stabilized)
 - #91709 (Replace iterator-based set construction by *Set::From<[T; N]>)
 - #91716 (Improve x.py logging and defaults a bit more)
 - #91747 (Add pierwill to .mailmap)
 - #91755 (Fix since attribute for const_linked_list_new feature)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-11 03:52:12 +00:00
Scott McMurray
24affba02e Allow memcmp for more array comparisons
This way comparing `[NonZeroU8; 8]` is just as fast as comparing `[u8; 8]`.
2021-12-10 17:30:39 -08:00
Matthias Krüger
637859b26e
Rollup merge of #91755 - not-my-profile:fix-const_linked_list_new-since, r=dtolnay
Fix since attribute for const_linked_list_new feature

https://github.com/rust-lang/rust/pull/63684
was merged for 1.39 not 1.32
2021-12-10 22:41:31 +01:00
Matthias Krüger
3beeb75dde
Rollup merge of #91709 - juniorbassani:use-from-array-in-set-examples, r=jyn514
Replace iterator-based set construction by *Set::From<[T; N]>

This uses the array-based construction for `BtreeSet`s and `HashSet`s instead of first creating an iterator. I could also replace the `let mut a = Set::new(); a.insert(...);` fragments if desired.
2021-12-10 22:41:28 +01:00
Matthias Krüger
2784051c11
Rollup merge of #91697 - dtolnay:lossyfromstr, r=Mark-Simulacrum
Delete Utf8Lossy::from_str

This whole type is marked as being for str internals only, but this constructor is never used by str internals. If you had a &amp;str already and wanted to lossy display it or iterate its lossy utf8 chunks, you would simply not use Utf8Lossy because the whole &amp;str is known to be one contiguous valid utf8 chunk.

If code really does need to obtain a value of type &amp;Utf8Lossy somewhere, and has only a &amp;str, `Utf8Lossy::from_bytes(s.as_bytes())` remains available. As currently implemented, there is no performance penalty relative to `from_str` i.e. the Utf8Lossy does not "remember" that it was constructed using `from_str` to bypass later utf8 decoding.
2021-12-10 22:41:26 +01:00
Matthias Krüger
1d36c6ac2e
Rollup merge of #91686 - dalcde:patch-1, r=dtolnay
Fix `Vec::reserve_exact` documentation

The documentation previously said the new capacity cannot overflow `usize`, but in fact it cannot exceed `isize::MAX`.
2021-12-10 22:41:25 +01:00
Matthias Krüger
4286ade8c9
Rollup merge of #91681 - WaffleLapkin:patch-3, r=scottmcm
fix typo in `intrinsics::raw_eq` docs
2021-12-10 22:41:24 +01:00
Matthias Krüger
6451de0a5d
Rollup merge of #91679 - ibraheemdev:stream-mod, r=Mark-Simulacrum
Move core/stream/stream/mod.rs to core/stream/stream.rs

Removes an unnecessary nested module.
2021-12-10 22:41:23 +01:00
Matthias Krüger
1fca934898
Rollup merge of #91646 - ibraheemdev:patch-9, r=dtolnay
Fix documentation for `core::ready::Ready`
2021-12-10 22:40:37 +01:00
Matthias Krüger
ca352c4522
Rollup merge of #91524 - rukai:fix_extend_from_slice_docs, r=dtolnay
Fix Vec::extend_from_slice docs

`other` is a slice not a vector.
2021-12-10 22:40:34 +01:00
Matthias Krüger
5510803fe9
Rollup merge of #91482 - JosephTLyons:update-HashMap-and-BTreeMap-documentation, r=yaahc
Update documentation to use `from()` to initialize `HashMap`s and `BTreeMap`s

As of Rust 1.56, `HashMap` and `BTreeMap` both have associated `from()` functions.  I think using these in the documentation cleans things up a bit.  It allows us to remove some of the `mut`s and avoids the Initialize-Then-Modify anti-pattern.
2021-12-10 22:40:33 +01:00
Matthias Krüger
d317da48b1
Rollup merge of #91325 - RalfJung:const_eval_select, r=dtolnay
adjust const_eval_select documentation

"The Rust compiler assumes" indicates that this is language UB, but [I don't think that is a good idea](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const_eval_select.20assumptions). This UB would be very hard to test for and looks like a way-too-big footgun. ``@oli-obk`` suggested this is meant to be more like "library UB", so I tried to adjust the docs accordingly.

I also removed all references to "referential transparency". That is a rather vague concept used to mean many different things, and I honestly have no idea what exactly is meant by it in this specific instance. But I assume ``@fee1-dead`` had in their mind a property that all `const fn` code upholds, so by demanding that the runtime code and the const-time code are *observably equivalent*, whatever that property is would also be enforced here.

Cc ``@rust-lang/wg-const-eval``
2021-12-10 22:40:32 +01:00
Matthias Krüger
60aa03aa71
Rollup merge of #91105 - jplatte:stream-docs, r=dtolnay
Fix method name reference in stream documentation
2021-12-10 22:40:31 +01:00
Matthias Krüger
616f9efebb
Rollup merge of #90897 - jhpratt:fix-incorrect-feature-flags, r=dtolnay
Fix incorrect stability attributes

These two instances were caught in #90356, but that PR isn't going to be merged. I've extracted these to ensure it's still correct.

``@rustbot`` label: +A-stability +C-cleanup +S-waiting-on-review
2021-12-10 22:40:29 +01:00
Jethro Beekman
203cf2d366 Add rsplit_array variants to slices and arrays 2021-12-10 21:34:19 +01:00
Martin Fischer
305dd6908c Fix since attribute for const_linked_list_new feature
https://github.com/rust-lang/rust/pull/63684
was merged for 1.39 not 1.32
2021-12-10 20:22:19 +01:00
Jane Lusby
44756d8d96 Readd track_caller to Result::from_residual 2021-12-10 09:17:55 -08:00
Stein Somers
27b4b19c8c BTree: improve public descriptions and comments 2021-12-10 17:37:55 +01:00
Stein Somers
cc35a11a39 BTree: assert presence of derived functions 2021-12-10 16:30:04 +01:00
Stein Somers
c8bc4b7a55 BTree: rename compile-time assertions to match library/alloc/tests 2021-12-10 16:22:39 +01:00
Josh Triplett
67ab53daee
Update library/core/tests/future.rs
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2021-12-10 05:07:52 -08:00
Manish Goregaokar
917dafc73a Add separate impl of unwrap_failed to avoid constructing trait objects 2021-12-10 13:12:26 +05:30
Manish Goregaokar
0adee2c01e inline Option panics on panic_immediate_abort 2021-12-10 13:08:06 +05:30
Manish Goregaokar
3cf9ae6ff3 inline slice panics on panic_immediate_abort 2021-12-10 13:05:06 +05:30
Andrew Banchich
c78fb62255 Improve std::iter::zip example.
Update library/core/src/iter/adapters/zip.rs

Co-authored-by: r00ster <r00ster91@protonmail.com>

Update library/core/src/iter/adapters/zip.rs

Co-authored-by: r00ster <r00ster91@protonmail.com>
2021-12-09 17:29:36 -05:00
Daniel Henry-Mantilla
f8dc13db43 Add tests asserting the function-like semantics of join!() 2021-12-09 22:57:30 +01:00
Daniel Henry-Mantilla
e277a98758
Fix missing mut typo
Co-authored-by: Ibraheem Ahmed <ibrah1440@gmail.com>
2021-12-09 21:21:37 +01:00
Daniel Henry-Mantilla
07bcf4aad3 Bring back the colon separators for the macro munching.
Co-Authored-By: Ibraheem Ahmed <ibrah1440@gmail.com>
2021-12-09 21:05:34 +01:00
Daniel Henry-Mantilla
846cb9c583 Fix two false positive lints 2021-12-09 21:05:34 +01:00
Daniel Henry-Mantilla
e936071fbf Minor improvements to future::join!'s implementation
This is a follow-up from #91645, regarding [some remarks I made](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/join!/near/264293660).

Mainly:
  - it hides the recursive munching through a private `macro`, to avoid leaking such details (a corollary is getting rid of the need to use `@` to disambiguate);
  - it uses a `match` binding, _outside_ the `async move` block, to better match the semantics from function-like syntax;
  - it pre-pins the future before calling into `poll_fn`, since `poll_fn`, alone, cannot guarantee that its capture does not move;
  - it uses `.ready()?` since it's such a neat pattern;
  - it renames `Took` to `Taken` for consistency with `Done`.
2021-12-09 21:05:29 +01:00
bors
0b42deaccc Auto merge of #85157 - the8472:drain-drop-in-place, r=Mark-Simulacrum
replace vec::Drain drop loops with drop_in_place

The `Drain::drop` implementation came up in https://github.com/rust-lang/rust/pull/82185#issuecomment-789584796 as potentially interfering with other optimization work due its widespread use somewhere in `println!`

`@rustbot` label T-libs-impl
2021-12-09 15:01:42 +00:00
Júnior Bassani
cebd9494bd
Replace iterator-based set construction by *Set::From<[T; N]> 2021-12-09 11:56:19 -03:00
luojia65
0ccf58b928 Update stdarch dependency 2021-12-09 22:33:25 +08:00
bors
3b263ceb5c Auto merge of #81156 - DrMeepster:read_buf, r=joshtriplett
Implement most of RFC 2930, providing the ReadBuf abstraction

This replaces the `Initializer` abstraction for permitting reading into uninitialized buffers, closing #42788.

This leaves several APIs described in the RFC out of scope for the initial implementation:

* read_buf_vectored
* `ReadBufs`

Closes #42788, by removing the relevant APIs.
2021-12-09 10:11:55 +00: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
David Tolnay
4b0a9c9bc3
Delete Utf8Lossy::from_str 2021-12-08 22:54:51 -08:00
Matthias Krüger
856eefece9
Rollup merge of #89999 - talagrand:GetTempPath2, r=m-ou-se
Update std::env::temp_dir to use GetTempPath2 on Windows when available.

As a security measure, Windows 11 introduces a new temporary directory API, GetTempPath2.
When the calling process is running as SYSTEM, a separate temporary directory
will be returned inaccessible to non-SYSTEM processes. For non-SYSTEM processes
the behavior will be the same as before.

This can help mitigate against attacks such as this one:
https://medium.com/csis-techblog/cve-2020-1088-yet-another-arbitrary-delete-eop-a00b97d8c3e2

Compatibility risk: Software which relies on temporary files to communicate between SYSTEM and non-SYSTEM
processes may be affected by this change. In many cases, such patterns may be vulnerable to the very
attacks the new API was introduced to harden against.
I'm unclear on the Rust project's tolerance for such change-of-behavior in the standard library. If anything,
this PR is meant to raise awareness of the issue and hopefully start the conversation.

How tested: Taking the example code from the documentation and running it through psexec (from SysInternals) on
Win10 and Win11.
On Win10:
C:\test>psexec -s C:\test\main.exe
<...>
Temporary directory: C:\WINDOWS\TEMP\

On Win11:
C:\test>psexec -s C:\test\main.exe
<...>
Temporary directory: C:\Windows\SystemTemp\
2021-12-09 05:08:31 +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