Commit graph

4789 commits

Author SHA1 Message Date
Flying-Toast 9a2e3f3a8e Recommend swap_remove in Vec::remove docs 2021-07-30 16:01:49 -04:00
Yuki Okushi 84e18828d4
Rollup merge of #87602 - wesleywiser:partially_fix_short_backtraces_windows_optimized, r=dtolnay
[backtraces]: look for the `begin` symbol only after seeing `end`

On `x86_64-pc-windows-msvc`, we often get backtraces which look like
    this:

    ```
    10:     0x7ff77e0e9be5 - std::panicking::rust_panic_with_hook
    11:     0x7ff77e0e11b4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c
    12:     0x7ff77e0e116f - std::sys_common::backtrace::__rust_end_short_backtrace::h61c7ecb1b55338ae
    13:     0x7ff77e0f89dd - std::panicking::begin_panic::h8e60ef9f82a41805
    14:     0x7ff77e0e108c - d
    15:     0x7ff77e0e1069 - c
    16:     0x7ff77e0e1059 - b
    17:     0x7ff77e0e1049 - a
    18:     0x7ff77e0e1039 - core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>::h1bfcd14d5e15ba81
    19:     0x7ff77e0e1186 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c
    20:     0x7ff77e0e100c - std::rt::lang_start::{{closure}}::ha054184bbf9921e3
    ```

Notice that `__rust_begin_short_backtrace` appears on frame 11 before
    `__rust_end_short_backtrace` on frame 12. This is because in typical
    release binaries without debug symbols, dbghelp.dll, which we use to walk
    and symbolize the stack, does not know where CGU internal functions
    start or end and so the closure invoked by `__rust_end_short_backtrace`
    is incorrectly described as `__rust_begin_short_backtrace` because it
    happens to be near that symbol.

While that can obviously change, this has been happening quite
    consistently since #75048. Since this is a very small change to the std
    and the change makes sense by itself, I think this is worth doing.

This doesn't completely resolve the situation for release binaries on
    Windows, since without debug symbols, the stack printed can still show
    incorrect symbol names (this is why the test uses `#[no_mangle]`) but it
    does slightly improve the situation in that you see the same backtrace
    you would see with `RUST_BACKTRACE=full` or in a debugger (without the
    uninteresting bits at the top and bottom).

Fixes part of #87481
2021-07-30 16:27:01 +09:00
Yuki Okushi 0180d4ca07
Rollup merge of #87594 - devnexen:netbsd_fs_getfiledescriptor_path, r=joshtriplett
fs File get_path procfs usage for netbsd same as linux.
2021-07-30 16:27:00 +09:00
Yuki Okushi 6e61383b66
Rollup merge of #87585 - GuillaumeGomez:char-types-doc, r=joshtriplett
Add missing links for core::char types
2021-07-30 16:26:59 +09:00
Yuki Okushi 3bc6c28376
Rollup merge of #87574 - cuviper:retain-examples, r=joshtriplett
Update the examples in `String` and `VecDeque::retain`

The examples added in #60396 used a "clever" post-increment hack,
unrelated to the actual point of the examples. That hack was found
[confusing] in the users forum, and #81811 already changed the `Vec`
example to use a more direct iterator. This commit changes `String` and
`VecDeque` in the same way for consistency.

[confusing]: https://users.rust-lang.org/t/help-understand-strange-expression/62858
2021-07-30 16:26:57 +09:00
Yuki Okushi fd79e7740b
Rollup merge of #87522 - frogtd:patch-1, r=yaahc
Fix assert in diy_float

The shifting should have gone the other way, the current incarnation is always true.
2021-07-30 16:26:53 +09:00
Yuki Okushi c25b979db6
Rollup merge of #87052 - phlopsi:patch-1, r=jyn514
Optimize fmt::PadAdapter::wrap

After adding the first `write!` usage to my project and printing the result to the console, I noticed, that my binary contains the strings "called `Option::unwrap()` on a `None` value`" and more importantly "C:\Users\Patrick Fischer\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\fmt\builders.rs", with my release build being configured as follows:
```
[profile.release]
panic = "abort"
codegen-units = 1
strip = "symbols" # the important bit
lto = true
```
I am in a no_std environment and my custom panic handler is a simple `loop {}`. I did not expect the above information to be preserved. I heavily suspect the edited function to be the culprit. It contains the only direct use of `Option::unwrap` in the entire file and I tracked the symbols in the assembly to be used from the section `_ZN68_$LT$core..fmt..builders..PadAdapter$u20$as$u20$core..fmt..Write$GT$9write_str17ha1d5e5efe167202aE`.

Aside from me suspecting this function to be the culprit, the replaced code performs the same operation as `Option::insert`, but without the `unreachable_unchecked` optimization `Option::insert` provides. Therefore, it makes sense to me to use the more optimized version, instead.

As I don't change any semantics, I hope a simple pull request suffices.
2021-07-30 16:26:52 +09:00
bors fe1c942eee Auto merge of #87445 - amalik18:issue-83584-fix, r=kennytm
Fix may not to appropriate might not or must not

I went through and changed occurrences of `may not` to be more explicit with `might not` and `must not`.
2021-07-30 04:34:13 +00:00
Wesley Wiser 286cdc81a8 [backtraces]: look for the begin symbol only after seeing end
On `x86_64-pc-windows-msvc`, we often get backtraces which look like
this:

```
10:     0x7ff77e0e9be5 - std::panicking::rust_panic_with_hook
11:     0x7ff77e0e11b4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c
12:     0x7ff77e0e116f - std::sys_common::backtrace::__rust_end_short_backtrace::h61c7ecb1b55338ae
13:     0x7ff77e0f89dd - std::panicking::begin_panic::h8e60ef9f82a41805
14:     0x7ff77e0e108c - d
15:     0x7ff77e0e1069 - c
16:     0x7ff77e0e1059 - b
17:     0x7ff77e0e1049 - a
18:     0x7ff77e0e1039 - core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>::h1bfcd14d5e15ba81
19:     0x7ff77e0e1186 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5769736bdb11136c
20:     0x7ff77e0e100c - std::rt::lang_start::{{closure}}::ha054184bbf9921e3
```

Notice that `__rust_begin_short_backtrace` appears on frame 11 before
`__rust_end_short_backtrace` on frame 12. This is because in typical
release binaries without debug symbols, dbghelp.dll, which we use to walk
and symbolize the stack, does not know where CGU internal functions
start or end and so the closure invoked by `__rust_end_short_backtrace`
is incorrectly described as `__rust_begin_short_backtrace` because it
happens to be near that symbol.

While that can obviously change, this has been happening quite
consistently since #75048. Since this is a very small change to the std
and the change makes sense by itself, I think this is worth doing.

This doesn't completely resolve the situation for release binaries on
Windows, since without debug symbols, the stack printed can still show
incorrect symbol names (this is why the test uses `#[no_mangle]`) but it
does slightly improve the situation in that you see the same backtrace
you would see with `RUST_BACKTRACE=full` or in a debugger (without the
uninteresting bits at the top and bottom).
2021-07-29 13:51:27 -04:00
David Carlier ce1bd70035 fs File get_path procfs usage for netbsd same as linux. 2021-07-29 17:49:48 +01:00
Ian Jackson bf30c51541 Rename feature gate bufwriter_into_parts from bufwriter_into_raw_parts
As requested
  https://github.com/rust-lang/rust/pull/85901#pullrequestreview-698404772

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29 15:23:32 +01:00
Ian Jackson 66f38075af BufWriter: rename into_parts from into_raw_parts
I looked in stdlib and as @BurntSushi thought, `raw` is generally
used for raw pointers, or other hazardous kinds of thing.  stdlib does
not have `into_parts` apart from the one I added to `IntoInnerError`.

I did an ad-hoc search of the rustdocs for my current game project
Otter, which includes quite a large number of dependencies.
`into_parts` seems heavily used for things quite like this.

So change this name.

Suggested-by: Andrew Gallant <jamslam@gmail.com>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29 15:23:32 +01:00
Ian Jackson cbba940daf BufWriter: actually export WriterPanicked error
I didn't notice the submodule, which means I failed to re-export this
to make it actually-public.

Reported-by: Andrew Gallant <jamslam@gmail.com>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29 13:54:16 +01:00
Guillaume Gomez cf0f5021f4 Add missing links for core::char types 2021-07-29 14:13:41 +02:00
bors 5fb3394cbd Auto merge of #86664 - m-ou-se:uninit-track-caller, r=JohnTitor
Add #[track_caller] for some function in core::mem.

These functions can panic for some types. This makes the panic point to the code that calls e.g. mem::uninitialized(), instead of inside the definition of mem::uninitialized.
2021-07-29 09:35:23 +00:00
bors 6e0a8bf790 Auto merge of #86998 - m-ou-se:const-panic-fmt-as-str, r=oli-obk
Make const panic!("..") work in Rust 2021.

During const eval, this replaces calls to core::panicking::panic_fmt and std::panicking::being_panic_fmt with a call to a new const fn: core::panicking::const_panic_fmt. That function uses fmt::Arguments::as_str() to get the str and calls panic_str with that instead.

panic!() invocations with formatting arguments are still not accepted, as the creation of such a fmt::Arguments cannot be done in constant functions right now.

r? `@RalfJung`
2021-07-29 07:12:07 +00:00
Ali Malik ffcf8a0d76 Fix may not to appropriate might not or must not 2021-07-29 01:16:53 -04:00
Ali Malik e43254aad1 Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
bors 85237886df Auto merge of #85874 - steffahn:fix_unsound_zip_optimization, r=yaahc
Remove unsound TrustedRandomAccess implementations

Removes the implementations that depend on the user-definable trait `Copy`.

Fixes #85873 in the most straightforward way.

<hr>

_Edit:_ This PR now contains additional trait infrastructure to avoid performance regressions around in-place collect, see the discussion in this thread starting from the codegen test failure at https://github.com/rust-lang/rust/pull/85874#issuecomment-872327577.

With this PR, `TrustedRandomAccess` gains additional documentation that specifically allows for and specifies the safety conditions around subtype coercions – those coercions can happen in safe Rust code with the `Zip` API’s usage of `TrustedRandomAccess`. This PR introduces a new supertrait of `TrustedRandomAccess`(currently named `TrustedRandomAccessNoCoerce`) that _doesn’t allow_ such coercions, which means it can be still be useful for optimizing cases such as in-place collect where no iterator is handed out to a user (who could do coercions) after a `get_unchecked` call; the benefit of the supertrait is that it doesn’t come with the additional safety conditions around supertraits either, so it can be implemented for more types than `TrustedRandomAccess`.

The `TrustedRandomAccess` implementations for `vec::IntoIter`, `vec_deque::IntoIter`, and `array::IntoIter` are removed as they don’t conform with the newly documented safety conditions, this way unsoundness is removed. But this PR in turn (re-)adds a `TrustedRandomAccessNoCoerce` implementation for `vec::IntoIter` to avoid performance regressions from stable in a case of in-place collecting of `Vec`s [the above-mentioned codegen test failure]. Re-introducing the (currently nightly+beta-only) impls for `VecDeque`’s and `[T; N]`’s iterators is technically possible, but goes beyond the scope of this PR (i.e. it can happen in a future PR).
2021-07-29 00:31:07 +00:00
Josh Stone d4a60ab34f Update the examples in String and VecDeque::retain
The examples added in #60396 used a "clever" post-increment hack,
unrelated to the actual point of the examples. That hack was found
[confusing] in the users forum, and #81811 already changed the `Vec`
example to use a more direct iterator. This commit changes `String` and
`VecDeque` in the same way for consistency.

[confusing]: https://users.rust-lang.org/t/help-understand-strange-expression/62858
2021-07-28 16:35:59 -07:00
Yuki Okushi 6c4888a74e
Rollup merge of #87565 - ibraheemdev:patch-7, r=scottmcm
Use backticks when referring to `core::future::Ready` in panic message
2021-07-29 06:11:50 +09:00
Yuki Okushi 87c9f32dc4
Rollup merge of #86839 - D1mon:patch-1, r=JohnTitor
Add doc aliases to fs.rs

Add aliases for create_dir, create_dir_all, remove_dir, remove_dir_all
2021-07-29 06:11:43 +09:00
Yuki Okushi 7c1283a068
Rollup merge of #81363 - jonhoo:no-unpin-in-pin-future-impl, r=m-ou-se
Remove P: Unpin bound on impl Future for Pin

We can safely produce a `Pin<&mut P::Target>` without moving out of the `Pin` by using `Pin::as_mut` directly.

The `Unpin` bound was originally added in #56939 following the recommendation of ``@withoutboats`` in https://github.com/rust-lang/rust/issues/55766#issue-378417538

That comment does not give explicit justification for why the bound should be added. The relevant context was:

> [ ] Remove `impl<P> Unpin for Pin<P>`
>
> This impl is not justified by our standard justification for unpin impls: there is no pointer direction between `Pin<P>` and `P`. Its usefulness is covered by the impls for pointers themselves.
>
> This futures impl (link to the impl changed in this PR) will need to change to add a `P: Unpin` bound.

The decision to remove the unconditional impl of `Unpin for Pin` is sound (these days there is just an auto-impl for when `P: Unpin`). But, I think the decision to also add the `Unpin` bound for `impl Future` may have been unnecessary. Or if that's not the case, I'd be very interested to have the argument for why written down somewhere. The bound _appears_ to not be needed, as demonstrated by the change requiring no unsafe code and by the existence of `Pin::as_mut`.
2021-07-29 06:11:42 +09:00
Yuki Okushi fef1725c0f
Rollup merge of #81050 - yoshuawuyts:stabilize-task-ready, r=m-ou-se
Stabilize core::task::ready!

_Tracking issue: https://github.com/rust-lang/rust/issues/70922_

This PR stabilizes the `task::ready!` macro. Similar to https://github.com/rust-lang/rust/pull/80886, this PR was waiting on https://github.com/rust-lang/rust/issues/74355 to be fixed.

The `task::ready!` API has existed in the futures ecosystem for several years, and was added on nightly last year in https://github.com/rust-lang/rust/pull/70817. The motivation for this macro is the same as it was back then: virtually every single manual future implementation makes use of this; so much so that it's one of the few things included in the [futures-core](https://docs.rs/futures-core/0.3.12/futures_core) library.

r? ``@tmandry``

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

## Example
```rust
use core::task::{Context, Poll};
use core::future::Future;
use core::pin::Pin;

async fn get_num() -> usize {
    42
}

pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
    let mut f = get_num();
    let f = unsafe { Pin::new_unchecked(&mut f) };

    let num = ready!(f.poll(cx));
    // ... use num

    Poll::Ready(())
}
```
2021-07-29 06:11:41 +09:00
Ibraheem Ahmed 2d8b6e3476
Use backticks when referring to core::future::Ready in panic message 2021-07-28 16:22:34 -04:00
D1mon 387cd6dbf6
Add some doc aliases
Add `mkdir` to `create_dir`, `rmdir` to `remove_dir`.
2021-07-29 04:23:01 +09:00
Mara Bos 18cc06c848 Update stable version of ready!() macro. 2021-07-28 16:56:12 +02:00
Mara Bos 312bf8e0b8 Extend documentation of const_format_args!(). 2021-07-28 16:18:38 +02:00
Mara Bos 0b8033ad8d Improve comments about const panic handling
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-07-28 16:18:38 +02:00
Mara Bos 38bf5b0412 Make const_fmt_args!() work during bootstrap. 2021-07-28 16:12:31 +02:00
Mara Bos b48274fd98 Use unreachable_unchecked in const_panic_fmt. 2021-07-28 16:12:30 +02:00
Mara Bos b64c4f9560 Add new const_format_args!() macro and use it in panics. 2021-07-28 16:12:25 +02:00
Mara Bos f827d3e285 Make const panic!("..") work in Rust 2021.
During const eval, this replaces calls to core::panicking::panic_fmt and
std::panicking::being_panic_fmt with a call to a new const fn:
core::panicking::const_panic_fmt. That function uses
fmt::Arguments::as_str() to get the str and calls panic_str with that
instead.

panic!() invocations with formatting arguments are still not accepted,
as the creation of such a fmt::Arguments cannot be done in constant
functions right now.
2021-07-28 16:10:41 +02:00
Mara Bos 3f6dc9a8ab Add #[track_caller] for some function in core::mem.
These functions can panic for some types. This makes the panic point to
the code that calls e.g. mem::uninitialized(), instead of inside the
definition of mem::uninitialized.
2021-07-28 14:34:36 +02:00
Frank Steffahn 6d9c0a16d9 Documentation improvements 2021-07-28 14:33:37 +02:00
Frank Steffahn 89583e98e8 Make SpecInPlaceCollect use TrustedRandomAccessNoCoerce 2021-07-28 14:33:36 +02:00
Frank Steffahn 9ff421da99 Remove redundant bounds on get_unchecked for vec_deque iterators, and run fmt 2021-07-28 14:33:36 +02:00
Frank Steffahn f9c982c8fd Add back TrustedRandomAccess-specialization for Vec, but only without coercions 2021-07-28 14:33:36 +02:00
Frank Steffahn bbc6b2691e Change __iterator_get_unchecked to work with TrustedRandomAccessNoCoerce 2021-07-28 14:33:35 +02:00
Frank Steffahn 69dd992f95 Add TrustedRandomAccessNoCoerce supertrait without requirements or guarantees about subtype coercions
Update all the TrustedRandomAccess impls to also implement the new supertrait
2021-07-28 14:33:35 +02:00
Frank Steffahn 1c7f27f792 Improve documentation of TrustedRandomAccess
Include new details regarding coercions to a subtype.
These conditions also explain why the previously removed implementations
for {array, vec, vec_deque}::IntoIter<T> were unsound, because they introduced
an extra `T: Clone` for the TrustedRandomAccess impl, even though their parameter T
is covariant.
2021-07-28 14:33:35 +02:00
Frank Steffahn a0d8a324eb Remove unsound TrustedRandomAccess implementations
Removes the implementations that depend on the user-definable trait `Copy`.
2021-07-28 14:33:28 +02:00
Yuki Okushi 4ae529688a
Rollup merge of #87523 - frogtd:patch-2, r=dtolnay
Stop creating a reference then immediately dereferencing it.

Stop creating a reference then immediately dereferencing it.
2021-07-28 18:28:22 +09:00
Yuki Okushi 8bc7ec1316
Rollup merge of #87507 - jethrogb:jb/sgx-unmoveable-mutex, r=dtolnay
SGX mutex is *not* moveable

Reverts the erroneous change in #85029.
2021-07-28 18:28:20 +09:00
Yuki Okushi 23479f716a
Rollup merge of #87501 - spastorino:remove-min-tait, r=oli-obk
Remove min_type_alias_impl_trait in favor of type_alias_impl_trait

r? ``@oli-obk``
2021-07-28 18:28:19 +09:00
Yuki Okushi 35dddd3dea
Rollup merge of #87500 - Smittyvb:min-max-docs, r=kennytm
Document math behind MIN/MAX consts on integers

Currently the documentation for `[integer]::{MIN, MAX}` doesn't explain where the constants come from. This documents how the values of those constants are related to powers of 2.
2021-07-28 18:28:18 +09:00
Yuki Okushi 98f7a009fa
Rollup merge of #87330 - inquisitivecrystal:extend-reserve, r=JohnTitor
Use hashbrown's `extend_reserve()` in `HashMap`

When we added `extend_reserve()` to our implementation of `Extend` for `HashMap`, hashbrown didn't have a version we could use. Now that hashbrown has added it, we should use its version instead of implementing it ourself.
2021-07-28 18:28:14 +09:00
bors aea2e446f0 Auto merge of #86735 - jhpratt:rfc-3107, r=petrochenkov
Implement RFC 3107: `#[derive(Default)]` on enums with a `#[default]` attribute

This PR implements RFC 3107, which permits `#[derive(Default)]` on enums where a unit variant has a `#[default]` attribute. See comments for current status.
2021-07-28 05:59:30 +00:00
Smitty 0e017496eb remove unneeded stringify 2021-07-27 16:37:18 -04:00
Jacob Pratt 37af399573
Update tests 2021-07-27 16:26:50 -04:00