Commit graph

4878 commits

Author SHA1 Message Date
Aris Merchant
dc38d87505 Fix linker error
This makes `fs::hard_link` use weak! for some platforms,
thereby preventing a linker error.
2021-07-09 23:24:36 -07:00
Kornel
bc67f6bc95 Debug formatting of raw_arg() 2021-07-09 14:24:34 +01:00
Kornel
8f9d0f12eb Use AsRef in CommandExt for raw_arg 2021-07-09 14:09:48 +01:00
Kornel
d868da7796 Unescaped command-line arguments for Windows
Fixes #29494
2021-07-09 14:09:48 +01:00
Kornel
fcd5cecdcf Test escaping of trialing slashes in Windows command-line args 2021-07-09 14:09:48 +01:00
bors
ee86f96ba1 Auto merge of #85828 - scottmcm:raw-eq, r=oli-obk
Stop generating `alloca`s & `memcmp` for simple short array equality

Example:
```rust
pub fn demo(x: [u16; 6], y: [u16; 6]) -> bool { x == y }
```

Before:
```llvm
define zeroext i1 `@_ZN10playground4demo17h48537f7eac23948fE(i96` %0, i96 %1) unnamed_addr #0 {
start:
  %y = alloca [6 x i16], align 8
  %x = alloca [6 x i16], align 8
  %.0..sroa_cast = bitcast [6 x i16]* %x to i96*
  store i96 %0, i96* %.0..sroa_cast, align 8
  %.0..sroa_cast3 = bitcast [6 x i16]* %y to i96*
  store i96 %1, i96* %.0..sroa_cast3, align 8
  %_11.i.i.i = bitcast [6 x i16]* %x to i8*
  %_14.i.i.i = bitcast [6 x i16]* %y to i8*
  %bcmp.i.i.i = call i32 `@bcmp(i8*` nonnull dereferenceable(12) %_11.i.i.i, i8* nonnull dereferenceable(12) %_14.i.i.i, i64 12) #2, !alias.scope !2
  %2 = icmp eq i32 %bcmp.i.i.i, 0
  ret i1 %2
}
```
```x86
playground::demo: # `@playground::demo`
	sub	rsp, 32
	mov	qword ptr [rsp], rdi
	mov	dword ptr [rsp + 8], esi
	mov	qword ptr [rsp + 16], rdx
	mov	dword ptr [rsp + 24], ecx
	xor	rdi, rdx
	xor	esi, ecx
	or	rsi, rdi
	sete	al
	add	rsp, 32
	ret
```

After:
```llvm
define zeroext i1 `@_ZN4mini4demo17h7a8994aaa314c981E(i96` %0, i96 %1) unnamed_addr #0 {
start:
  %2 = icmp eq i96 %0, %1
  ret i1 %2
}
```
```x86
_ZN4mini4demo17h7a8994aaa314c981E:
	xor	rcx, r8
	xor	edx, r9d
	or	rdx, rcx
	sete	al
	ret
```
2021-07-09 09:16:27 +00:00
bors
95fb131521 Auto merge of #86904 - m-ou-se:prelude-collision-check-trait, r=nikomatsakis
Check FromIterator trait impl in prelude collision check.

Fixes #86902.
2021-07-09 06:35:42 +00:00
Scott McMurray
b63b2f1e42 PR feedback
- Add `:Sized` assertion in interpreter impl
- Use `Scalar::from_bool` instead of `ScalarInt: From<bool>`
- Remove unneeded comparison in intrinsic typeck
- Make this UB to call with undef, not just return undef in that case
2021-07-08 14:55:57 -07:00
Scott McMurray
2456495a26 Stop generating allocas+memcmp for simple array equality 2021-07-08 14:55:54 -07:00
Scott McMurray
d05eafae2f Move the PartialEq and Eq impls for arrays to a separate file 2021-07-08 14:53:37 -07:00
Stein Somers
35d02e2c6a BTree: lazily locate leaves in rangeless iterators 2021-07-08 22:34:35 +02:00
bors
8b87e85394 Auto merge of #86930 - tspiteri:int_log10, r=kennytm
special case for integer log10

Now that #80918 has been merged, this PR provides a faster version of `log10`.

The PR also adds some tests for values close to all powers of 10.
2021-07-08 20:19:00 +00:00
bors
aa65b08b1d Auto merge of #86982 - GuillaumeGomez:rollup-7sbye3c, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #84961 (Rework SESSION_GLOBALS API)
 - #86726 (Use diagnostic items instead of lang items for rfc2229 migrations)
 - #86789 (Update BTreeSet::drain_filter documentation)
 - #86838 (Checking that function is const if marked with rustc_const_unstable)
 - #86903 (Fix small headers display)
 - #86913 (Document rustdoc with `--document-private-items`)
 - #86957 (Update .mailmap file)
 - #86971 (mailmap: Add alternative addresses for myself)

Failed merges:

 - #86869 (Account for capture kind in auto traits migration)

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-08 17:51:10 +00:00
Guillaume Gomez
ff4bf73a42
Rollup merge of #86789 - janikrabe:btreeset-drainfilter-doc, r=kennytm
Update BTreeSet::drain_filter documentation

This commit makes the documentation of `BTreeSet::drain_filter` more
consistent with that of `BTreeMap::drain_filter` after the changes in
f0b8166870.

In particular, this explicitly documents the iteration order.
2021-07-08 18:30:34 +02:00
Guillaume Gomez
d12b16887b
Rollup merge of #86726 - sexxi-goose:use-diagnostic-item-for-rfc2229-migration, r=nikomatsakis
Use diagnostic items instead of lang items for rfc2229 migrations

This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in https://github.com/rust-lang/rust/pull/84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations.

r? ```@nikomatsakis```
2021-07-08 18:30:33 +02:00
bors
d0485c7986 Auto merge of #86520 - ssomers:btree_iterators_checked_unwrap, r=Mark-Simulacrum
BTree: consistently avoid unwrap_unchecked in iterators

Some iterator support functions named `_unchecked` internally use `unwrap`, some use `unwrap_unchecked`. This PR tries settling on `unwrap`. #86195 went up the same road but travelled way further and doesn't seem successful.

r? `@Mark-Simulacrum`
2021-07-08 15:06:43 +00:00
bors
0cd0709f19 Auto merge of #86823 - the8472:opt-chunk-tra, r=kennytm
Optimize unchecked indexing into chunks and chunks_mut

Fixes #53340

```
# BEFORE

$ rustc +nightly -Copt-level=3 -Ccodegen-units=1 -Clto=fat chunks.rs
$ perf stat ./chunks

 Performance counter stats for './chunks':

          3,177.03 msec task-clock                #    1.000 CPUs utilized
                 4      context-switches          #    0.001 K/sec
                 0      cpu-migrations            #    0.000 K/sec
           984,006      page-faults               #    0.310 M/sec
    13,092,199,322      cycles                    #    4.121 GHz                      (83.29%)
       384,543,475      stalled-cycles-frontend   #    2.94% frontend cycles idle     (83.35%)
     7,414,280,722      stalled-cycles-backend    #   56.63% backend cycles idle      (83.38%)
    50,493,980,662      instructions              #    3.86  insn per cycle
                                                  #    0.15  stalled cycles per insn  (83.29%)
     6,625,375,297      branches                  # 2085.396 M/sec                    (83.38%)
         3,087,652      branch-misses             #    0.05% of all branches          (83.31%)

       3.178079469 seconds time elapsed

       2.327156000 seconds user
       0.762041000 seconds sys

# AFTER

$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc -Copt-level=3 -Ccodegen-units=1 -Clto=fat chunks.rs
$ perf stat ./chunks

 Performance counter stats for './chunks':

          2,705.76 msec task-clock                #    1.000 CPUs utilized
                 4      context-switches          #    0.001 K/sec
                 0      cpu-migrations            #    0.000 K/sec
           984,005      page-faults               #    0.364 M/sec
    11,156,763,039      cycles                    #    4.123 GHz                      (83.26%)
       342,198,882      stalled-cycles-frontend   #    3.07% frontend cycles idle     (83.37%)
     6,486,263,637      stalled-cycles-backend    #   58.14% backend cycles idle      (83.37%)
    40,553,476,617      instructions              #    3.63  insn per cycle
                                                  #    0.16  stalled cycles per insn  (83.37%)
     6,668,429,113      branches                  # 2464.532 M/sec                    (83.37%)
         3,099,636      branch-misses             #    0.05% of all branches          (83.26%)

       2.706725288 seconds time elapsed

       1.782083000 seconds user
       0.848424000 seconds sys
```
2021-07-08 09:44:52 +00:00
Yuki Okushi
01474ad92c
Rollup merge of #86956 - cuviper:unalias-every, r=m-ou-se
Revert "Add "every" as a doc alias for "all"."

This reverts commit 35450365ac (#81697) for "every" and closes #86554 in kind for "some".

The new [doc alias policy](https://std-dev-guide.rust-lang.org/documentation/doc-alias-policy.html) is that we don't want language-specific aliases like these JavaScript names, and we especially don't want to conflict with real names. While "every" is okay in the latter regard, its natural pair "some" makes a doc-search collision with `Option::Some`.

r? ```@m-ou-se```
2021-07-08 10:44:37 +09:00
Yuki Okushi
0f37050b74
Rollup merge of #86955 - Swordelf2:patch-1, r=cuviper
Fix typo in `ops::Drop` docs
2021-07-08 10:44:36 +09:00
Yuki Okushi
a57a2e991d
Rollup merge of #86917 - notriddle:notriddle/from-try-reserve-error, r=JohnTitor
Add doc comment for `impl From<LayoutError> for TryReserveError`
2021-07-08 10:44:31 +09:00
Mara Bos
e3044432c7 Move [debug_]assert_matches to mod {core, std}::assert. 2021-07-08 02:33:36 +02:00
Josh Stone
ace3989d55 Revert "Add "every" as a doc alias for "all"."
This reverts commit 35450365ac.
2021-07-07 13:13:26 -07:00
Swordelf2
7677f5fe31
Fix typo in ops::Drop docs 2021-07-07 22:26:32 +03:00
cyberia
a853a49425 Clarify behaviour of f64 and f32::sqrt when argument is negative zero 2021-07-07 18:22:17 +01:00
Mara Bos
60535441c8 Check FromIterator trait impl in prelude collision check. 2021-07-07 13:26:38 +00:00
Christiaan Dirkx
a674ae6f76 Add documentation for Ipv6MulticastScope 2021-07-07 14:41:06 +02:00
Trevor Spiteri
ed76c11202 special case for integer log10 2021-07-07 14:10:05 +02:00
Trevor Spiteri
b0f98c60a6 test integer log10 values close to all powers of 10 2021-07-07 14:07:32 +02:00
Yuki Okushi
9aee3c2883
Rollup merge of #86916 - godmar:@godmar/thread-yield-documentation-fix, r=joshtriplett
rewrote documentation for thread::yield_now()

The old documentation suggested the use of yield_now for repeated
polling instead of discouraging it; it also made the false claim that
channels are implemented using yield_now. (They are not, except for
a corner case).
2021-07-07 12:17:44 +09:00
Yuki Okushi
fe3d6a74d9
Rollup merge of #86906 - juniorbassani:update-sync-docs, r=yaahc
Replace deprecated compare_and_swap and fix typo in core::sync::atomic::{fence, compiler_fence} docs
2021-07-07 12:17:42 +09:00
Yuki Okushi
c630b6b0fc
Rollup merge of #86880 - m-ou-se:test-manuallydrop-clone-from, r=Mark-Simulacrum
Test ManuallyDrop::clone_from.

See #86288
2021-07-07 12:17:41 +09:00
Yuki Okushi
7e95290caa
Rollup merge of #86717 - rylev:rename, r=nikomatsakis
Rename some Rust 2021 lints to better names

Based on conversation in https://github.com/rust-lang/rust/issues/85894.

Rename a bunch of Rust 2021 related lints:

Lints that are officially renamed because they are already in beta or stable:
* `disjoint_capture_migration` => `rust_2021_incompatible_closure_captures`
* `or_patterns_back_compat` => `rust_2021_incompatible_or_patterns`
* `non_fmt_panic` => `non_fmt_panics`

Lints that are renamed but don't require any back -compat work since they aren't yet in stable:
* `future_prelude_collision` => `rust_2021_prelude_collisions`
* `reserved_prefix` => `rust_2021_token_prefixes`

Lints that have been discussed but that I did not rename:
* ~`non_fmt_panic` and `bare_trait_object`: is making this plural worth the headache we might cause users?~
* `array_into_iter`: I'm unsure of a good name and whether bothering users with a name change is worth it.

r? `@nikomatsakis`
2021-07-07 12:17:39 +09:00
Yuki Okushi
9bbc470e97
Rollup merge of #80918 - yoshuawuyts:int-log2, r=m-ou-se
Add Integer::log variants

_This is another attempt at landing https://github.com/rust-lang/rust/pull/70835, which was approved by the libs team but failed on Android tests through Bors. The text copied here is from the original issue. The only change made so far is the addition of non-`checked_` variants of the log methods._

_Tracking issue: #70887_

---

This implements `{log,log2,log10}` methods for all integer types. The implementation was provided by `@substack` for use in the stdlib.

_Note: I'm not big on math, so this PR is a best effort written with limited knowledge. It's likely I'll be getting things wrong, but happy to learn and correct. Please bare with me._

## Motivation
Calculating the logarithm of a number is a generally useful operation. Currently the stdlib only provides implementations for floats, which means that if we want to calculate the logarithm for an integer we have to cast it to a float and then back to an int.

> would be nice if there was an integer log2 instead of having to either use the f32 version or leading_zeros() which i have to verify the results of every time to be sure

_— [`@substack,` 2020-03-08](https://twitter.com/substack/status/1236445105197727744)_

At higher numbers converting from an integer to a float we also risk overflows. This means that Rust currently only provides log operations for a limited set of integers.

The process of doing log operations by converting between floats and integers is also prone to rounding errors. In the following example we're trying to calculate `base10` for an integer. We might try and calculate the `base2` for the values, and attempt [a base swap](https://www.rapidtables.com/math/algebra/Logarithm.html#log-rules) to arrive at `base10`. However because we're performing intermediate rounding we arrive at the wrong result:

```rust
// log10(900) = ~2.95 = 2
dbg!(900f32.log10() as u64);

// log base change rule: logb(x) = logc(x) / logc(b)
// log2(900) / log2(10) = 9/3 = 3
dbg!((900f32.log2() as u64) / (10f32.log2() as u64));
```
_[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6bd6c68b3539e400f9ca4fdc6fc2eed0)_

This is somewhat nuanced as a lot of the time it'll work well, but in real world code this could lead to some hard to track bugs. By providing correct log implementations directly on integers we can help prevent errors around this.

## Implementation notes

I checked whether LLVM intrinsics existed before implementing this, and none exist yet. ~~Also I couldn't really find a better way to write the `ilog` function. One option would be to make it a private method on the number, but I didn't see any precedent for that. I also didn't know where to best place the tests, so I added them to the bottom of the file. Even though they might seem like quite a lot they take no time to execute.~~

## References

- [Log rules](https://www.rapidtables.com/math/algebra/Logarithm.html#log-rules)
- [Rounding error playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6bd6c68b3539e400f9ca4fdc6fc2eed0)
- [substack's tweet asking about integer log2 in the stdlib](https://twitter.com/substack/status/1236445105197727744)
- [Integer Logarithm, A. Jaffer 2008](https://people.csail.mit.edu/jaffer/III/ilog.pdf)
2021-07-07 12:17:32 +09:00
Jon Gjengset
cf40292122
Link tracking issue for pin_deref_mut 2021-07-06 16:59:45 -07:00
Michael Howell
a151982af3 Add doc comment for impl From<LayoutError> for TryReserveError 2021-07-06 14:44:18 -07:00
Godmar Back
fb464a3b39 rewrote documentation for thread::yield_now()
The old documentation suggested the use of yield_now for repeated
polling instead of discouraging it; it also made the false claim that
channels are implementing using yield_now. (They are not, except for
a corner case).
2021-07-06 15:50:42 -04:00
Ryan Levick
a902e25f58 Add s to non_fmt_panic 2021-07-06 20:12:56 +02:00
Ryan Levick
1d49658f5c Change or_patterns_back_compat lint to rust_2021_incompatible_or_patterns 2021-07-06 20:11:45 +02:00
Júnior Bassani
0d61e6e8d6
Fix typo in core::sync::atomic::compiler_fence example 2021-07-06 10:53:14 -03:00
Júnior Bassani
a87fb18027
Replace deprecated compare_and_swap by compare_exchange_weak in core::sync::atomic::fence example 2021-07-06 10:50:17 -03:00
Aris Merchant
d9752c7d84 Improve env var getter docs 2021-07-05 22:19:30 -07:00
Aris Merchant
a12107afaa Make getenv return an Option instead of a Result 2021-07-05 22:19:23 -07:00
Aris Merchant
f2c0f29248 Change env var getters to error recoverably
Before this, `std`'s env var getter functions would panic on
receiving certain invalid inputs. This commit makes them
return a `None` or `Err` instead.
2021-07-05 22:13:38 -07:00
Yuki Okushi
470ed70a86
Rollup merge of #86852 - Amanieu:remove_doc_aliases, r=joshtriplett
Remove some doc aliases

As per the new doc alias policy in https://github.com/rust-lang/std-dev-guide/pull/25, this removes some controversial doc aliases:
- `malloc`, `alloc`, `realloc`, etc.
- `length` (alias for `len`)
- `delete` (alias for `remove` in collections and also file/directory deletion)

r? `@joshtriplett`
2021-07-06 02:33:16 +09:00
Yuki Okushi
2bc7d4d70a
Rollup merge of #86794 - inquisitivecrystal:seek-rewind, r=m-ou-se
Stabilize `Seek::rewind()`

This stabilizes `Seek::rewind`. It seemed to fit into one of the existing tests, so I extended that test rather than adding a new one.

Closes #85149.
2021-07-06 02:33:15 +09:00
Yuki Okushi
add24d2f4f
Rollup merge of #85377 - ijackson:abort-docs, r=m-ou-se
aborts: Clarify documentation and comments

In the docs for intrinsics::abort():

 * Strengthen the recommendation by to use process::abort instead.
 * Document the fact that it sometimes (ab)uses an LLVM debug trap and what the likely consequences are.
 * State that the precise behaviour is unstable.

In the docs for process::abort():

 * Promise that we have the same behaviour as C `abort()`.
 * Document the likely consequences, including, specifically, the consequences on Unix.

In the internal comment for unix::abort_internal:

 * Refer to the public docs for the public API functions.
 * Correct and expand the description of libc::abort.  Specifically:
 * Do not claim that abort() unregisters signal handlers.  It doesn't; it honours the SIGABRT handler.
 * Discuss, extensively, the issue with abort() flushing stdio buffers.
 * Describe the glibc behaviour in some detail.

Co-authored-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>

Fixes #40230
2021-07-06 02:33:13 +09:00
Yuki Okushi
1fcd9abbb1
Rollup merge of #83581 - arennow:dir_entry_ext_unix_borrow_name, r=m-ou-se
Add std::os::unix::fs::DirEntryExt2::file_name_ref(&self) -> &OsStr

Greetings!

This is my first PR here, so please forgive me if I've missed an important step or otherwise done something wrong. I'm very open to suggestions/fixes/corrections.

This PR adds a function that allows `std::fs::DirEntry` to vend a borrow of its filename on Unix platforms, which is especially useful for sorting. (Windows has (as I understand it) encoding differences that require an allocation.) This new function sits alongside the cross-platform [`file_name(&self) -> OsString`](https://doc.rust-lang.org/std/fs/struct.DirEntry.html#method.file_name) function.

I pitched this idea in an [internals thread](https://internals.rust-lang.org/t/allow-std-direntry-to-vend-borrows-of-its-filename/14328/4), and no one objected vehemently, so here we are.

I understand features in general, I believe, but I'm not at all confident that my whole-cloth invention of a new feature string (as required by the compiler) was correct (or that the name is appropriate). Further, there doesn't appear to be a test for the sibling `ino` function, so I didn't add one for this similarly trivial function either. If it's desirable that I should do so, I'd be happy to [figure out how to] do that.

The following is a trivial sample of a use-case for this function, in which directory entries are sorted without any additional allocations:

```rust
use std::os::unix::fs::DirEntryExt;
use std::{fs, io};

fn main() -> io::Result<()> {
    let mut entries = fs::read_dir(".")?.collect::<Result<Vec<_>, io::Error>>()?;
    entries.sort_unstable_by(|a, b| a.file_name_ref().cmp(b.file_name_ref()));

    for p in entries {
        println!("{:?}", p);
    }

    Ok(())
}
```
2021-07-06 02:33:06 +09:00
Mara Bos
469f4674fb
Enable dir_entry_ext2 feature in doc test.
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
2021-07-05 16:26:54 +02:00
bors
6e9b3696d4 Auto merge of #84560 - cjgillot:inline-iter, r=m-ou-se
Inline Iterator as IntoIterator.

For some reason, it appears on rustc's own perf stats.
2021-07-05 13:12:07 +00:00
Mara Bos
3d20b2a14f Test ManuallyDrop::clone_from. 2021-07-05 11:55:45 +00:00
Mara Bos
08d912fdcc s/die/terminate/ in abort documentation. 2021-07-05 12:43:45 +02:00
Mara Bos
f73a555fc9 Use american spelling for behaviour
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
2021-07-05 12:43:03 +02:00
Ian Jackson
19c347ede9 Talk about "terminate" rather than "die"
Adapted from a suggestion by @m-ou-se.

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-05 12:43:03 +02:00
Ian Jackson
44852e0603 Talk about invalid instructions rather than debug traps
And withdraw the allegation of "abuse".

Adapted from a suggestion by @m-ou-se.

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-05 12:43:03 +02:00
Ian Jackson
4e7c348140 abort docs: Document buffer non-flushing
There is discussion of this in #40230 which requests clarification.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-05 12:43:02 +02:00
Ian Jackson
de19e4d2b6 abort docs: Do not claim that intrinsics::abort is always a debug trap
As per discussion here
 https://github.com/rust-lang/rust/pull/85377#pullrequestreview-660460501

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-05 12:43:02 +02:00
Ian Jackson
a8bb7fa76b aborts: Clarify documentation and comments
In the docs for intrinsics::abort():

 * Strengthen the recommendation by to use process::abort instead.
 * Document the fact that it (ab)uses an LLVM debug trap and what the
   likely consequences are.
 * State that the precise behaviour is unstable.

In the docs for process::abort():

 * Promise that we have the same behaviour as C `abort()`.
 * Document the likely consequences, including, specifically, the
   consequences on Unix.

In the internal comment for unix::abort_internal:

 * Refer to the public docs for the public API functions.
 * Correct and expand the description of libc::abort.  Specifically:
 * Do not claim that abort() unregisters signal handlers.  It doesn't;
   it honours the SIGABRT handler.
 * Discuss, extensively, the issue with abort() flushing stdio buffers.
 * Describe the glibc behaviour in some detail.

Co-authored-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-05 12:43:00 +02:00
bors
5efa4c0555 Auto merge of #86875 - JohnTitor:rollup-fuefamw, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #86477 (E0716: clarify that equivalent code example is erroneous)
 - #86623 (Add check to ensure error code explanations are not removed anymore even if not emitted)
 - #86856 (Make x.py less verbose on failures)
 - #86858 (Stabilize `string_drain_as_str`)
 - #86859 (Add a regression test for issue-69323)
 - #86862 (re-export SwitchIntEdgeEffects)
 - #86864 (Add missing code example for Write::write_vectored)
 - #86874 (Bump deps)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-04 22:23:06 +00:00
Yuki Okushi
0e4c4cd076
Rollup merge of #86864 - GuillaumeGomez:example-write-vectored, r=JohnTitor
Add missing code example for Write::write_vectored
2021-07-05 07:13:28 +09:00
Yuki Okushi
28dba82e11
Rollup merge of #86858 - JohnTitor:stabilize-string-drain-as-str, r=Mark-Simulacrum
Stabilize `string_drain_as_str`

Closes #76905, FCP is done: https://github.com/rust-lang/rust/issues/76905#issuecomment-873461688
2021-07-05 07:13:25 +09:00
bors
b3d11f95cc Auto merge of #86598 - yoshuawuyts:poll-method-docs, r=JohnTitor
Add examples to the various methods of `core::task::Poll`

This improves the documentation of the various methods of [`core::task::Poll`](https://doc.rust-lang.org/std/task/enum.Poll.html). These currently have fairly simple docs with no examples. This PR changes these methods to be closer to `core::option::Option` and adds usage examples (and importantly: tests!) to `Poll`'s methods.

cc/ `@rust-lang/wg-async-foundations`

## Screenshots

<details>
<summary>View generated rustdoc page</summary>
<image src="https://user-images.githubusercontent.com/2467194/123286616-59ee9b00-d50e-11eb-9e02-40269070f904.png" alt="Poll in core::task"></details>
2021-07-04 20:00:57 +00:00
Guillaume Gomez
f742cde948 Add missing code example for Write::write_vectored 2021-07-04 19:23:29 +02:00
bors
90442458ac Auto merge of #86048 - nbdd0121:no_floating_point, r=Amanieu
core: add unstable no_fp_fmt_parse to disable float formatting code

In some projects (e.g. kernel), floating point is forbidden. They can disable
hardware floating point support and use `+soft-float` to avoid fp instructions
from being generated, but as libcore contains the formatting code for `f32`
and `f64`, some fp intrinsics are depended. One could define stubs for these
intrinsics that just panic [1], but it means that if any formatting functions
are accidentally used, mistake can only be caught during the runtime rather
than during compile-time or link-time, and they consume a lot of space without
LTO.

This patch provides an unstable cfg `no_fp_fmt_parse` to disable these.
A panicking stub is still provided for the `Debug` implementation (unfortunately)
because there are some SIMD types that use `#[derive(Debug)]`.

[1]: https://lkml.org/lkml/2021/4/14/1028
2021-07-04 14:18:57 +00:00
bors
308fc2322b Auto merge of #86213 - jhpratt:stabilize-const-from_utf8_unchecked, r=JohnTitor
Stabilize `str::from_utf8_unchecked` as `const`

This stabilizes `unsafe fn str::from_utf8_unchecked` as `const` pending FCP on #75196. By the time FCP finishes, the beta will have already been cut, so I've set 1.55 as the stable-since version.

(should also be +relnotes but I don't have the permission to do that)

r? `@m-ou-se`

Closes #75196
2021-07-04 11:56:55 +00:00
Yuki Okushi
ab86df0ce9
Stabilize string_drain_as_str 2021-07-04 14:23:43 +09:00
bors
71a567fae4 Auto merge of #86833 - crlf0710:remove-std-raw-mod, r=SimonSapin
Remove the deprecated `core::raw` and `std::raw` module.

A few months has passed since #84207. I think now it's time for the final removal.

Closes #27751.

r? `@m-ou-se`
2021-07-04 04:04:47 +00:00
bors
1540711946 Auto merge of #85270 - ChrisDenton:win-env-case, r=m-ou-se
When using `process::Command` on Windows, environment variable names must be case-preserving but case-insensitive

When using `Command` to set the environment variables, the key should be compared as uppercase Unicode but when set it should preserve the original case.

Fixes #85242
2021-07-04 01:24:05 +00:00
Taylor Yu
24d6536be9 stdio_locked: add tracking issue 2021-07-03 11:35:47 -05:00
bors
8649737bee Auto merge of #86810 - ojeda:alloc-gate, r=dtolnay
alloc: `no_global_oom_handling`: disable `new()`s, `pin()`s, etc.

They are infallible, and could not be actually used because
they will trigger an error when monomorphized, but it is better
to just remove them.

Link: https://github.com/Rust-for-Linux/linux/pull/402
Suggested-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-07-03 13:23:28 +00:00
bors
a8b8558f08 Auto merge of #86799 - tlyu:stdio-locked, r=joshtriplett
add owned locked stdio handles

Add stderr_locked, stdin_locked, and stdout_locked free functions
to obtain owned locked stdio handles in a single step. Also add
into_lock methods to consume a stdio handle and return an owned
lock. These methods will make it easier to use locked stdio
handles without having to deal with lifetime problems or keeping
bindings to the unlocked handles around.

Fixes #85383; enables #86412.

r? `@joshtriplett`
`@rustbot` label +A-io +C-enhancement +D-newcomer-roadblock +T-libs-api
2021-07-03 10:40:53 +00:00
Charles Lew
0d1919c7ab Remove the deprecated core::raw and std::raw module. 2021-07-03 14:03:27 +08:00
bors
fdd9a07147 Auto merge of #79965 - ijackson:moreerrnos, r=joshtriplett
More ErrorKinds for common errnos

From the commit message of the main commit here (as revised):

```
There are a number of IO error situations which it would be very
useful for Rust code to be able to recognise without having to resort
to OS-specific code.  Taking some Unix examples, `ENOTEMPTY` and
`EXDEV` have obvious recovery strategies.  Recently I was surprised to
discover that `ENOSPC` came out as `ErrorKind::Other`.

Since I am familiar with Unix I reviwed the list of errno values in
  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html

Here, I add those that most clearly seem to be needed.

`@CraftSpider` provided information about Windows, and references, which
I have tried to take into account.

This has to be insta-stable because we can't sensibly have a different
set of ErrorKinds depending on a std feature flag.

I have *not* added these to the mapping tables for any operating
systems other than Unix and Windows.  I hope that it is OK to add them
now for Unix and Windows now, and maybe add them to other OS's mapping
tables as and when someone on that OS is able to consider the
situation.

I adopted the general principle that it was usually a bad idea to map
two distinct error values to the same Rust error code.  I notice that
this principle is already violated in the case of `EACCES` and
`EPERM`, which both map to `PermissionDenied`.  I think this was
probably a mistake but it would be quite hard to change now, so I
don't propose to do anything about that.

However, for Windows, there are sometimes different error codes for
identical situations.  Eg there are WSA* versions of some error
codes as well as ERROR_* ones.  Also Windows seems to have a great
many more erorr codes.  I don't know precisely what best practice
would be for Windows.
```

<strike>

```
Errno values I wasn't sure about so *haven't* included:

EMFILE ENFILE ENOBUFS ENOLCK:

  These are all fairly Unix-specific resource exhaustion situations.
  In practice it seemed not very likely to me that anyone would want
  to handle these differently to `Other`.

ENOMEM ERANGE EDOM EOVERFLOW

  Normally these don't get exposed to the Rust callers I hope.  They
  don't tend to come out of filesystem APIs.

EILSEQ

  Hopefully Rust libraries open files in binary mode and do the
  converstion in Rust.  So Rust code ought not to be exposed to
  EILSEQ.

EIO

  The range of things that could cause this is troublesome.  I found
  it difficult to describe.  I do think it would be useful to add this
  at some point, because EIO on a filesystem operation is much more
  serious than most other errors.

ENETDOWN

  I wasn't sure if this was useful or, indeed, if any modern systems
  use it.

ENOEXEC

  It is not clear to me how a Rust program could respond to this.  It
  seems rather niche.

EPROTO ENETRESET ENODATA ENOMSG ENOPROTOOPT ENOSR ENOSTR ETIME
ENOTRECOVERABLE EOWNERDEAD EBADMSG EPROTONOSUPPORT EPROTOTYPE EIDRM

  These are network or STREAMS related errors which I have never in
  my own Unix programming found the need to do anything with.  I think
  someone who understands these better should be the one to try to
  find good Rust names and descriptions for them.

ENOTTY ENXIO ENODEV EOPNOTSUPP ESRCH EALREADY ECANCELED ECHILD
EINPROGRESS

  These are very hard to get unless you're already doing something
  very Unix-specific, in which case the raw_os_error interface is
  probably more suitable than relying on the Rust ErrorKind mapping.

EFAULT EBADF

  These would seem to be the result of application UB.
```
</strike>
<i>(omitted errnos are discussed below, especially in https://github.com/rust-lang/rust/pull/79965#issuecomment-810468334)
2021-07-03 04:12:36 +00:00
Christiaan Dirkx
c93cb40b90 Move os_str_bytes to sys::unix and reuse it on other platforms. 2021-07-03 03:01:36 +02:00
Gary Guo
ec7292ad3c core: add unstable no_fp_fmt_parse to disable float fmt/parse code
In some projects (e.g. kernel), floating point is forbidden. They can disable
hardware floating point support and use `+soft-float` to avoid fp instructions
from being generated, but as libcore contains the formatting code for `f32`
and `f64`, some fp intrinsics are depended. One could define stubs for these
intrinsics that just panic [1], but it means that if any formatting functions
are accidentally used, mistake can only be caught during the runtime rather
than during compile-time or link-time, and they consume a lot of space without
LTO.

This patch provides an unstable cfg `no_fp_fmt_parse` to disable these.
A panicking stub is still provided for the `Debug` implementation (unfortunately)
because there are some SIMD types that use `#[derive(Debug)]`.

[1]: https://lkml.org/lkml/2021/4/14/1028
2021-07-02 22:52:37 +01:00
The8472
24094a04b6 optimize chunks and chunks_mut 2021-07-02 23:14:05 +02:00
Taylor Yu
c58ceb7a42 stdio_locked: updates based on feedback
Rename methods to `into_locked`. Remove type aliases for owned locks.
2021-07-02 15:56:56 -05:00
Yuki Okushi
df55204afb
Rollup merge of #86807 - tversteeg:patch-1, r=bjorn3
Fix double import in wasm thread

The `unsupported` type is imported two times, as `super::unsupported` and as `crate::sys::unsupported`, throwing an error. Remove `super::unsupported` in favor of the other.

As reported in #86802.

Fix #86802
2021-07-03 03:15:13 +09:00
Yuki Okushi
6107340483
Rollup merge of #86803 - xfix:remove-unnecessary-ampersand-from-command-args-calls, r=joshtriplett
Remove & from Command::args calls in documentation

Now that arrays implement `IntoIterator`, using `&` is no longer necessary. This makes examples easier to understand.
2021-07-03 03:15:12 +09:00
Yuki Okushi
7fb3c29dc6
Rollup merge of #86308 - bstrie:intrinsafe, r=JohnTitor
Docs: clarify that certain intrinsics are not unsafe

As determined by the hardcoded list at 003b8eadd7/compiler/rustc_typeck/src/check/intrinsic.rs (L59-L92)
2021-07-03 03:15:10 +09:00
Yuki Okushi
fb736d96c3
Rollup merge of #85001 - CDirkx:bytestring, r=JohnTitor
Merge `sys_common::bytestring` back into `os_str_bytes`

`bytestring` contains code for correctly debug formatting a byte slice (`[u8]`). This functionality is and has historically only been used to provide the debug formatting of byte-based os-strings (on unix etc.).

Having this functionality in the separate `bytestring` module was useful in the past to reduce duplication, as [when it was added](https://github.com/rust-lang/rust/pull/46798) `os_str_bytes` was still split into `sys::{unix, redox, wasi, etc.}::os_str`. However, now that is no longer the case, there is not much reason for the `bytestring` functionality to be separate from `os_str_bytes`; I don't think it is very likely that another part of std will need to handle formatting byte strings that are not os-strings in the future (everything should be `utf8`). This is why this PR merges the functionality of `bytestring` directly into the debug implementation in `os_str_bytes`.
2021-07-03 03:15:09 +09:00
Yuki Okushi
45470a3bcd
Rollup merge of #84029 - drahnr:master, r=petrochenkov
add `track_path::path` fn for usage in `proc_macro`s

Adds a way to declare a dependency on external files without including them, to either re-trigger the build of a file as well as covering the use case of including dependencies within the `rustc` invocation, such that tools like `sccache`/`cachepot` are able to handle references to external files which are not included.

Ref #73921
2021-07-03 03:15:07 +09:00
Sören Meier
626bab5a7c Remove unstable Cursor::remaining 2021-07-02 16:23:44 +02:00
Miguel Ojeda
7775dffbc0 alloc: no_global_oom_handling: disable new()s, pin()s, etc.
They are infallible, and could not be actually used because
they will trigger an error when monomorphized, but it is better
to just remove them.

Link: https://github.com/Rust-for-Linux/linux/pull/402
Suggested-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-07-02 14:55:20 +02:00
bors
ce331ee6ee Auto merge of #86806 - GuillaumeGomez:rollup-pr5r37w, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #85749 (Revert "Don't load all extern crates unconditionally")
 - #86714 (Add linked list cursor end methods)
 - #86737 (Document rustfmt on nightly-rustc)
 - #86776 (Skip layout query when computing integer type size during mangling)
 - #86797 (Stabilize `Bound::cloned()`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-02 11:42:38 +00:00
Thomas Versteeg
d3bf89b302
Fix double import in wasm thread
The `unsupported` type is imported two times, as `super::unsupported` and as `crate::sys::unsupported`, throwing an error. Remove `super::unsupported` in favor of the other.
2021-07-02 09:37:00 +00:00
Guillaume Gomez
cd3a48fdb6
Rollup merge of #86797 - inquisitivecrystal:bound-cloned, r=jyn514
Stabilize `Bound::cloned()`

This PR stabilizes the function `Bound::cloned()`.

Closes #61356.
2021-07-02 11:35:31 +02:00
Guillaume Gomez
ccdbda6688
Rollup merge of #86714 - iwahbe:add-linked-list-cursor-end-methods, r=Amanieu
Add linked list cursor end methods

I add several methods to `LinkedList::CursorMut` and `LinkedList::Cursor`. These methods allow you to access/manipulate the ends of a list via the cursor. This is especially helpful when scanning through a list and reordering. For example:

```rust
let mut c = ll.back_cursor_mut();
let mut moves = 10;
while c.current().map(|x| x > 5).unwrap_or(false) {
    let n = c.remove_current();
    c.push_front(n);
    if moves > 0 { break; } else { moves -= 1; }
}
```
I encountered this problem working on my bachelors thesis doing graph index manipulation.

While this problem can be avoided by splicing, it is awkward. I asked about the problem [here](https://internals.rust-lang.org/t/linked-list-cursurmut-missing-methods/14921/4) and it was suggested I write a PR.

All methods added consist of
```rust
Cursor::front(&self) -> Option<&T>;
Cursor::back(&self) -> Option<&T>;
CursorMut::front(&self) -> Option<&T>;
CursorMut::back(&self) -> Option<&T>;
CursorMut::front_mut(&mut self) -> Option<&mut T>;
CursorMut::back_mut(&mut self) -> Option<&mut T>;
CursorMut::push_front(&mut self, elt: T);
CursorMut::push_back(&mut self, elt: T);
CursorMut::pop_front(&mut self) -> Option<T>;
CursorMut::pop_back(&mut self) -> Option<T>;
```
#### Design decisions:
I tried to remain as consistent as possible with what was already present for linked lists.
The methods `front`, `front_mut`, `back` and `back_mut` are identical to their `LinkedList` equivalents.

I tried to make the `pop_front` and `pop_back` methods work the same way (vis a vis the "ghost" node) as `remove_current`. I thought this was the closest analog.

`push_front` and `push_back` do not change the "current" node, even if it is the "ghost" node. I thought it was most intuitive to say that if you add to the list, current will never change.

Any feedback would be welcome 😄
2021-07-02 11:35:28 +02:00
Konrad Borowski
18715c0753 Remove & from Command::args calls in documentation
Now that arrays implement `IntoIterator`, using
`&` is no longer necessary. This makes examples
easier to understand.
2021-07-02 11:14:42 +02:00
bors
f9fa13f705 Auto merge of #85746 - m-ou-se:io-error-other, r=joshtriplett
Redefine `ErrorKind::Other` and stop using it in std.

This implements the idea I shared yesterday in the libs meeting when we were discussing how to handle adding new `ErrorKind`s to the standard library: This redefines `Other` to be for *user defined errors only*, and changes all uses of `Other` in the standard library to a `#[doc(hidden)]` and permanently `#[unstable]` `ErrorKind` that users can not match on. This ensures that adding `ErrorKind`s at a later point in time is not a breaking change, since the user couldn't match on these errors anyway. This way, we use the `#[non_exhaustive]` property of the enum in a more effective way.

Open questions:
- How do we check this change doesn't cause too much breakage? Will a crate run help and be enough?
- How do we ensure we don't accidentally start using `Other` again in the standard library? We don't have a `pub(not crate)` or `#[deprecated(in this crate only)]`.

cc https://github.com/rust-lang/rust/pull/79965

cc `@rust-lang/libs` `@ijackson`

r? `@dtolnay`
2021-07-02 09:01:42 +00:00
Bernhard Schuster
67e6a81315 add track_path::path fn for proc-macro usage
Ref #73921
2021-07-02 07:13:19 +02:00
Taylor Yu
b3db5cd46c add owned locked stdio handles
Add stderr_locked, stdin_locked, and stdout_locked free functions
to obtain owned locked stdio handles in a single step. Also add
into_lock methods to consume a stdio handle and return an owned
lock. These methods will make it easier to use locked stdio
handles without having to deal with lifetime problems or keeping
bindings to the unlocked handles around.
2021-07-01 20:55:46 -05:00
Taylor Yu
2b4a6aa149 fix missing word 2021-07-01 19:14:27 -05:00
Aris Merchant
f2b21e2d0b Stabilize Bound::cloned() 2021-07-01 17:09:57 -07:00
Aris Merchant
6d34a2e007 Stabilize Seek::rewind 2021-07-01 15:08:20 -07:00
Yuki Okushi
76bf7c0069
Rollup merge of #86785 - lf-:dead-code, r=Mark-Simulacrum
proc_macro/bridge: Remove dead code Slice type

See https://github.com/rust-lang/rust/pull/85390#discussion_r662464868
2021-07-02 06:20:34 +09:00
Yuki Okushi
3ec8e6c5fd
Rollup merge of #86783 - mark-i-m:mutex-drop-unsized, r=Xanewok
Move Mutex::unlock to T: ?Sized

r? ``@mbrubeck``

cc https://github.com/rust-lang/rust/issues/81872
2021-07-02 06:20:33 +09:00
Janik Rabe
2dd69aaafc Document iteration order of retain functions
For `HashSet` and `HashMap`, this simply copies the comment from
`BinaryHeap::retain`.

For `BTreeSet` and `BTreeMap`, this adds an additional guarantee that
wasn't previously documented. I think that because these data structures
are inherently ordered and other functions guarantee ordered iteration,
it makes sense to provide this guarantee for `retain` as well.
2021-07-01 22:15:13 +01:00
Janik Rabe
3b2ad49a7a Update BTreeSet::drain_filter documentation
This commit makes the documentation of `BTreeSet::drain_filter` more
consistent with that of `BTreeMap::drain_filter` after the changes in
f0b8166870.

In particular, this explicitly documents the iteration order.
2021-07-01 21:56:10 +01:00
Ian Wahbe
c4ad273fe1 Implement changes suggested by @Amanieu 2021-07-01 21:08:01 +02:00
Jade
0b3fedc8df proc_macro/bridge: Remove dead code Slice type
See https://github.com/rust-lang/rust/pull/85390#discussion_r662464868
2021-07-01 10:20:57 -07:00
Mark Mansi
057bc91399 Move Mutex::unlock to T: ?Sized 2021-07-01 12:04:41 -05:00
Josh Stone
6f5e933adb Make the specialized Fuse still deal with None 2021-06-30 16:10:33 -07:00
bstrie
2db05230d3 impl From<[(K, V); N]> for std::collections 2021-06-30 17:28:17 -04:00
Amanieu d'Antras
e2536bb271 Remove "length" doc aliases 2021-06-30 20:28:51 +01:00
Amanieu d'Antras
fc2705d707 Remove "delete" doc aliases 2021-06-30 20:28:51 +01:00
Amanieu d'Antras
618c805746 Remove alloc/malloc/calloc/realloc doc aliases 2021-06-30 19:59:39 +01:00
Miguel Ojeda
7c9445d4a7 alloc: RawVec<T, A>::shrink can be in no_global_oom_handling.
Found in https://github.com/Rust-for-Linux/linux/pull/402.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-06-30 19:42:41 +02:00
Roxane
cc3af7091c Rename variable 2021-06-29 20:26:37 -04:00
Roxane Fruytier
06afafd492 Use diagnostic items to check for Send, UnwindSafe and RefUnwindSafe traits 2021-06-29 17:47:57 -04:00
Roxane Fruytier
3e569dd2df Remove lang items Send, UnwindSafe and RefUnwindSafe 2021-06-29 17:47:57 -04:00
Ian Wahbe
e77acf7d27 Add non-mutable methods to Cursor 2021-06-29 15:35:14 +02:00
Ian Wahbe
a981be75cc add head/tail methods to linked list mutable cursor 2021-06-29 15:24:01 +02:00
Mark Rousskov
06661ba759 Update to new bootstrap compiler 2021-06-28 11:30:49 -04:00
bors
17ea490310 Auto merge of #82624 - ojeda:rwlock-example-deadlock, r=JohnTitor
RWLock: Add deadlock example

Suggested in https://github.com/rust-lang/rust/pull/82596 but it was a bit too late.

`@matklad` `@azdavis` `@sfackler`
2021-06-28 09:58:06 +00:00
bors
9cdb2d3d59 Auto merge of #86655 - jonas-schievink:const-arguments-as-str, r=kennytm
Make `fmt::Arguments::as_str` unstably const

Motivation: mostly to move "panic!() in const contexts" forward, making use of `as_str` was mentioned in https://github.com/rust-lang/rust/issues/85194#issuecomment-852345377 and seems like the simplest way forward.
2021-06-27 15:45:29 +00:00
Albin Hedman
22fe76d97d
Add reference to tracking issue #86302 for const_ptr_write 2021-06-27 12:05:19 +02:00
Albin Hedman
1aa032f506
Add reference to issue for const_intrinsic_copy in ptr::write 2021-06-27 12:05:19 +02:00
Albin Hedman
6c890bb969
Revert "Revert tests added by PR 81167."
This reverts commit cebfcd3256.
2021-06-27 12:05:17 +02:00
Albin Hedman
5fbb1354ce
Revert "Revert effects of PRs 81167 and 83091."
This reverts commit 9d96b0ed8c.
2021-06-27 12:05:16 +02:00
Jonas Schievink
b3fbfe474b Make fmt::Arguments::as_str unstably const 2021-06-27 03:54:06 +02:00
bors
481971978f Auto merge of #86586 - Smittyvb:https-everywhere, r=petrochenkov
Use HTTPS links where possible

While looking at #86583, I wondered how many other (insecure) HTTP links were in `rustc`. This changes most other `http` links to `https`. While most of the links are in comments or documentation, there are a few other HTTP links that are used by CI that are changed to HTTPS.

Notes:
- I didn't change any to or in licences
- Some links don't support HTTPS :(
- Some `http` links were dead, in those cases I upgraded them to their new places (all of which used HTTPS)
2021-06-26 08:24:31 +00:00
bors
6830052c7b Auto merge of #86637 - ehuss:spellings, r=dtolnay
Fix a few misspellings.
2021-06-26 05:09:27 +00:00
Eric Huss
6235e6f93f Fix a few misspellings. 2021-06-25 13:18:56 -07:00
Mara Bos
cc90733008 Restore original ordering of ErrorKind::Other. 2021-06-25 19:04:08 +00:00
Yoshua Wuyts
9f579968cd Add Integer::{log,log2,log10} variants 2021-06-25 18:52:46 +02:00
Yuki Okushi
9e4649995f
Rollup merge of #86592 - jhpratt:non_exhaustive, r=JohnTitor
Use `#[non_exhaustive]` where appropriate

Due to the std/alloc split, it is not possible to make `alloc::collections::TryReserveError::AllocError` non-exhaustive without having an unstable, doc-hidden method to construct (which negates the benefits from `#[non_exhaustive]`).

`@rustbot` label +C-cleanup +T-libs +S-waiting-on-review
2021-06-26 00:42:12 +09:00
bors
50e0cc59ff Auto merge of #86151 - scottmcm:simple-hash-of, r=joshtriplett
Add `BuildHasher::hash_one` as unstable

Inspired by https://github.com/rust-lang/rust/pull/86140/files#diff-246941135168fbc44fce120385ee9c3156e08a1c3e2697985b56dcb8d728eedeR2416, where I wanted to write a quick test for a `Hash` implementation and it took more of a dance than I'd hoped.

It looks like this would be handy in hashtable implementations, too -- a quick look at hashbrown found two places where it needs to do the same dance:
6302512a8a/src/map.rs (L247-L270)

I wanted to get a "seems plausible" from a libs member before making a tracking issue, so random-sampling the intersection of highfive and governance gave me...
r? `@joshtriplett`

(As always, bikeshed away!  And let me know if I missed something obvious again that I should have used instead.)
2021-06-25 06:47:30 +00:00
est31
8e328be73d Fix grammar mistake
present perfect passive constructions need to use the past participle form,
which for run is "run".
2021-06-25 00:54:34 +02:00
est31
5585cce06c Add another example 2021-06-25 00:54:34 +02:00
Yoshua Wuyts
a06ee821b7 Document the various methods of core::task::Poll 2021-06-25 00:41:56 +02:00
bors
cbeda5cbeb Auto merge of #86467 - ChrisDenton:win-env-clear, r=JohnTitor
Windows: Fix `Command::env_clear` so it works if no variables are set

Previously, it would error unless at least one new environment variable was added. The missing null presumably meant that Windows was reading random memory in that case.

See: [CreateProcessW](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) (scroll down to `lpEnvironment`). Essentially the environment block is a null terminated list of null terminated strings and an empty list is `\0\0` and not `\0`.

EDIT: Oh, [CreateEnvironmentBlock](https://docs.microsoft.com/en-gb/windows/win32/api/userenv/nf-userenv-createenvironmentblock) states this much more explicitly.

Fixes #31259
2021-06-24 17:37:29 +00:00
Taylor Yu
c196cc9f12 option/result overviews: address feedback
(Most of these are from a review by joshtriplett. Thanks!)

Fix errors in `as_pin_ref` and `as_pin_mut` in the "Adapters for
working with references" overview.

Reword some headings about transformation methods.

Reclassify `map`, `map_or`, `map_or_else`, `map_err`, etc. to more
accurately reflect which variants they transform.

Document `Debug` requirement for `get_or_insert_default`.

Reword text about `take` and `replace` to be more accurate.

Add examples for the `Product` and `Sum` traits.

Also:

Move link reference definitions closer to their uses. Warn about making
link reference definintions for `err` and `ok`. Avoid making other link
reference definitions that might conflict in the future (foreign methods
that share a name with local ones, etc.)

Write out the generics of `Option` and `Result` when the following
text refers to the type parameters.
2021-06-24 12:33:51 -05:00
Jacob Pratt
5d85130995
Partially stabilize const_slice_first_last 2021-06-24 05:16:45 -04:00
Chris Denton
16145a9952
Test that env_clear works on Windows 2021-06-24 09:32:24 +01:00
Scott McMurray
579d19bc6a Use hash_one to simplify some other doctests 2021-06-24 01:30:48 -07:00
Scott McMurray
63d28192da Add tracking issue and rename to hash_one 2021-06-24 01:30:48 -07:00
Scott McMurray
a3eb9e3db2 Add BuildHasher::hash_of as unstable 2021-06-24 01:30:48 -07:00
Jacob Pratt
3f14f4b3ce
Use #[non_exhaustive] where appropriate
Due to the std/alloc split, it is not possible to make
`alloc::collections::TryReserveError::AllocError` non-exhaustive without
having an unstable, doc-hidden method to construct (which negates the
benefits from `#[non_exhaustive]`.
2021-06-24 04:16:11 -04:00
Yuki Okushi
0fa4f0ba62
Rollup merge of #86415 - Kmeakin:iterator-associativity-docs, r=dtolnay
Document associativity of iterator folds.

Document the associativity of `Iterator::fold` and
`DoubleEndedIterator::rfold` and add examples demonstrating this.
Add links to direct users to the fold of the opposite associativity.
2021-06-24 13:47:34 +09:00
Smitty
bdfcb88e8b Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
Yoshua Wuyts
660f585413 Add core::stream::from_iter 2021-06-23 17:49:26 +02:00
bors
8cb207ae69 Auto merge of #86386 - inquisitivecrystal:better-errors-for-display-traits-v3, r=estebank
Better errors for Debug and Display traits

Currently, if someone tries to pass value that does not implement `Debug` or `Display` to a formatting macro, they get a very verbose and confusing error message. This PR changes the error messages for missing `Debug` and `Display` impls to be less overwhelming in this case, as suggested by #85844. I was a little less aggressive in changing the error message than that issue proposed. Still, this implementation would be enough to reduce the number of messages to be much more manageable.

After this PR, information on the cause of an error involving a `Debug` or `Display` implementation would suppressed if the requirement originated within a standard library macro. My reasoning was that errors originating from within a macro are confusing when they mention details that the programmer can't see, and this is particularly problematic for `Debug` and `Display`, which are most often used via macros. It is possible that either a broader or a narrower criterion would be better. I'm quite open to any feedback.

Fixes #85844.
2021-06-23 03:16:04 +00:00
Dylan DPC
6023ac2c8d
Rollup merge of #86521 - the8472:add-footgun-comments, r=RalfJung
Add comments around code where ordering is important due for panic-safety

Iterators contain arbitrary code which may panic. Unsafe code has to be
careful to do its state updates at the right point between calls that may panic.

As requested in https://github.com/rust-lang/rust/pull/86452#discussion_r655153948

r? `@RalfJung`
2021-06-23 00:20:20 +02:00
Taylor Yu
771f35ce84 Some<T> is not a type, etc 2021-06-22 15:35:14 -05:00
The8472
e0d70153cd Add comments around code where ordering is important due for panic-safety
Iterators contain arbitrary code which may panic. Unsafe code has to be
careful to do its state updates at the right point between calls
that may panic.
2021-06-22 19:06:55 +02:00
bors
75ed34223a Auto merge of #84910 - eopb:stabilize_int_error_matching, r=yaahc
stabilize `int_error_matching`

closes #22639

> It has been over half a year since https://github.com/rust-lang/rust/pull/77640#pullrequestreview-511263516, and the indexing question is rejected in https://github.com/rust-lang/rust/pull/79728#pullrequestreview-633030341, so I guess we can submit another stabilization attempt? 😉

_Originally posted by `@kennytm` in https://github.com/rust-lang/rust/issues/22639#issuecomment-831738266_
2021-06-22 09:30:15 +00:00
Ethan Brierley
52a6885c50 postpone stabilizaton by one release 2021-06-22 10:20:56 +01:00
Aris Merchant
20ea5fedea Change Debug unimplemented message per request 2021-06-22 00:38:31 -07:00
bors
2c04f0bb17 Auto merge of #86527 - JohnTitor:rollup-cbu78g4, r=JohnTitor
Rollup of 11 pull requests

Successful merges:

 - #85054 (Revert SGX inline asm syntax)
 - #85182 (Move `available_concurrency` implementation to `sys`)
 - #86037 (Add `io::Cursor::{remaining, remaining_slice, is_empty}`)
 - #86114 (Reopen #79692 (Format symbols under shared frames))
 - #86297 (Allow to pass arguments to rustdoc-gui tool)
 - #86334 (Resolve type aliases to the type they point to in intra-doc links)
 - #86367 (Fix comment about rustc_inherit_overflow_checks in abs().)
 - #86381 (Add regression test for issue #39161)
 - #86387 (Remove `#[allow(unused_lifetimes)]` which is now unnecessary)
 - #86398 (Add regression test for issue #54685)
 - #86493 (Say "this enum variant takes"/"this struct takes" instead of "this function takes")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-06-22 01:14:31 +00:00
Yuki Okushi
8389cd3a1a
Rollup merge of #86367 - m-ou-se:fix-abs-comment, r=scottmcm
Fix comment about rustc_inherit_overflow_checks in abs().
2021-06-22 07:37:51 +09:00
Yuki Okushi
7ee6b8bc43
Rollup merge of #86114 - JDuchniewicz:feat/panic-frame-fmt, r=yaahc
Reopen #79692 (Format symbols under shared frames)

Reopening #79692.
2021-06-22 07:37:47 +09:00
Yuki Okushi
4463b08652
Rollup merge of #86037 - soerenmeier:cursor_remaining, r=yaahc
Add `io::Cursor::{remaining, remaining_slice, is_empty}`

Tracking issue: #86369

I came across an inconvenience when answering the following [Stack Overflow](https://stackoverflow.com/questions/67831170) question.
To get the remaining slice you have to call `buff.fill_buf().unwrap()`. Which in my opinion doesn't really tell you what is returned (in the context of Cursor). To improve readability and convenience when using Cursor i propose adding the method `remaining`.

The next thing i found inconvenient (unnecessary long) was detecting if the cursor reached the end. There are a few ways this can be achieved right now:
- `buff.fill_buf().unwrap().is_empty()`
- `buff.position() >= buff.get_ref().len()`
- `buff.bytes().next().is_none()`

Which all seem a bit unintuitive, hidden in trait documentations or just a bit long for such a simple task.
Therefor i propose another method called `is_empty`, maybe with another name, since this one may leave room for interpretation on what really is empty (the underlying slice, the remaining slice or maybe the position).

Since it seemed easier to create this PR instead of an RFC i did that, if an RFC is wanted, i can close this PR and write an RFC first.
2021-06-22 07:37:46 +09:00
Yuki Okushi
7f1a4a287f
Rollup merge of #85182 - CDirkx:available_concurrency, r=JohnTitor
Move `available_concurrency` implementation to `sys`

This splits out the platform-specific implementation of `available_concurrency` to the corresponding platforms under `sys`. No changes are made to the implementation.

Tidy didn't lint against this code being originally added outside of `sys` because of a bug (see #84677), this PR also reverts the exclusion that was introduced in that bugfix.

Tracking issue of `available_concurrency`: #74479
2021-06-22 07:37:46 +09:00
Yuki Okushi
d6e344d45d
Rollup merge of #85054 - jethrogb:jb/sgx-inline-asm, r=Amanieu
Revert SGX inline asm syntax

This was erroneously changed in #83387
2021-06-22 07:37:42 +09:00
bors
4573a4a879 Auto merge of #86383 - shamatar:slice_len_lowering, r=bjorn3
Add MIR pass to lower call to `core::slice::len` into `Len` operand

During some larger experiment with range analysis I've found that code like `let l = slice.len()` produces different MIR then one found in bound checks. This optimization pass replaces terminators that are calls to `core::slice::len` with just a MIR operand and Goto terminator.

It uses some heuristics to remove the outer borrow that is made to call `core::slice::len`, but I assume it can be eliminated, just didn't find how.

Would like to express my gratitude to `@oli-obk` who helped me a lot on Zullip
2021-06-21 22:24:13 +00:00
Stein Somers
6a5b6450e7 BTree: consistently avoid unwrap_unchecked in iterators 2021-06-21 20:35:49 +02:00
Yuki Okushi
2fdc2eab76
Rollup merge of #86495 - r00ster91:patch-11, r=petrochenkov
Improve `proc_macro::{Punct, Spacing}` documentation

I noticed some misspellings and then thought I could improve it a bit overall.
2021-06-22 00:00:44 +09:00
Christiaan Dirkx
059008f033 Merge sys_common::bytestring into os_str_bytes 2021-06-21 12:57:14 +02:00
Christiaan Dirkx
888418a079 Use Unsupported on platforms where available_concurrency is not implemented. 2021-06-21 11:31:07 +02:00
Christiaan Dirkx
9063edaf3b Move available_concurrency implementation to sys 2021-06-21 11:01:46 +02:00
bors
6a540bd40c Auto merge of #86502 - JohnTitor:rollup-wge0f3x, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #83739 (Account for bad placeholder errors on consts/statics with trait objects)
 - #85637 (document PartialEq, PartialOrd, Ord requirements more explicitly)
 - #86152 (Lazify is_really_default condition in the RustdocGUI bootstrap step)
 - #86156 (Fix a bug in the linkchecker)
 - #86427 (Updated release note)
 - #86452 (fix panic-safety in specialized Zip::next_back)
 - #86484 (Do not set depth to 0 in fully_expand_fragment)
 - #86491 (expand: Move some more derive logic to rustc_builtin_macros)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-06-21 01:16:15 +00:00
Yuki Okushi
504c378159
Rollup merge of #86452 - the8472:fix-zip-drop-safety, r=m-ou-se
fix panic-safety in specialized Zip::next_back

This was unsound since a panic in a.next_back() would result in the
length not being updated which would then lead to the same element
being revisited in the side-effect preserving code.

fixes #86443
2021-06-21 09:42:17 +09:00
Yuki Okushi
e6732e05e4
Rollup merge of #85637 - RalfJung:partial-ord, r=m-ou-se
document PartialEq, PartialOrd, Ord requirements more explicitly

This is the result of discussion in https://github.com/rust-lang/rust/issues/50230, in particular [this summary comment](https://github.com/rust-lang/rust/issues/50230#issuecomment-392819364).

Fixes https://github.com/rust-lang/rust/issues/50230.
2021-06-21 09:42:13 +09:00
bors
03b845a41f Auto merge of #85980 - ssomers:btree_cleanup_LeafRange, r=Mark-Simulacrum
BTree: encapsulate LeafRange better & some debug asserts

Looking at iterators again, I think #81937 didn't house enough code in `LeafRange`. Moving the API boundary a little makes things more local in navigate.rs and less complicated in map.rs.

r? `@Mark-Simulacrum`
2021-06-20 22:52:49 +00:00
Taylor Yu
9a00fd049b add more to result overview 2021-06-20 17:22:03 -05:00
r00ster91
f804d8d71b Improve documentation 2021-06-20 22:19:47 +02:00
bors
dd941450fb Auto merge of #84967 - CDirkx:os_str_ext, r=m-ou-se
Move `OsStringExt` and `OsStrExt` to `std::os`

Moves the `OsStringExt` and `OsStrExt` traits and implementations from `sys_common` to `os`. `sys_common` is for abstractions over `sys` and shouldn't really contain publicly exported items.

This does introduce some duplication: the traits and implementations are now duplicated in `unix`, `wasi`, `hermit`, and `sgx`. However, I would argue that this duplication is no different to how something like `MetadataExt` is duplicated in `linux`, `vxworkx`, `redox`, `solaris` etc. The duplication also matches the fact that the traits on different platforms are technically distinct types: any platform is free to add it's own extra methods to the extension trait.
2021-06-20 16:42:13 +00:00
Ian Jackson
333d42de2c ErrorKind: Add missing full stops
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-20 17:16:24 +01:00
Ian Jackson
f00975ea7d ErrorKind::FilesystemLoop: Generalise dscription
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-20 17:05:18 +01:00
Alex Vlasov
aa53928ed7 Squashed implementation of the pass 2021-06-20 16:09:42 +02:00
The8472
b4734b7c38 disable test on platforms that don't support unwinding 2021-06-20 12:20:05 +02:00
Christiaan Dirkx
ad7b8975e0 Add comment to std::os::unix::ffi::os_str explaining that the module is reused on other platforms. 2021-06-20 12:06:19 +02:00
Christiaan Dirkx
835561ac5b Make os_str_bytes::{Buf, Slice} pub and repr(transparent) 2021-06-20 11:55:26 +02:00
Christiaan Dirkx
1a96d2272e Move OsStringExt and OsStrExt to std::os 2021-06-20 11:55:01 +02:00
bors
192920c22b Auto merge of #86463 - fee1-dead:fixed-encode_wide, r=m-ou-se
Account for self.extra in size_hint for EncodeWide

Fixes #86414.
2021-06-20 02:18:51 +00:00
bors
f639657fe4 Auto merge of #86433 - paolobarbolini:string-overlapping, r=m-ou-se
Use `copy_nonoverlapping` to copy `bytes` in `String::insert_bytes`

The second copy could be made using `ptr::copy_nonoverlapping` instead of `ptr::copy`, since aliasing won't allow `self` and `bytes` to overlap. LLVM even seems to recognize this, [replacing the second `memmove` with a `memcopy`](https://rust.godbolt.org/z/Yoaa6rrGn), so this makes it so it's always applied.
2021-06-19 23:10:55 +00:00
bors
6b354a1382 Auto merge of #86034 - nagisa:nagisa/rt-soundness, r=m-ou-se
Change entry point to 🛡️ against 💥 💥-payloads

Guard against panic payloads panicking within entrypoints, where it is
UB to do so.

Note that there are a number of tradeoffs to consider. For instance, I
considered guarding against accidental panics inside the `rt::init` and
`rt::cleanup` code as well, as it is not all that obvious these may not
panic, but doing so would mean that we initialize certain thread-local
slots unconditionally, which has its own problems.

Fixes #86030
r? `@m-ou-se`
2021-06-19 17:05:08 +00:00
bstrie
16168dd114 Clarify that certain intrinsics are not unsafe 2021-06-19 12:22:39 -04:00
Christiaan Dirkx
a26237e634 Remove Ipv4Addr::is_ietf_protocol_assignment 2021-06-19 15:03:02 +02:00
Simonas Kazlauskas
9c9a0da132 Change entry point to 🛡️ against 💥 💥-payloads
Guard against panic payloads panicking within entrypoints, where it is
UB to do so.

Note that there are a number of implementation approaches to consider.
Some simpler, some more complicated. This particular solution is nice in
that it also guards against accidental implementation issues in
various pieces of runtime code, something we cannot prevent statically
right now.

Fixes #86030
2021-06-19 11:46:56 +03:00
Chris Denton
365a3586a9
Windows: Fix Command::env_clear so it works
Previously, it would error unless at least one new environment variable was added.
2021-06-19 09:46:34 +01:00
bors
39260f6d49 Auto merge of #86426 - hi-rustin:rustin-patch-lint-warn, r=Aaron1011
Lint for unused borrows as part of UNUSED_MUST_USE

close https://github.com/rust-lang/rust/issues/76264

base on https://github.com/rust-lang/rust/pull/76894

r? `@RalfJung`
2021-06-19 08:41:58 +00:00
Deadbeef
15cdb28f5b Account for self.extra in size_hint for EncodeWide 2021-06-19 12:59:22 +08:00
Yuki Okushi
ad79aba2bc
Rollup merge of #86453 - akiselev:patch-1, r=dtolnay
stdlib: Fix typo in internal RefCell docs

`BorroeError` => `BorrowError` in [cell.rs](https://github.com/rust-lang/rust/blob/master/library/core/src/cell.rs#L581)
2021-06-19 10:14:15 +09:00
Yuki Okushi
90e82c950b
Rollup merge of #86397 - Eosis:alter-cell-docs, r=JohnTitor
Alter std::cell::Cell::get_mut documentation

I felt that there was some inconsistency between between Cell and RefCell with regards to their `get_mut` method documentation: `RefCell` flags this method as "unusual" in that it takes `&mut self`, while `Cell` does not. I attempted to flag this in `Cell`s documentation as well, and point to `RefCell`s method in the case where it is required.

Find relevant parts of docs and the new version below.

The current docs for `Cell::get_mut`:
> Returns a mutable reference to the underlying data.
This call borrows Cell mutably (at compile-time) which guarantees that we possess the only reference.

And `RefCell::get_mut`:
> Returns a mutable reference to the underlying data.
 This call borrows `RefCell` mutably (at compile-time) so there is no need for dynamic checks.
However be cautious: this method expects self to be mutable, which is generally not the case when using a `RefCell`. Take a look at the `borrow_mut` method instead if self isn’t mutable.
Also, please be aware that this method is only for special circumstances and is usually not what you want. In case of doubt, use `borrow_mut` instead.

My attempt to make `Cell::get_mut` clearer:
> Returns a mutable reference to the underlying data.
This call borrows `Cell` mutably (at compile-time) which guaranteesthat we possess the only reference.
However be cautious: this method expects `self` to be mutable, which is generally not the case when using a `Cell`. If you require interior mutability by reference, consider using `RefCell` which provides run-time checked mutable borrows through its `borrow_mut` method.
2021-06-19 10:14:10 +09:00
Yuki Okushi
0c7b74fcef
Rollup merge of #86359 - fee1-dead:f64-junit-formatter, r=JohnTitor
Use as_secs_f64 in JunitFormatter

cc `@andoriyu`
2021-06-19 10:14:08 +09:00
Yuki Okushi
aa22799b36
Rollup merge of #86136 - m-ou-se:proc-macro-open-close-span, r=m-ou-se
Stabilize span_open() and span_close().

This proposes to stabilize `Group::span_open()` and `Group::span_close()`.

These are part of the `proc_macro_span` feature gate tracked in https://github.com/rust-lang/rust/issues/54725

Most of the features gated behind `proc_macro_span` are about source location information (file path, line and column information), expansion information (parent()), source_text(), etc. Those are not ready for stabilizaiton. However, getting the span of the `(` and `)` separately instead of only of the entire `(...)` can be very useful in proc macros, and doesn't seem blocked on anything that all the other parts of `proc_macro_span` are blocked on. So, this renames the feature gate for those two functions to `proc_macro_group_span` and stabilizes them.
2021-06-19 10:14:07 +09:00
Alexander Kiselev
c688e70d66
Fixed typo BorroeError => BorrowError in RefCell docs 2021-06-18 17:43:18 -07:00
The8472
8b518542d0 fix panic-safety in specialized Zip::next_back
This was unsound since a panic in a.next_back() would result in the
length not being updated which would then lead to the same element
being revisited in the side-effect preserving code.
2021-06-19 02:20:51 +02:00
bors
ce1d5611a2 Auto merge of #85815 - YuhanLiin:buf-read-data-left, r=m-ou-se
Add has_data_left() to BufRead

This is a continuation of #40747 and also addresses #40745. The problem with the previous PR was that it had "eof" in its method name. This PR uses a more descriptive method name, but I'm open to changing it.
2021-06-18 20:11:51 +00:00
Ian Jackson
c8bddf3bd1 ErrorKind::NotSeekable: Fix reference to File::open()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 19:40:31 +01:00
Ian Jackson
622a45d1b8 ErrorKind: Windows: Fix tidy
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 19:30:55 +01:00
Ian Jackson
58d0cec678 ErrorKind: Windows: Fix botched rebase
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 19:18:10 +01:00
Ian Jackson
1ec9454403 ErrorKind: Provide many more ErrorKinds, motivated by Unix errnos
Rationale for the mappings etc. is extensively discussed in the MR
  https://github.com/rust-lang/rust/pull/79965

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 18:51:53 +01:00
Ian Jackson
655053ed91 Windows error codes: Add two missing ones
For some reason these aren't in the mingw list.

We'll need them shortly.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 18:51:53 +01:00
Ian Jackson
8a4b1e4c0b Windows error codes: Add very very many from mingw
Dump mingw-64's error codes into our source tree.

I have verified with these runes:

  $ f=library/std/src/sys/windows/c/errors.rs
  $ diff -ub <(git-cat-file blob HEAD~:$f | sort) <(cat $f | perl -pe 's/WSABASEERR \+ (\d+)/10000 + $1/e' |sort) |grep ^- |less

that this does not change any existing values.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 18:51:53 +01:00
Ian Jackson
9580f3336b Windows error codes: Move to a separate module
We're going to add many more of these.

This commit is pure code motion, plus the necessary administrivia, as
I have veried with the following runes:

  $ git-diff HEAD~ | grep '^+' |sort >plus
  $ git-diff HEAD~ | grep '^-' | perl -pe 's/^-/+/' |sort >min
  $ diff -ub min plus |less

The output is precisely the expected `mod` and `use` directives.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 18:51:47 +01:00
Ian Jackson
e7fb1a71cd windows errors: Change type name for ERROR_SHARING_VIOLATION
DWORD is a type alias for u32, so this makes no difference.
But this entry is anomalous and in my forthcoming commits I am going
to import many errors wholesale, and I spotted that my wholesale
import didn't match what was here.

CC: Chris Denton <christophersdenton@gmail.com>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 18:51:47 +01:00
Ian Jackson
2a38dfbe04 ErrorKind: Fix a spurious space
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 18:46:50 +01:00
bors
88ba8ad730 Auto merge of #85747 - maxwase:path-symlinks-methods, r=m-ou-se
Path methods — symlinks improvement

This PR adds symlink method for the `Path`.

Tracking issue: #85748
For the discussion you can see [internals topic](https://internals.rust-lang.org/t/path-methods-symlinks-improvement/14776)

P.S.
I'm not fully sure about `stable` attribute, correct me if I'm wrong.
2021-06-18 17:13:19 +00:00
Ian Jackson
d59d52e455 ErrorKind: Reformat the mapping table (windows)
use ErrorKind::*;

I don't feel confident enough about Windows things to reorder this
alphabetically

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 17:53:19 +01:00
Ian Jackson
5513faa512 ErrorKind: Reformat the mapping table (unix)
* Sort the single matches alphabetically.
* use ErrorKind::*;

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 17:45:04 +01:00
Ian Jackson
f092501737 ErrorKind: Reformat the error string table
* Sort alphabetically.
* use ErrorKind::*;

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18 17:43:08 +01:00
Paolo Barbolini
d8530d0fa3 Use copy_nonoverlapping to copy bytes in String::insert_bytes 2021-06-18 15:14:22 +02:00
Max Wase
01435fc83a no_run and ignore doc attributes 2021-06-18 14:17:21 +03:00
hi-rustin
88abd7d81d Lint for unused borrows as part of UNUSED_MUST_USE 2021-06-18 15:09:40 +08:00
YuhanLiin
99939c44c3 Update tracking issue 2021-06-17 23:17:16 -04:00
Mara Bos
a5dce6c99a
Rollup merge of #86357 - de-vri-es:simplify-repeated-cfg-ifs, r=m-ou-se
Rely on libc for correct integer types in os/unix/net/ancillary.rs.

This PR is a small maintainability improvement. It simplifies `unix/net/ancillary.rs` in `std` by removing the `cfg_ifs` for casting to the correct integer type, and just rely on libc to define the struct correctly.
2021-06-17 23:41:00 +02:00
Mara Bos
b7dd942e15
Rollup merge of #86202 - a1phyr:spec_io_bytes_size_hint, r=m-ou-se
Specialize `io::Bytes::size_hint` for more types

Improve the result of `<io::Bytes as Iterator>::size_hint` for some readers. I did not manage to specialize `SizeHint` for `io::Cursor`

Side question: would it be interesting for `io::Read` to have an optional `size_hint` method ?
2021-06-17 23:40:58 +02:00
Mara Bos
fcac478966
Rollup merge of #85925 - clarfonthey:lerp, r=m-ou-se
Linear interpolation

#71016 is a previous attempt at implementation that was closed by the author. I decided to reuse the feature request issue (#71015) as a tracking issue. A member of the rust-lang org will have to edit the original post to be formatted correctly as I am not the issue's original author.

The common name `lerp` is used because it is the term used by most code in a wide variety of contexts; it also happens to be the recently chosen name of the function that was added to C++20.

To ensure symmetry as a method, this breaks the usual ordering of the method from `lerp(a, b, t)` to `t.lerp(a, b)`. This makes the most sense to me personally, and there will definitely be discussion before stabilisation anyway.

Implementing lerp "correctly" is very dififcult even though it's a very common building-block used in all sorts of applications. A good prior reading is [this proposal](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0811r2.html#linear-interpolation) for the C++20 lerp which talks about the various guarantees, which I've simplified down to:

1. Exactness: `(0.0).lerp(start, end) == start` and `(1.0).lerp(start, end) == end`
2. Consistency: `anything.lerp(x, x) == x`
3. Monotonicity: once you go up don't go down

Fun story: the version provided in that proposal, from what I understand, isn't actually monotonic.

I messed around with a *lot* of different lerp implementations because I kind of got a bit obsessed and I ultimately landed on one that uses the fused `mul_add` instruction. Floating-point lerp lore is hard to come by, so, just trust me when I say that this ticks all the boxes. I'm only 90% certain that it's monotonic, but I'm sure that people who care deeply about this will be there to discuss before stabilisation.

The main reason for using `mul_add` is that, in general, it ticks more boxes with fewer branches to be "correct." Although it will be slower on architectures without the fused `mul_add`, that's becoming more and more rare and I have a feeling that most people who will find themselves needing `lerp` will also have an efficient `mul_add` instruction available.
2021-06-17 23:40:57 +02:00
Karl Meakin
8eb0c0df0e Document associativity of iterator folds.
Document the associativity of `Iterator::fold` and
`DoubleEndedIterator::rfold` and add examples demonstrating this.
Add links to direct users to the fold of the opposite associativity.
2021-06-17 20:42:48 +01:00
Maarten de Vries
259bf5f47a Rely on libc for correct integer types in os/unix/net/ancillary.rs. 2021-06-17 15:56:47 +02:00
Yuki Okushi
65d412b637
Rollup merge of #86389 - kpreid:sum, r=scottmcm
Make `sum()` and `product()` documentation hyperlinks refer to `Iterator` methods.

The previous linking seemed confusing: within "the sum() method on iterators", "sum()" was linked to `Sum::sum`, not `Iterator::sum`, even though the sentence is talking about the latter. I have rewritten the sentence to be, I believe, clearer, as well as changing the link destinations; applying the same change to the `Product` documentation as well as `Sum`.

I reviewed other traits in the same module and did not see similar issues, and previewed the results using `./x.py doc library/std`.
2021-06-17 21:56:46 +09:00
Yuki Okushi
9521da7179
Rollup merge of #85970 - jsha:remove-methods-implementors, r=GuillaumeGomez
Remove methods under Implementors on trait pages

As discussed at https://github.com/rust-lang/rust/issues/84326#issuecomment-842652412.

On a trait page, the "Implementors" section currently lists all methods of each implementor. That duplicates the method definitions on the trait itself, and is usually not very useful. So the implementors are collapsed by default. This PR changes rustdoc to just not render them at all. Any documentation specific to an implementor can be found by clicking through to the implementor's page.

This moves the "portability" info inside the `<summary>` tags so it is still visible on trait pages (as originally implemented in #79201). That also means it will be visible on struct/enum pages when methods are collapsed.

Add `#[doc(hidden)]` to all implementations of `Iterator::__iterator_get_unchecked` that didn't already have it. Otherwise, due to #86145, the structs/enums with those implementations would generate documentation for them, and that documentation would have a broken link into the Iterator page. Those links were already "broken" but not detected by the link-checker, because they pointed to one of the Implementors on the Iterator page, which happened to have the right anchor name.

This reduces the Read trait's page size from 128kB to 68kB (uncompressed) and from 12,125 bytes to 9,989 bytes (gzipped
Demo:

https://hoffman-andrews.com/rust/remove-methods-implementors/std/string/struct.String.html#trait-implementations
https://hoffman-andrews.com/rust/remove-methods-implementors/std/io/trait.Read.html#implementors

r? `@GuillaumeGomez`
2021-06-17 21:56:42 +09:00
Yuki Okushi
31ee68067e
Rollup merge of #85802 - Thomasdezeeuw:ioslice-advance, r=m-ou-se
Rename IoSlice(Mut)::advance to advance_slice and add IoSlice(Mut)::advance

Also changes the signature of `advance_slice` to accept a `&mut &mut [IoSlice]`, not returning anything. This will better match the `IoSlice::advance` function.

Updates https://github.com/rust-lang/rust/issues/62726.
2021-06-17 21:56:41 +09:00
Yuki Okushi
36b9a6ee73
Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-se
Document Arc::from
2021-06-17 21:56:39 +09:00
Mara Bos
5e7a8c6eb1
Fix typos in code examples. 2021-06-17 12:13:06 +02:00
Rupert Rutledge
7cadf7bc01 Alter std::cell::Cell::get_mut documentation
I find this more consistent with RefCell's equivalent method.
2021-06-17 11:02:16 +01:00
Mara Bos
13bfbb4253 Fix comment about rustc_inherit_overflow_checks in abs(). 2021-06-17 10:02:08 +00:00
Chris Denton
a200c01e4f
Document how Windows compares environment variables 2021-06-17 07:15:33 +01:00
Jacob Hoffman-Andrews
910c7fa767 Add doc(hidden) to all __iterator_get_unchecked
This method on the Iterator trait is doc(hidden), and about half of
implementations were doc(hidden). This adds the attribute to the
remaining implementations.
2021-06-16 22:08:44 -07:00
Kevin Reid
cb2f8d9b02 Make sum() and product() hyperlinks refer to Iterator methods.
The previous linking seemed confusing: within "the sum() method on
iterators", "sum()" was linked to `Sum::sum`, not `Iterator::sum`, even
though the sentence is talking about the latter.

I have rewritten the sentence to be, I believe, clearer, as well as
changing the link destinations; applying the same change to the
`Product` documentation as well as `Sum`.
2021-06-16 17:52:33 -07:00
Sören Meier
664bde0770 rename remaining to remaining_slice and add a new remaining 2021-06-17 02:14:53 +02:00
Yuki Okushi
27d5426bcf
Rollup merge of #86372 - snoyberg:patch-1, r=jonas-schievink
Typo correction: s/is/its
2021-06-17 05:55:02 +09:00
Yuki Okushi
0d14acad7e
Rollup merge of #86141 - amorison:link-ref-in-doc-dyn-keyword, r=kennytm
Link reference in `dyn` keyword documentation

The "read more" sentence formatted "object safety" as inline code
instead of providing a link to more information.  This PR adds a link
to the Reference about this matter, as well as the page regarding trait
objects.

---

We could also put these links in the very first line (instead of the link to the
Book) and in the first paragraph which mentions the "object safe" requirement.
Personally, I think it's good to keep the link to the Book up-front as it's more
accessible than the Reference.
2021-06-17 05:54:55 +09:00
Yuki Okushi
b1fb32d165
Rollup merge of #86140 - scottmcm:array-hash-facepalm, r=kennytm
Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`

To remind people like me who forget about it and send PRs to make them different, and to (probably) get a test failure if the code is changed to no longer uphold it.
2021-06-17 05:54:54 +09:00
Deadbeef
e4b3131584
Use as_secs_f64 in JunitFormatter 2021-06-17 03:23:17 +08:00
Michael Snoyman
770e8cc01e
Typo correction: s/is/its 2021-06-16 19:20:15 +03:00
Sören Meier
212e91a356
Update tracking issue 2021-06-16 17:25:47 +02:00
bors
9fef8d91b4 Auto merge of #86179 - the8472:revere-path-cmp, r=kennytm
optimize Eq implementation for paths

Filesystems generally have a tree-ish structure which means paths are more likely to share a prefix than a suffix. Absolute paths are especially prone to share long prefixes.

quick benchmark consisting of a search through through a vec containing the absolute paths of all (1850) files in `compiler/`:

```
# old
test path::tests::bench_path_cmp                                  ... bench:     227,407 ns/iter (+/- 2,162)

# new
test path::tests::bench_path_cmp                                  ... bench:      64,976 ns/iter (+/- 1,142)
```
2021-06-16 15:18:19 +00:00
Aris Merchant
f1f1c9b25b Improve errors for missing Debug and Display impls 2021-06-16 01:13:28 -07:00
Yuki Okushi
d476707a1f
Rollup merge of #86209 - tlyu:option-doc-typos, r=JohnTitor
fix minor wording/typo issues in core::option docs

These are just minor wording or typo things I came across while making other edits.
2021-06-16 13:31:07 +09:00
Yuki Okushi
7ceb706e9d
Rollup merge of #86200 - qwerty01:clone-doc-update, r=JohnTitor
Updates `Clone` docs for `Copy` comparison.

Quite a few people (myself included) have come under the impression that the difference between `Copy` and `Clone` is that `Copy` is cheap and `Clone` is expensive, where the actual difference is that `Copy` constrains the type to bit-wise copying, and `Clone` allows for more expensive operations. The source of this misconception is in the `Clone` docs, where the following line is in the description:

> Differs from `Copy` in that `Copy` is implicit and extremely inexpensive, while `Clone` is always explicit and may or may not be expensive.

The `Clone` documentation page also comes up before the `Copy` page on google when searching for "the difference between `Clone` and `Copy`".

This PR updates the documentation to clarify that "extremely inexpensive" means an "inexpensive bit-wise copy" to hopefully prevent future rust users from falling into this misunderstanding.
2021-06-16 13:31:06 +09:00
bors
d192c80d22 Auto merge of #85820 - CDirkx:is_unicast_site_local, r=joshtriplett
Remove `Ipv6Addr::is_unicast_site_local`

Removes the unstable method `Ipv6Addr::is_unicast_site_local`, see also #85604 where I have tried to summarize related discussion so far.

Unicast site-local addresses (`fec0::/10`) were deprecated in [IETF RFC #3879](https://datatracker.ietf.org/doc/html/rfc3879), see also [RFC #4291 Section 2.5.7](https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.7). Any new implementation must no longer support the special behaviour of site-local addresses. This is mentioned in the docs of `is_unicast_site_local` and already implemented in `is_unicast_global`, which considers addresses in `fec0::/10` to have global scope, thus overlapping with `is_unicast_site_local`.

Given that RFC #3879 was published in 2004, long before Rust existed, and it is specified that any new implementation must no longer support the special behaviour of site-local addresses, I don't see how a user would ever have a need for `is_unicast_site_local`. It is also confusing that currently both `is_unicast_site_local` and `is_unicast_global` can be `true` for an address, but an address can actually only have a single scope. The deprecating RFC mentions that Site-Local scope was confusing to work with and that the classification of an address as either Link-Local or Global better matches the mental model of users.

There has been earlier discussion of removing `is_unicast_site_local` (https://github.com/rust-lang/rust/pull/60145#issuecomment-485970669) which decided against it, but that had the incorrect assumption that the method was already stable; it is not. (This confusion arose from the placement of the unstable attribute on the entire module, instead of on individual methods, resolved in #85672)

r? `@joshtriplett` as reviewer of all the related PRs
2021-06-16 01:46:08 +00:00
Jon Gjengset
b5e5a182ca
Update library/core/src/pin.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-06-15 20:47:43 -04:00
est31
1c8033f77f Split MaybeUninit::write into new feature gate and stabilize it 2021-06-16 02:47:05 +02:00
bors
684ca335d5 Auto merge of #85406 - VillSnow:integrate_binary_search, r=JohnTitor
Integrate binary search codes of binary_search_by and partition_point

For now partition_point has own binary search code piece.
It is because binary_search_by had called the comparer more times and the author (=me) wanted to avoid it.

However, now binary_search_by uses the comparer minimum times. (#74024)
So it's time to integrate them.

The appearance of the codes are a bit different but both use completely same logic.
2021-06-15 22:56:41 +00:00
Christiaan Dirkx
1f2480b9d4 Document IPv4-mapped and IPv4-compatible addresses. 2021-06-15 20:10:25 +02:00
Mara Bos
a0d11a4fab Rename ErrorKind::Unknown to Uncategorized. 2021-06-15 14:30:13 +02:00
Mara Bos
82d3ef199f Fix copy-paste error in sys/hermit error message. 2021-06-15 14:22:56 +02:00
Mara Bos
0b37bb2bc2 Redefine ErrorKind::Other and stop using it in std. 2021-06-15 14:22:49 +02:00
Yuki Okushi
74cc63a7a5
Rollup merge of #86314 - Veykril:patch-2, r=JohnTitor
Remove trailing triple backticks in `mut_keyword` docs
2021-06-15 17:40:17 +09:00
Yuki Okushi
891ceab0ea
Rollup merge of #86294 - m-ou-se:edition-prelude-modules, r=joshtriplett
Stabilize {std, core}::prelude::rust_*.

This stabilizes the `{core, std}::prelude::{rust_2015, rust_2018, rust_2021}` modules.

The usage of these modules as the prelude in those editions was already stabilized. This just stabilizes the modules themselves, making it possible for a user to explicitly refer to them.

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

FCP on the RFC that included this finished here: https://github.com/rust-lang/rfcs/pull/3114#issuecomment-840577395
2021-06-15 17:40:14 +09:00
Yuki Okushi
e84ee522a9
Rollup merge of #86220 - est31:maybe-uninit-extra, r=RalfJung
Improve maybe_uninit_extra docs

For reasoning, see https://github.com/rust-lang/rust/issues/63567#issuecomment-858640987
2021-06-15 17:40:10 +09:00
Yuki Okushi
3f4d6d73a9
Rollup merge of #85792 - mjptree:refactor-windows-sockets, r=JohnTitor
Refactor windows sockets impl methods

No behavioural changes, but a bit tidier visual flow.
2021-06-15 17:40:09 +09:00
Yuki Okushi
5936ecc24f
Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-se
Stabilize `ops::ControlFlow` (just the type)

Tracking issue: https://github.com/rust-lang/rust/issues/75744 (which also tracks items *not* closed by this PR).

With the new `?` desugar implemented, [it's no longer possible to mix `Result` and `ControlFlow`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=13feec97f5c96a9d791d97f7de2d49a6).  (At the time of making this PR, godbolt was still on the 2021-05-01 nightly, where you can see that [the mixing example compiled](https://rust.godbolt.org/z/13Ke54j16).)  That resolves the only blocker I know of, so I'd like to propose that `ControlFlow` be considered for stabilization.

Its basic existence was part of https://github.com/rust-lang/rfcs/pull/3058, where it got a bunch of positive comments (examples [1](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-758277325) [2](https://github.com/rust-lang/rfcs/pull/3058#pullrequestreview-592106494) [3](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-784444155) [4](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-797031584)).  Its use in the compiler has been well received (https://github.com/rust-lang/rust/pull/78182#issuecomment-713695594), and there are ecosystem updates interested in using it (https://github.com/rust-itertools/itertools/issues/469#issuecomment-677729589, https://github.com/jonhoo/rust-imap/issues/194).

As this will need an FCP, picking a libs member manually:
r? `@m-ou-se`

## Stabilized APIs

```rust
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ControlFlow<B, C = ()> {
    /// Exit the operation without running subsequent phases.
    Break(B),
    /// Move on to the next phase of the operation as normal.
    Continue(C),
}
```

As well as using `?` on a `ControlFlow<B, _>` in a function returning `ControlFlow<B, _>`.  (Note, in particular, that there's no `From::from`-conversion on the `Break` value, the way there is for `Err`s.)

## Existing APIs *not* stabilized here

All the associated methods and constants: `break_value`, `is_continue`, `map_break`, [`CONTINUE`](https://doc.rust-lang.org/nightly/std/ops/enum.ControlFlow.html#associatedconstant.CONTINUE), etc.

Some of the existing methods in nightly seem reasonable, some seem like they should be removed, and some need more discussion to decide.  But none of them are *essential*, so [as in the RFC](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#methods-on-controlflow), they're all omitted from this PR.

They can be considered separately later, as further usage demonstrates which are important.
2021-06-15 17:40:08 +09:00
Yuki Okushi
1e14d397db
Rollup merge of #82179 - mbartlett21:patch-5, r=joshtriplett
Add functions `Duration::try_from_secs_{f32, f64}`

These functions allow constructing a Duration from a floating point value that could be out of range without panicking.

Tracking issue: #83400
2021-06-15 17:40:03 +09:00
Yuki Okushi
2d2f1a5e88
Rollup merge of #80269 - pickfire:patch-4, r=joshtriplett
Explain non-dropped sender recv in docs

Original senders that are still hanging around could cause
Receiver::recv to not block since this is a potential footgun
for beginners, clarify more on this in the docs for readers to
be aware about it.

Maybe it would be better to show an example of the pattern where `drop(tx)` is used when it is being cloned multiple times? Although I have seen it in quite a few articles but I am surprised that this part is not very clear with the current words without careful reading.

> If the corresponding Sender has disconnected, or it disconnects while this call is blocking, this call will wake up and return Err to indicate that no more messages can ever be received on this channel. However, since channels are buffered, messages sent before the disconnect will still be properly received.

Some words there may seemed similar if I carefully read and relate it but if I am new, I probably does not know "drop" makes it "disconnected". So I mention the words "drop" and "alive" to make it more relatable to lifetime.
2021-06-15 17:39:58 +09:00
Ralf Jung
45675f3d95
wording
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2021-06-15 10:20:08 +02:00
Taylor Yu
1b58d93bb2 add boolean operator example 2021-06-14 21:42:34 -05:00
Lukas Wirth
7cd750f16f
Update keyword_docs.rs 2021-06-15 00:22:03 +02:00
Scott McMurray
590d4526e9 Master is 1.55 now :( 2021-06-14 10:37:05 -07:00
Mara Bos
65c1d35973 Stabilize {std, core}::prelude::rust_*. 2021-06-14 14:44:50 +00:00
bors
a216131c35 Auto merge of #86273 - JohnTitor:stabilize-maybe-uninit-ref, r=RalfJung
Stabilize `maybe_uninit_ref`

This stabilizes `assume_init_{ref,mut}`. FCP is complete: https://github.com/rust-lang/rust/issues/63568#issuecomment-590121300
The renaming was done by #76047 and FIXME was resolved by #76241, so I think we can now stabilize them finally 🎉
Still, it's const-unstable as `assert_inhabited` is unstable.

Closes #63568
2021-06-14 13:05:54 +00:00
mbartlett21
7803955cae Use try_from_secs_* in Duration::from_secs_* functions.
`Duration::from_secs_{f32, f64}` now use the results from the
non-panicking functions and unwrap it.
2021-06-14 12:17:53 +00:00
mbartlett21
c2c1ca071f Add functions Duration::try_from_secs_{f32, f64}
This also adds the error type used, `FromSecsError` and its `impl`s.
2021-06-14 12:16:13 +00:00
est31
8710258714 Improve maybe_uninit_extra docs
For reasoning, see https://github.com/rust-lang/rust/issues/63567#issuecomment-858640987
2021-06-14 13:30:58 +02:00
bors
7510b0ca45 Auto merge of #85758 - petertodd:2021-revert-manuallydrop-clone-from, r=m-ou-se
Revert #85176 addition of `clone_from` for `ManuallyDrop`

Forwarding `clone_from` to the inner value changes the observable behavior, as previously the inner value would *not* be dropped by the default implementation.

Frankly, this is a super-niche case, so #85176 is welcome to argue the behavior should be otherwise! But if we overrride it, IMO documenting the behavior would be good.

Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c5d0856686fa850c1d7ee16891014efb
2021-06-14 10:24:48 +00:00
Ethan Brierley
85b06e9c01 run tidy 2021-06-14 09:58:41 +01:00
Ethan Brierley
b59f7d9662 stabilize int_error_matching 2021-06-14 09:58:32 +01:00
Yuki Okushi
7fa1308db1
Stabilize maybe_uninit_ref 2021-06-14 05:08:03 +09:00
ltdk
525d76026f Change tracking issue 2021-06-13 14:04:43 -04:00
ltdk
d8e247e38c More lerp tests, altering lerp docs 2021-06-13 14:00:15 -04:00
bors
a75e74df89 Auto merge of #86233 - JohnTitor:stabilize-simd-x86-bittest, r=Amanieu
Stabilize `simd_x86_bittest` feature

This pulls https://github.com/rust-lang/stdarch/pull/1180, FCP is complete: https://github.com/rust-lang/rust/issues/59414#issuecomment-826072554
Closes #59414
2021-06-13 01:27:37 +00:00
Taylor Yu
834f4b770e updates based on feedback
Make minor wording changes in a few places. Move `filter` to the
"transformations" section. Add `zip` methods to the "transformations"
section. Clarify the section about `Option` iterators, and add a section
about collecting into `Option`.

Clarify that for `Result`, `or` and `or_else` can also produce a
`Result` having a different type.
2021-06-12 16:33:13 -05:00
Yuki Okushi
b8b559cfcb Update stdarch submodule to stabilize simd_x86_bittest feature 2021-06-13 02:29:17 +09:00
bors
da7ada584a Auto merge of #82703 - iago-lito:nonzero_add_mul_pow, r=m-ou-se
Implement nonzero arithmetics for NonZero types.

Hello'all, this is my first PR to this repo.

Non-zero natural numbers are stable by addition/multiplication/exponentiation, so it makes sense to make this arithmetic possible with `NonZeroU*`.

The major pitfall is that overflowing underlying `u*` types possibly lead to underlying `0` values, which break the major invariant of `NonZeroU*`. To accommodate it, only `checked_` and `saturating_` operations are implemented.

Other variants allowing wrapped results like `wrapping_` or `overflowing_` are ruled out *de facto*.

`impl Add<u*> for NonZeroU* { .. }` was considered, as it panics on overflow which enforces the invariant, but it does not so in release mode. I considered forcing `NonZeroU*::add` to panic in release mode by deferring the check to `u*::checked_add`, but this is less explicit for the user than directly using `NonZeroU*::checked_add`.
Following `@Lokathor's` advice on zulip, I have dropped the idea.

`@poliorcetics` on Discord also suggested implementing `_sub` operations, but I'd postpone this to another PR if there is a need for it. My opinion is that it could be useful in some cases, but that it makes less sense because non-null natural numbers are not stable by subtraction even in theory, while the overflowing problem is just about technical implementation.

One thing I don't like is that the type of the `other` arg differs in every implementation: `_add` methods accept any raw positive integer, `_mul` methods only accept non-zero values otherwise the invariant is also broken, and `_pow` only seems to accept `u32` for a reason I ignore but that seems consistent throughout `std`. Maybe there is a better way to harmonize this?

This is it, Iope I haven't forgotten anything and I'll be happy to read your feedback.
2021-06-12 15:29:51 +00:00
Iago-lito
7afdaf2c06 Stop relying on #[feature(try_trait)] in doctests. 2021-06-12 10:58:37 +02:00
Ivan Tham
0f3c7d18fb Explain non-dropped sender recv in docs
Original senders that are still hanging around could cause
Receiver::recv to not block since this is a potential footgun
for beginners, clarify more on this in the docs for readers to
be aware about it.

Fix minor tidbits in sender recv doc

Co-authored-by: Dylan DPC <dylan.dpc@gmail.com>

Add example for unbounded receive loops in doc

Show the drop(tx) pattern, based on tokio docs
https://tokio-rs.github.io/tokio/doc/tokio/sync/index.html

Fix example code for drop sender recv

Fix wording in sender docs

Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-06-12 14:56:46 +08:00
Taylor Yu
7265bef2e7 add modify-in-place methods to option overview 2021-06-11 13:10:29 -05:00
Taylor Yu
370f731dfb more transformation methods in option overview 2021-06-11 12:47:37 -05:00
Taylor Yu
7edc66661f updates based on reviews
Fix an error in `map_or_else`. Use more descriptive text for
"don't care" in truth tables. Make minor corrections to truth tables.
Rename `makeiter` to `make_iter` in examples.
2021-06-11 11:34:57 -05:00
Deadbeef
8f78660c82 Remove "generic type" in boxed.rs 2021-06-12 04:11:48 +08:00
Jacob Pratt
fe7487a79e
Stabilize str::from_utf8_unchecked as const 2021-06-11 01:55:47 -04:00
bors
68aa6b2d83 Auto merge of #86204 - alexcrichton:wasm-simd-stable, r=Amanieu
std: Stabilize wasm simd intrinsics

This commit performs two changes to stabilize Rust support for
WebAssembly simd intrinsics:

* The stdarch submodule is updated to pull in rust-lang/stdarch#1179.
* The `wasm_target_feature` feature gate requirement for the `simd128`
  feature has been removed, stabilizing the name `simd128`.

This should conclude the FCP started on #74372 and...

Closes #74372
2021-06-11 05:02:41 +00:00
Taylor Yu
4763377a96 fix typo in option doc
Fix a typo/missed replacement in the documentation for
`impl From<&Option<T>> for Option<&T>` in `core::option`.
2021-06-10 22:30:00 -05:00
Taylor Yu
d54d59b182 method overviews for option and result 2021-06-10 22:30:00 -05:00
Taylor Yu
cb65b48c06 fix wording in option doc
Fix some awkward wording in the `core::option` documentation in the
"Options and pointers" section.
2021-06-10 22:30:00 -05:00
Alex Crichton
e05bb26d9f std: Stabilize wasm simd intrinsics
This commit performs two changes to stabilize Rust support for
WebAssembly simd intrinsics:

* The stdarch submodule is updated to pull in rust-lang/stdarch#1179.
* The `wasm_target_feature` feature gate requirement for the `simd128`
  feature has been removed, stabilizing the name `simd128`.

This should conclude the FCP started on #74372 and...

Closes #74372
2021-06-10 19:42:05 -07:00
bors
46ad16b70f Auto merge of #85630 - gilescope:to_digit_speedup3, r=nagisa
to_digit simplification (less jumps)

I just realised we might be able to make use of the fact that changing case in ascii is easy to help simplify to_digit some more.

It looks a bit cleaner and it looks like it's less jumps and there's less instructions in the generated assembly:

https://godbolt.org/z/84Erh5dhz

The benchmarks don't really tell me much. Maybe a slight improvement on the var radix.

Before:
```
test char::methods::bench_to_digit_radix_10                     ... bench:      53,819 ns/iter (+/- 8,314)
test char::methods::bench_to_digit_radix_16                     ... bench:      57,265 ns/iter (+/- 10,730)
test char::methods::bench_to_digit_radix_2                      ... bench:      55,077 ns/iter (+/- 5,431)
test char::methods::bench_to_digit_radix_36                     ... bench:      56,549 ns/iter (+/- 3,248)
test char::methods::bench_to_digit_radix_var                    ... bench:      43,848 ns/iter (+/- 3,189)

test char::methods::bench_to_digit_radix_10                     ... bench:      51,707 ns/iter (+/- 10,946)
test char::methods::bench_to_digit_radix_16                     ... bench:      52,835 ns/iter (+/- 2,689)
test char::methods::bench_to_digit_radix_2                      ... bench:      51,012 ns/iter (+/- 2,746)
test char::methods::bench_to_digit_radix_36                     ... bench:      53,210 ns/iter (+/- 8,645)
test char::methods::bench_to_digit_radix_var                    ... bench:      40,386 ns/iter (+/- 4,711)

test char::methods::bench_to_digit_radix_10                     ... bench:      54,088 ns/iter (+/- 5,677)
test char::methods::bench_to_digit_radix_16                     ... bench:      55,972 ns/iter (+/- 17,229)
test char::methods::bench_to_digit_radix_2                      ... bench:      52,083 ns/iter (+/- 2,425)
test char::methods::bench_to_digit_radix_36                     ... bench:      54,132 ns/iter (+/- 1,548)
test char::methods::bench_to_digit_radix_var                    ... bench:      41,250 ns/iter (+/- 5,299)
```
After:
```
test char::methods::bench_to_digit_radix_10                     ... bench:      48,907 ns/iter (+/- 19,449)
test char::methods::bench_to_digit_radix_16                     ... bench:      52,673 ns/iter (+/- 8,122)
test char::methods::bench_to_digit_radix_2                      ... bench:      48,509 ns/iter (+/- 2,885)
test char::methods::bench_to_digit_radix_36                     ... bench:      50,526 ns/iter (+/- 4,610)
test char::methods::bench_to_digit_radix_var                    ... bench:      38,618 ns/iter (+/- 3,180)

test char::methods::bench_to_digit_radix_10                     ... bench:      54,202 ns/iter (+/- 6,994)
test char::methods::bench_to_digit_radix_16                     ... bench:      56,585 ns/iter (+/- 8,448)
test char::methods::bench_to_digit_radix_2                      ... bench:      50,548 ns/iter (+/- 1,674)
test char::methods::bench_to_digit_radix_36                     ... bench:      52,749 ns/iter (+/- 2,576)
test char::methods::bench_to_digit_radix_var                    ... bench:      40,215 ns/iter (+/- 3,327)

test char::methods::bench_to_digit_radix_10                     ... bench:      50,233 ns/iter (+/- 22,272)
test char::methods::bench_to_digit_radix_16                     ... bench:      50,841 ns/iter (+/- 19,981)
test char::methods::bench_to_digit_radix_2                      ... bench:      50,386 ns/iter (+/- 4,555)
test char::methods::bench_to_digit_radix_36                     ... bench:      52,369 ns/iter (+/- 2,737)
test char::methods::bench_to_digit_radix_var                    ... bench:      40,417 ns/iter (+/- 2,766)
```

I removed the likely as it resulted in a few less instructions. (It's not been in there long - I added it in the last to_digit iteration).
2021-06-10 23:14:11 +00:00
Giles Cope
9c3d81e186
Further simplification of to_digit 2021-06-10 20:16:35 +01:00
Benoît du Garreau
2cbd5d1df5 Specialize io::Bytes::size_hint for more types 2021-06-10 19:16:55 +02:00
qwerty01
2788c71dd4 Updates Clone docs for Copy comparison. 2021-06-10 11:28:26 -04:00
Yuki Okushi
6a292ebdcf
Rollup merge of #86111 - spookyvision:master, r=JohnTitor
fix off by one in `std::iter::Iterator` documentation

the range `(0..10)` is documented as "The even numbers from zero to ten." - should be ".. to nine".
2021-06-10 11:02:14 +09:00
Yuki Okushi
ceed619194
Rollup merge of #86051 - erer1243:update_move_keyword_docs, r=Mark-Simulacrum
Updated code examples and wording in move keyword documentation

Had a conversation with someone on the Rust Discord who was confused by the move keyword documentation. Some of the wording is odd sounding ("owned by value" - what else can something be owned by?). Also, some of the examples used Copy types when demonstrating move, leading to variables still being accessible in the outer scope after the move, contradicting the examples' comments.

I changed the move keyword documentation a bit, removing that odd wording and changing all the examples to use non-Copy types
2021-06-10 11:02:13 +09:00
Yuki Okushi
578eb6d65f
Rollup merge of #84687 - a1phyr:improve_rwlock, r=m-ou-se
Multiple improvements to RwLocks

This PR replicates #77147, #77380 and #84650 on RWLocks :
- Split `sys_common::RWLock` in `StaticRWLock` and `MovableRWLock`
- Unbox rwlocks on some platforms (Windows, Wasm and unsupported)
- Simplify `RwLock::into_inner`

Notes to reviewers :
- For each target, I copied `MovableMutex` to guess if `MovableRWLock` should be boxed.
- ~A comment says that `StaticMutex` is not re-entrant, I don't understand why and I don't know whether it applies to `StaticRWLock`.~

r? `@m-ou-se`
2021-06-10 11:02:10 +09:00
The8472
53d71c181e optimize Eq implementation for paths
Filesystems generally have a tree-ish structure which means
paths are more likely to share a prefix than a suffix. Absolute paths
are especially prone to share long prefixes.
2021-06-09 23:11:07 +02:00
bors
eab201df70 Auto merge of #86003 - pnkfelix:issue-84297-revert-81238, r=Mark-Simulacrum
Make copy/copy_nonoverlapping fn's again

Make copy/copy_nonoverlapping fn's again, rather than intrinsics.

This a short-term change to address issue #84297.

It effectively reverts PRs #81167 #81238 (and part of #82967), #83091, and parts of #79684.
2021-06-09 16:47:05 +00:00
Iago-lito
d442c104ea Fix diverging doc regarding signedness. 2021-06-09 17:28:34 +02:00
Iago-lito
3c168b0dc6 Explicit what check means on concerned method. 2021-06-09 17:28:34 +02:00
Iago-lito
b8056d8e29 NonZero saturating_pow. 2021-06-09 17:28:34 +02:00
Iago-lito
7b37800b45 NonZero checked_pow. 2021-06-09 17:28:34 +02:00
Iago-lito
6979bb40f8 NonZero unchecked_mul. 2021-06-09 17:28:33 +02:00
Iago-lito
7e0b9a8bd0 NonZero saturating_mul. 2021-06-09 17:28:33 +02:00
Iago-lito
ac3eb90d59 NonZero checked_mul. 2021-06-09 17:28:33 +02:00
Iago-lito
7e7b316163 NonZero unsigned_abs. 2021-06-09 17:28:33 +02:00
Iago-lito
b6589bbfa9 NonZero wrapping_abs. 2021-06-09 17:28:32 +02:00
Iago-lito
65e7321457 NonZero saturating_abs. 2021-06-09 17:28:32 +02:00
Iago-lito
6083b0ad2a NonZero overflowing_abs. 2021-06-09 17:28:32 +02:00
Iago-lito
62f97d950f NonZero checked_abs. 2021-06-09 17:28:31 +02:00