Commit Graph

6436 Commits

Author SHA1 Message Date
Matthias Krüger 42a3acfdb1
Rollup merge of #92517 - ChrisDenton:explicit-path, r=dtolnay
Explicitly pass `PATH` to the Windows exe resolver

This allows for testing different `PATH`s without using the actual environment.
2022-01-05 11:26:07 +01:00
Matthias Krüger a0262fdf1f
Rollup merge of #92322 - alper:add_debug_trait_documentation, r=dtolnay
Add another implementation example to Debug trait

As per the discussion in: #92276
2022-01-05 11:26:05 +01:00
luojia65 06f4453027 Add is_riscv_feature_detected!; modify impl of hint::spin_loop
Update library/core/src/hint.rs

Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>

Remove redundant config gate
2022-01-05 15:44:52 +08:00
Mark Rousskov 57b59af9fb Add note about non_exhaustive to variant_count 2022-01-04 21:58:36 -05:00
bors 5883b87563 Auto merge of #92560 - matthiaskrgr:rollup-jeli7ip, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91587 (core::ops::unsize: improve docs for DispatchFromDyn)
 - #91907 (Allow `_` as the length of array types and repeat expressions)
 - #92515 (RustWrapper: adapt for an LLVM API change)
 - #92516 (Do not use deprecated -Zsymbol-mangling-version in bootstrap)
 - #92530 (Move `contains` method of Option and Result lower in docs)
 - #92546 (Update books)
 - #92551 (rename StackPopClean::None to Root)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-04 23:01:49 +00:00
David Tolnay 4df1a5561a
Touch up Debug example from PR 92322 2022-01-04 14:28:28 -08:00
Matthias Krüger af49d81e04
Rollup merge of #92530 - dtolnay:contains, r=yaahc
Move `contains` method of Option and Result lower in docs

Follow-up to #92444 trying to get the `Option` and `Result` rustdocs in better shape.

This addresses the request in https://github.com/rust-lang/rust/issues/62358#issuecomment-645676285. The `contains` methods are previously too high up in the docs on both `Option` and `Result` &mdash; stuff like `ok` and `map` and `and_then` should all be featured higher than `contains`. All of those are more ubiquitously useful than `contains`.
2022-01-04 21:23:10 +01:00
Matthias Krüger d49c692eeb
Rollup merge of #91587 - nrc:dispatchfromdyn-docs, r=yaahc
core::ops::unsize: improve docs for DispatchFromDyn

Docs-only PR, improves documentation for DispatchFromDyn.
2022-01-04 21:23:05 +01:00
Matthias Krüger b2d6ff4b6e
Rollup merge of #92525 - zohnannor:patch-1, r=camelid
intra-doc: Make `Receiver::into_iter` into a clickable link

The documentation on `std::sync::mpsc::Iter` and `std::sync::mpsc::TryIter` provides links to the corresponding `Receiver` methods, unlike `std::sync::mpsc::IntoIter` does.

This was left out in c59b188aae
Related to #29377
2022-01-04 16:34:19 +01:00
Matthias Krüger 4e4e1ec931
Rollup merge of #92456 - danielhenrymantilla:patch-1, r=petrochenkov
Make the documentation of builtin macro attributes accessible

`use ::std::prelude::v1::derive;` compiles on stable, so, AFAIK, there is no reason to have it be `#[doc(hidden)]`.

  - What it currently looks like for things such as `#[test]`, `#[derive]`, `#[global_allocator]`: https://doc.rust-lang.org/1.57.0/core/prelude/v1/index.html#:~:text=Experimental-,pub,-use%20crate%3A%3Amacros%3A%3Abuiltin%3A%3Aglobal_allocator

    <img width="767" alt="Screen Shot 2021-12-31 at 17 49 46" src="https://user-images.githubusercontent.com/9920355/147832999-cbd747a6-4607-4df6-8e57-c1675dcbc1c3.png">

    and in `::std` they're just straight `hidden`.

    <img width="452" alt="Screen Shot 2021-12-31 at 17 53 18" src="https://user-images.githubusercontent.com/9920355/147833105-c5ff8cd1-9e4d-4d2b-9621-b36aa3cfcb28.png">

  - Here is how it looks like with this PR (assuming the `Rustc{De,En}codable` ones are not reverted):

    <img width="778" alt="Screen Shot 2021-12-31 at 17 50 55" src="https://user-images.githubusercontent.com/9920355/147833034-84286342-dbf7-4e6e-9062-f39cd6c286a4.png">

    <img width="291" alt="Screen Shot 2021-12-31 at 17 52 54" src="https://user-images.githubusercontent.com/9920355/147833109-c92ed55c-51c6-40a2-9205-f834d1e349c0.png">

 Since this involves doc people to chime in, and since `jyn` is on vacation, I'll cc `@GuillaumeGomez` and tag the `rustdoc` team as well
2022-01-04 16:34:16 +01:00
Matthias Krüger c7125ba0fa
Rollup merge of #91884 - woppopo:const_box, r=oli-obk
Constify `Box<T, A>` methods

Tracking issue: none yet

Most of the methods bounded on `~const`. `intrinsics::const_eval_select` is used for handling an allocation error.

<details><summary>Constified API</summary>

```rust
impl<T, A: Allocator> Box<T, A> {
    pub const fn new_in(x: T, alloc: A) -> Self
    where
        A: ~const Allocator + ~const Drop;
    pub const fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
    where
        T: ~const Drop,
        A: ~const Allocator + ~const Drop;
    pub const fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn try_new_uninit_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn try_new_zeroed_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn pin_in(x: T, alloc: A) -> Pin<Self>
    where
        A: 'static,
        A: 'static + ~const Allocator + ~const Drop,
    pub const fn into_boxed_slice(boxed: Self) -> Box<[T], A>;
    pub const fn into_inner(boxed: Self) -> T
    where
        Self: ~const Drop,
}

impl<T, A: Allocator> Box<MaybeUninit<T>, A> {
    pub const unsafe fn assume_init(self) -> Box<T, A>;
    pub const fn write(mut boxed: Self, value: T) -> Box<T, A>;
    pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self;
    pub const fn into_raw_with_allocator(b: Self) -> (*mut T, A);
    pub const fn into_unique(b: Self) -> (Unique<T>, A);
    pub const fn allocator(b: &Self) -> &A;
    pub const fn leak<'a>(b: Self) -> &'a mut T
    where
        A: 'a;
    pub const fn into_pin(boxed: Self) -> Pin<Self>
    where
        A: 'static;
}

unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> const Drop for Box<T, A>;
impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
where
    A: 'static;
impl<T: ?Sized, A: Allocator> const Deref for Box<T, A>;
impl<T: ?Sized, A: Allocator> const DerefMut for Box<T, A>;
impl<T: ?Sized, A: Allocator> const Unpin for Box<T, A> where A: 'static;
```

</details>

<details><summary>Example</summary>

```rust
pub struct ConstAllocator;

unsafe impl const Allocator for ConstAllocator {
    fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        unsafe {
            let ptr = core::intrinsics::const_allocate(layout.size(), layout.align());
            Ok(NonNull::new_unchecked(ptr as *mut [u8; 0] as *mut [u8]))
        }
    }

    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
        /* do nothing */
    }

    fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        self.allocate(layout)
    }

    unsafe fn grow(
        &self,
        _ptr: NonNull<u8>,
        _old_layout: Layout,
        _new_layout: Layout,
    ) -> Result<NonNull<[u8]>, AllocError> {
        unimplemented!()
    }

    unsafe fn grow_zeroed(
        &self,
        _ptr: NonNull<u8>,
        _old_layout: Layout,
        _new_layout: Layout,
    ) -> Result<NonNull<[u8]>, AllocError> {
        unimplemented!()
    }

    unsafe fn shrink(
        &self,
        _ptr: NonNull<u8>,
        _old_layout: Layout,
        _new_layout: Layout,
    ) -> Result<NonNull<[u8]>, AllocError> {
        unimplemented!()
    }

    fn by_ref(&self) -> &Self
    where
        Self: Sized,
    {
        self
    }
}

#[test]
fn const_box() {
    const VALUE: u32 = {
        let mut boxed = Box::new_in(1u32, ConstAllocator);
        assert!(*boxed == 1);

        *boxed = 42;
        assert!(*boxed == 42);

        *boxed
    };

    assert!(VALUE == 42);
}
```

</details>
2022-01-04 16:34:14 +01:00
Matthias Krüger 50a66b75dc
Rollup merge of #91754 - Patrick-Poitras:rm-4byte-minimum-stdio-windows, r=Mark-Simulacrum
Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte buffer minimum in read().

This is an attempted fix of issue #91722, where a too-small buffer was passed to the read function of stdio on Windows. This caused an error to be returned when `read_to_end` or `read_to_string` were called. Both delegate to `std::io::default_read_to_end`, which creates a buffer that is of length >0, and forwards it to `std::io::Stdin::read()`. The latter method returns an error if the length of the buffer is less than 4, as there might not be enough space to allocate a UTF-16 character. This creates a problem when the buffer length is in `0 < N < 4`, causing the bug.

The current modification creates an internal buffer, much like the one used for the write functions

I'd also like to acknowledge the help of ``@agausmann`` and ``@hkratz`` in detecting and isolating the bug, and for suggestions that made the fix possible.

Couple disclaimers:

- Firstly, I didn't know where to put code to replicate the bug found in the issue. It would probably be wise to add that case to the testing suite, but I'm afraid that I don't know _where_ that test should be added.
- Secondly, the code is fairly fundamental to IO operations, so my fears are that this may cause some undesired side effects ~or performance loss in benchmarks.~ The testing suite runs on my computer, and it does fix the issue noted in #91722.
- Thirdly, I left the "surrogate" field in the Stdin struct, but from a cursory glance, it seems to be serving the same purpose for other functions. Perhaps merging the two would be appropriate.

Finally, this is my first pull request to the rust language, and as such some things may be weird/unidiomatic/plain out bad. If there are any obvious improvements I could do to the code, or any other suggestions, I would appreciate them.

Edit: Closes #91722
2022-01-04 16:34:14 +01:00
Mara Bos a45b3ac183 Simpilfy thread::JoinInner. 2022-01-04 14:08:44 +01:00
ksqsf 1c547f422a Stabilize `result_cloned` and `result_copied` 2022-01-04 13:23:32 +08:00
Daniel Henry-Mantilla f20ccc0748 Make the documentation of builtin macro attributes accessible
- Do not `#[doc(hidden)]` the `#[derive]` macro attribute

  - Add a link to the reference section to `derive`'s inherent docs

  - Do the same for `#[test]` and `#[global_allocator]`

  - Fix `GlobalAlloc` link (why is it on `core` and not `alloc`?)

  - Try `no_inline`-ing the `std` reexports from `core`

  - Revert "Try `no_inline`-ing the `std` reexports from `core`"

  - Address PR review

  - Also document the unstable macros
2022-01-03 20:43:16 +01:00
David Tolnay 7dec41a236
Move `contains` method of Option and Result lower in docs 2022-01-03 10:46:15 -08:00
zohnannor ca3f9048a1
Make `Receiver::into_iter` into a clickable link
The documentation on `std::sync::mpsc::Iter` and `std::sync::mpsc::TryIter` provides links to the corresponding `Receiver` methods, unlike `std::sync::mpsc::IntoIter` does.

This was left out in c59b188aae
Related to #29377
2022-01-03 20:17:57 +03:00
woppopo 51e4291f2b Fix a compile error when no_global_oom_handling 2022-01-04 01:37:53 +09:00
woppopo c9d2d3cc66 Add tracking issues (`const_box`, `const_alloc_error`) 2022-01-04 00:35:53 +09:00
Matthias Krüger 13e284033e
Rollup merge of #92444 - dtolnay:coremethods, r=joshtriplett
Consolidate Result's and Option's methods into fewer impl blocks

`Result`'s and `Option`'s methods have historically been separated up into `impl` blocks based on their trait bounds, with the bounds specified on type parameters of the impl block. I find this unhelpful because closely related methods, like `unwrap_or` and `unwrap_or_default`, end up disproportionately far apart in source code and rustdocs:

<pre>
impl&lt;T&gt; Option&lt;T&gt; {
    pub fn unwrap_or(self, default: T) -&gt; T {
        ...
    }

    <img alt="one eternity later" src="https://user-images.githubusercontent.com/1940490/147780325-ad4e01a4-c971-436e-bdf4-e755f2d35f15.jpg" width="750">
}

impl&lt;T: Default&gt; Option&lt;T&gt; {
    pub fn unwrap_or_default(self) -&gt; T {
        ...
    }
}
</pre>

I'd prefer for method to be in as few impl blocks as possible, with the most logical grouping within each impl block. Any bounds needed can be written as `where` clauses on the method instead:

```rust
impl<T> Option<T> {
    pub fn unwrap_or(self, default: T) -> T {
        ...
    }

    pub fn unwrap_or_default(self) -> T
    where
        T: Default,
    {
        ...
    }
}
```

*Warning: the end-to-end diff of this PR is computed confusingly by git / rendered confusingly by GitHub; it's practically impossible to review that way. I've broken the PR into commits that move small groups of methods for which git behaves better &mdash; these each should be easily individually reviewable.*
2022-01-03 14:44:21 +01:00
Matthias Krüger 92f28bda38
Rollup merge of #92409 - bjorn3:libtest_cleanups, r=m-ou-se
Couple of libtest cleanups

Remove the unnecessary `TDynBenchFn` trait and remove a couple of unused attributes and feature gates.
2022-01-03 14:44:19 +01:00
Chris Denton 4145877731
Explicitly pass `PATH` to the Windows exe resolver 2022-01-03 12:55:42 +00:00
bors 82418f93ac Auto merge of #91961 - kornelski:track_split_caller, r=joshtriplett
Track caller of slice split and swap

Improves error location for `slice.split_at*()` and `slice.swap()`.

These are generic inline functions, so the `#[track_caller]` on them is free — only changes a value of an argument already passed to panicking code.
2022-01-02 09:35:24 +00:00
bors 7b13c628a2 Auto merge of #92482 - matthiaskrgr:rollup-uso1zi0, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #84083 (Clarify the guarantees that ThreadId does and doesn't make.)
 - #91593 (Remove unnecessary bounds for some Hash{Map,Set} methods)
 - #92297 (Reduce compile time of rustbuild)
 - #92332 (Add test for where clause order)
 - #92438 (Enforce formatting for rustc_codegen_cranelift)
 - #92463 (Remove pronunciation guide from Vec<T>)
 - #92468 (Emit an error for `--cfg=)`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-02 00:20:04 +00:00
Matthias Krüger aa31c9726d
Rollup merge of #92463 - thomcc:thats-not-how-its-pronounced, r=joshtriplett
Remove pronunciation guide from Vec<T>

I performed an extremely scientific poll on twitter, and determined this is not how it's pronounced: https://twitter.com/at_tcsc/status/1476643344285581315
2022-01-01 22:49:52 +01:00
Matthias Krüger 5137f7c9db
Rollup merge of #91593 - upsuper-forks:hashmap-set-methods-bound, r=dtolnay
Remove unnecessary bounds for some Hash{Map,Set} methods

This PR moves `HashMap::{into_keys,into_values,retain}` and `HashSet::retain` from `impl` blocks with `K: Eq + Hash, S: BuildHasher` into the blocks without them. It doesn't seem to me there is any reason these methods need to be bounded by that. This change brings `HashMap::{into_keys,into_values}` on par with `HashMap::{keys,values,values_mut}` which are not bounded either.
2022-01-01 22:49:48 +01:00
Matthias Krüger 30ec1f0384
Rollup merge of #84083 - ltratt:threadid_doc_tweak, r=dtolnay
Clarify the guarantees that ThreadId does and doesn't make.

The existing documentation does not spell out whether `ThreadId`s are unique during the lifetime of a thread or of a process. I had to examine the source code to realise (pleasingly!) that they're unique for the lifetime of a process. That seems worth documenting clearly, as it's a strong guarantee.

Examining the way `ThreadId`s are created also made me realise that the `as_u64` method on `ThreadId` could be a trap for the unwary on those platforms where the platform's notion of a thread identifier is also a 64 bit integer (particularly if they happen to use a similar identifier scheme to `ThreadId`). I therefore think it's worth being even clearer that there's no relationship between the two.
2022-01-01 22:49:47 +01:00
bors dd3ac41495 Auto merge of #92396 - xfix:remove-commandenv-apply, r=Mark-Simulacrum
Remove CommandEnv::apply

It's not being used and uses unsound set_var and remove_var functions. This is an internal function that isn't exported (even with `process_internals` feature), so this shouldn't break anything.

Also see #92365. Note that this isn't the only use of those methods in standard library, so that particular pull request will need more changes than just this to work (in particular, `test_capture_env_at_spawn` is using `set_var` and `remove_var`).
2022-01-01 20:45:37 +00:00
Matthias Krüger 4bd4e271e4
Rollup merge of #92469 - joshtriplett:test-number-fix, r=Mark-Simulacrum
Make tidy check for magic numbers that spell things

Remove existing problematic cases.

r? `@Mark-Simulacrum`
2022-01-01 10:48:58 +01:00
Matthias Krüger a6e4d684aa
Rollup merge of #92097 - saethlin:split-without-deref, r=the8472
Implement split_at_spare_mut without Deref to a slice so that the spare slice is valid

~I'm not sure I understand what's going on here correctly. And I'm pretty sure this safety comment needs to be changed. I'm just referring to the same thing that `as_mut_ptr_range` does.~ (Thanks `@RalfJung` for the guidance and clearing things up)

I tried to run https://github.com/rust-lang/miri-test-libstd on alloc with -Zmiri-track-raw-pointers, and got a failure on the test `vec::test_extend_from_within`.

I minimized the test failure into this program:
```rust
#![feature(vec_split_at_spare)]
fn main() {
    Vec::<i32>::with_capacity(1).split_at_spare_mut();
}
```

The problem is that the existing implementation is actually getting a pointer range where both pointers are derived from the initialized region of the Vec's allocation, but we need the second one to be valid for the region between len and capacity. (thanks Ralf for clearing this up)
2022-01-01 10:48:54 +01:00
Josh Triplett 0d55bd1100 Make tidy check for magic numbers that spell things
Remove existing problematic cases.
2021-12-31 21:13:07 -08:00
Ben Kimock 777c853b4a Clarify safety comment 2021-12-31 18:03:07 -05:00
Matthias Krüger 8322603970
Rollup merge of #92338 - Xuanwo:try_reserve, r=dtolnay
Add try_reserve and  try_reserve_exact for OsString

Add `try_reserve` and `try_reserve_exact` for OsString.

Part of https://github.com/rust-lang/rust/issues/91789

I will squash the commits after PR is ready to merge.

Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-31 23:14:46 +01:00
Thom Chiovoloni 51a1681b69 Remove pronunciation guide from Vec<T> 2021-12-31 16:04:13 -05:00
David Tolnay d29941e724
Remove needless allocation from example code of OsString 2021-12-30 12:45:02 -08:00
David Tolnay 1f62c24d5a
Fix some copy/paste hysteresis in OsString try_reserve docs
It appears `find_max_slow` comes from the BinaryHeap docs, where the
try_reserve example is a slow implementation of find_max. It has no
relevance to this code in OsString though.
2021-12-30 12:41:26 -08:00
David Tolnay dc3291614a
Consolidate impl Option<&mut T> 2021-12-30 10:37:53 -08:00
David Tolnay 538fe4b28d
Consolidate impl Option<&T> 2021-12-30 10:37:27 -08:00
David Tolnay 9d65bc51c1
Move Option::as_deref_mut 2021-12-30 10:36:55 -08:00
David Tolnay 48a91a08d1
Move Option::as_deref 2021-12-30 10:36:37 -08:00
David Tolnay bbcf09f2fb
Move Option::unwrap_or_default 2021-12-30 10:34:35 -08:00
David Tolnay b7a0ab18f6
Consolidate impl Result<&mut T, E> 2021-12-30 10:31:26 -08:00
David Tolnay e63e2680da
Consolidate impl Result<&T, E> 2021-12-30 10:30:28 -08:00
David Tolnay b2df61fa9f
Move Result::into_err 2021-12-30 10:28:54 -08:00
David Tolnay 778ca204a6
Move Result::into_ok 2021-12-30 10:28:23 -08:00
David Tolnay 06ea5ebe4e
Move Result::expect_err and Result::unwrap_err 2021-12-30 10:27:43 -08:00
David Tolnay aa2aca2c8c
Move Result::unwrap_or_default 2021-12-30 10:26:36 -08:00
David Tolnay 15f57a6c59
Move Result::expect and Result::unwrap 2021-12-30 10:25:42 -08:00
David Tolnay 5aa8f91ff0
Move Result::as_deref_mut 2021-12-30 10:24:23 -08:00
David Tolnay eda61d8d8a
Move Result::as_deref 2021-12-30 10:23:46 -08:00
Chayim Refael Friedman e86ecdf9fe
Use `UnsafeCell::get_mut()` in `core::lazy::OnceCell::get_mut()`
This removes one unnecessary `unsafe` block.
2021-12-30 05:04:44 +02:00
bjorn3 e015b9ee80 Remove unused allow deprecated 2021-12-29 18:06:01 +01:00
bjorn3 f710bc5fc0 Remove unused feature gates from libtest 2021-12-29 16:36:22 +01:00
bjorn3 1ea4810c84 Remove #![crate_name] attribute from libtest
The crate name is already set in Cargo.toml. The comment says there is
some logic in the compiler that reads #![crate_name] and not
--crate-name, but I can't find it. Removing it seems to work fine.
2021-12-29 16:36:08 +01:00
bjorn3 75d8339cdd Replace TDynBenchFn with Fn(&mut Bencher) 2021-12-29 16:17:50 +01:00
Konrad Borowski 14fc9dcbba Remove CommandEnv::apply
It's not being used and uses unsound set_var and remove_var
functions.
2021-12-29 10:07:44 +01:00
Xuanwo b07ae1c4d5
Address comments
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-29 14:02:20 +08:00
bors b70cc6422c Auto merge of #92291 - AngelicosPhosphoros:typeid_inline_revert_92135, r=joshtriplett
Reverts #92135 because perf regression

Please, start a perf test for this.

r? `@joshtriplett` You approved original PR.
2021-12-29 05:53:19 +00:00
Xuanwo 9166428be1
Update library/std/src/ffi/os_str.rs
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2021-12-29 13:49:39 +08:00
Sprite a877b64717 Fix a minor mistake in `String::try_reserve_exact` examples 2021-12-29 13:22:35 +08:00
ltdk b1b873f365 Extend const_convert to rest of blanket core::convert impls 2021-12-28 20:53:51 -05:00
Matthias Krüger c9cc9e589c
Rollup merge of #92335 - ecstatic-morse:std-column-unicode, r=Manishearth
Document units for `std::column`

Fixes #92301.

r? ``@Manishearth`` (for the terminology and the Chinese)
2021-12-28 13:59:26 +01:00
Xuanwo 27b92c9f98
Implement support in wtf8
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28 11:53:14 +08:00
Xuanwo 013fbc6187
Fix windows build
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28 11:40:58 +08:00
Xuanwo c40ac57efb
Add try_reserve for OsString
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28 11:28:05 +08:00
Dylan MacKenzie 3115d8413a Document units for `std::column` 2021-12-27 15:39:35 -08:00
Matthias Krüger eab81297f7
Rollup merge of #92307 - hiroshi-maybe:fix-minor-typos, r=camelid
Fix minor typos
2021-12-27 21:42:30 +01:00
Matthias Krüger 4d8ba2193f
Rollup merge of #92264 - Shadlock0133:patch-1, r=the8472
Remove `maybe_uninit_extra` feature from Vec docs

In `Vec`, two doc tests are using `MaybeUninit::write` , stabilized in 1.55. This makes docs' usage of `maybe_uninit_extra` feature unnecessary.
2021-12-27 21:42:28 +01:00
Noah Lev 60ec6a0e38
Tweak sentence in `transmute` docs 2021-12-27 11:40:17 -08:00
Alper Çugun 1773e8318f
Add another implementation example to Debug trait 2021-12-27 12:28:11 +01:00
Hiroshi Kori 7a3a668bc9 fix typo: intialized -> initialized 2021-12-26 18:37:11 -08:00
Hiroshi Kori 7ddad349b1 fix typo: the use f.pad -> then use f.pad 2021-12-26 17:44:53 -08:00
AngelicosPhosphoros 72b0c8f233 Reverts #92135 because perf regression 2021-12-26 16:02:33 +03:00
Scallop Ye e3ad30962e
Fix a pair of mistyped test cases in std::net::ip 2021-12-26 16:41:32 +08:00
Laurence Tratt d66a9e16ba Language tweak. 2021-12-25 15:18:55 +00:00
Shadlock0133 584e88d41d
Remove `maybe_uninit_extra` feature from Vec docs
In `Vec`, two doc tests are using `MaybeUninit::write` , stabilized in 1.55. This makes docs' usage of `maybe_uninit_extra` feature unnecessary.
2021-12-24 23:04:10 +01:00
bors 475b00aa40 Auto merge of #92135 - AngelicosPhosphoros:typeid_inline_74362, r=dtolnay
Add `#[inline]` modifier to `TypeId::of`

It was already inlined but it happened only in 4th InlinerPass on my testcase.
With `#[inline]` modifier it happens on 2nd pass.

Closes #74362
2021-12-24 20:06:15 +00:00
bors fca4b155a7 Auto merge of #92226 - woppopo:const_black_box, r=joshtriplett
Constify `core::intrinsics::black_box` and `core::hint::black_box`.

`core::intrinsics::black_box` is already constified, but it wasn't marked as const (see: https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs#L471).

Tracking issue: None
2021-12-24 10:02:54 +00:00
bors e6f1f04e52 Auto merge of #92220 - nnethercote:RawVec-dont-recompute-capacity, r=joshtriplett
RawVec: don't recompute capacity after allocating.

Currently it sets the capacity to `ptr.len() / mem::size_of::<T>()`
after any buffer allocation/reallocation. This would be useful if
allocators ever returned a `NonNull<[u8]>` with a size larger than
requested. But this never happens, so it's not useful.

Removing this slightly reduces the size of generated LLVM IR, and
slightly speeds up the hot path of `RawVec` growth.

r? `@ghost`
2021-12-24 01:54:56 +00:00
Matthias Krüger 94b9b5f35f
Rollup merge of #92121 - RalfJung:miri-core-test, r=kennytm
disable test with self-referential generator on Miri

Running the libcore test suite in Miri currently fails due to the known incompatibility of self-referential generators with Miri's aliasing checks (https://github.com/rust-lang/unsafe-code-guidelines/issues/148). So let's disable that test in Miri for now.
2021-12-23 17:48:30 +01:00
Matthias Krüger 40c6720620
Rollup merge of #90625 - Milo123459:ref-unwind-safe, r=dtolnay
Add `UnwindSafe` to `Once`

Fixes #43469
2021-12-23 17:48:29 +01:00
Deadbeef 3ae0dabddb
Bless a few tests 2021-12-23 21:26:05 +08:00
woppopo eb4fc640b0 Constify `Box<T, A>` methods 2021-12-23 22:03:12 +09:00
woppopo 72f15ea22a Constify `core::intrinsics::black_box` 2021-12-23 20:07:41 +09:00
Deadbeef 06a1c14d52
Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
Deadbeef f52eb4ca8b
Add const-stability to `panicking::panic_*` fns
This allows us to use `panic!` and friends in a const-stable context
within libcore.
2021-12-23 19:03:43 +08:00
bors 390bb3406d Auto merge of #92155 - m-ou-se:panic-fn, r=eddyb
Use panic() instead of panic!() in some places in core.

See https://github.com/rust-lang/rust/pull/92068 and https://github.com/rust-lang/rust/pull/92140.

This avoids the `panic!()` macro in a few potentially hot paths. This becomes more relevant when switching `core` to Rust 2021, as it'll avoid format_args!() and save some compilation time. (It doesn't make a huge difference, but still.) (Also the errors in const panic become slightly nicer.)
2021-12-23 05:17:47 +00:00
Matthias Krüger 3afed8fc70
Rollup merge of #92208 - ChrisDenton:win-bat-cmd, r=dtolnay
Quote bat script command line

Fixes #91991

[`CreateProcessW`](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw#parameters) should only be used to run exe files but it does have some (undocumented) special handling for files with `.bat` and `.cmd` extensions. Essentially those magic extensions will cause the parameters to be automatically rewritten. Example pseudo Rust code (note that `CreateProcess` starts with an optional application name followed by the application arguments):
```rust
// These arguments...
CreateProcess(None, `@"foo.bat` "hello world""`@,` ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@""foo.bat` "hello world"""`@,` ...);
```

However, when setting the first parameter (the application name) as we now do, it will omit the extra level of quotes around the arguments:

```rust
// These arguments...
CreateProcess(Some("foo.bat"), `@"foo.bat` "hello world""`@,` ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@"foo.bat` "hello world""`@,` ...);
```

This means the arguments won't be passed to the script as intended.

Note that running batch files this way is undocumented but people have relied on this so we probably shouldn't break it.
2021-12-23 00:28:56 +01:00
Matthias Krüger 12e4907728
Rollup merge of #92139 - dtolnay:backtrace, r=m-ou-se
Change Backtrace::enabled atomic from SeqCst to Relaxed

This atomic is not synchronizing anything outside of its own value, so we don't need the `Acquire`/`Release` guarantee that all memory operations prior to the store are visible after the subsequent load, nor the `SeqCst` guarantee of all threads seeing all of the sequentially consistent operations in the same order.

Using `Relaxed` reduces the overhead of `Backtrace::capture()` in the case that backtraces are not enabled.

## Benchmark

```rust
#![feature(backtrace)]

use std::backtrace::Backtrace;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Instant;

fn main() {
    let begin = Instant::now();
    let mut threads = Vec::new();
    for _ in 0..64 {
        threads.push(thread::spawn(|| {
            for _ in 0..10_000_000 {
                let _ = Backtrace::capture();
                static LOL: AtomicUsize = AtomicUsize::new(0);
                LOL.store(1, Ordering::Release);
            }
        }));
    }
    for thread in threads {
        let _ = thread.join();
    }
    println!("{:?}", begin.elapsed());
}
```

**Before:**&ensp;6.73 seconds
**After:**&ensp;5.18 seconds
2021-12-23 00:28:54 +01:00
Matthias Krüger 554ad50fa2
Rollup merge of #92117 - solid-rs:fix-kmc-solid-read-buf, r=yaahc
kmc-solid: Add `std::sys::solid::fs::File::read_buf`

This PR adds `std::sys::solid::fs::File::read_buf` to catch up with the changes introduced by #81156 and fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets..
2021-12-23 00:28:53 +01:00
Matthias Krüger 60625a6ef0
Rollup merge of #88858 - spektom:to_lower_upper_rev, r=dtolnay
Allow reverse iteration of lowercase'd/uppercase'd chars

The PR implements `DoubleEndedIterator` trait for `ToLowercase` and `ToUppercase`.

This enables reverse iteration of lowercase/uppercase variants of character sequences.
One of use cases:  determining whether a char sequence is a suffix of another one.

Example:

```rust
fn endswith_ignore_case(s1: &str, s2: &str) -> bool {
    for eob in s1
        .chars()
        .flat_map(|c| c.to_lowercase())
        .rev()
        .zip_longest(s2.chars().flat_map(|c| c.to_lowercase()).rev())
    {
        match eob {
            EitherOrBoth::Both(c1, c2) => {
                if c1 != c2 {
                    return false;
                }
            }
            EitherOrBoth::Left(_) => return true,
            EitherOrBoth::Right(_) => return false,
        }
    }
    true
}
```
2021-12-23 00:28:51 +01:00
David Tolnay 417b6f354e
Update stability attribute for double ended case mapping iterators 2021-12-22 10:49:51 -08:00
Chris Denton 615604f0c7
Fix tests 2021-12-22 18:31:36 +00:00
Nicholas Nethercote 8217138f44 RawVec: don't recompute capacity after allocating.
Currently it sets the capacity to `ptr.len() / mem::size_of::<T>()`
after any buffer allocation/reallocation. This would be useful if
allocators ever returned a `NonNull<[u8]>` with a size larger than
requested. But this never happens, so it's not useful.

Removing this slightly reduces the size of generated LLVM IR, and
slightly speeds up the hot path of `RawVec` growth.
2021-12-22 05:13:41 +11:00
Mara Bos ad6ef48dd9 Use panic() instead of panic!() in some places in core. 2021-12-21 10:39:00 +01:00
Matthias Krüger 55b494445a
Rollup merge of #92129 - RalfJung:join-handle-docs, r=jyn514
JoinHandle docs: add missing 'the'
2021-12-21 08:33:42 +01:00
Matthias Krüger 4d840a6e45
Rollup merge of #91823 - woppopo:const_ptr_as_ref, r=lcnr
Make `PTR::as_ref` and similar methods `const`.

Tracking issue: #91822
Feature gate: `#![feature(const_ptr_as_ref)]`

```rust
// core::ptr
impl<T: ?Sized> *const T {
    pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>;
    pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>>
    where
        T: Sized;
    pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]>;
}

impl<T: ?Sized> *mut T {
    pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>;
    pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>>
    where
        T: Sized;
    pub const unsafe fn as_mut<'a>(self) -> Option<&'a mut T>;
    pub const unsafe fn as_uninit_mut<'a>(self) -> Option<&'a mut MaybeUninit<T>>
    where
        T: Sized;
    pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]>;
    pub const unsafe fn as_uninit_slice_mut<'a>(self) -> Option<&'a mut [MaybeUninit<T>]>;
}

impl<T: Sized> NonNull<T> {
    pub const unsafe fn as_uninit_ref<'a>(&self) -> &'a MaybeUninit<T>;
    pub const unsafe fn as_uninit_mut<'a>(&mut self) -> &'a mut MaybeUninit<T>;
}

impl<T: ?Sized> NonNull<T> {
    pub const unsafe fn as_ref<'a>(&self) -> &'a T;
    pub const unsafe fn as_mut<'a>(&mut self) -> &'a mut T;
    pub const unsafe fn as_uninit_slice<'a>(&self) -> &'a [MaybeUninit<T>];
    pub const unsafe fn as_uninit_slice_mut<'a>(&self) -> &'a mut [MaybeUninit<T>];
}
```
2021-12-21 08:33:40 +01:00
Matthias Krüger 3009dd7c5a
Rollup merge of #90345 - passcod:entry-insert, r=dtolnay
Stabilise entry_insert

This stabilises `HashMap:Entry::insert_entry` etc. Tracking issue #65225. It will need an FCP.

This was implemented in #64656 two years ago.

This PR includes the rename and change discussed in https://github.com/rust-lang/rust/issues/65225#issuecomment-910652430, happy to split if needed.
2021-12-21 08:33:37 +01:00
Tomoaki Kawada 874514c7b4 kmc-solid: Add `std::sys::solid::fs::File::read_buf`
Catching up with commit 3b263ceb5c
2021-12-21 11:18:35 +09:00
David Tolnay a2fd84a125
Bump insert_entry stabilization to Rust 1.59 2021-12-20 13:14:06 -08:00