about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-10-28Revert "Add rustc lint, warning when iterating over hashmaps"Mark Rousskov-20/+0
2021-10-27Fix broken doctestSean Chen-2/+2
2021-10-27Auto merge of #90347 - matthiaskrgr:rollup-rp2ms7j, r=matthiaskrgrbors-1/+1
Rollup of 5 pull requests Successful merges: - #90239 (Consistent big O notation in map.rs) - #90267 (fix: inner attribute followed by outer attribute causing ICE) - #90288 (Add hint for people missing `TryFrom`, `TryInto`, `FromIterator` import pre-2021) - #90304 (Add regression test for #75961) - #90344 (Add tracking issue number to const_cstr_unchecked) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-10-27Format doctestSean Chen-45/+10
2021-10-27Add `rust` annotation to doctestSean Chen-1/+1
2021-10-27Attempt to fix tidy errorsSean Chen-79/+345
2021-10-27Auto merge of #90273 - nbdd0121:const, r=fee1-deadbors-1/+3
Clean up special function const checks Mark them as const and `#[rustc_do_not_const_check]` instead of hard-coding them in const-eval checks. r? `@oli-obk` `@rustbot` label A-const-eval T-compiler
2021-10-28Stabilise entry_insertFélix Saparelli-4/+2
Signed-off-by: Félix Saparelli <felix@passcod.name>
2021-10-28Update doctests for renamesFélix Saparelli-2/+2
2021-10-28Expose HashMap:VacantEntry:insert_entryFélix Saparelli-1/+3
2021-10-28Rename HashMap:Entry:insert to :insert_entryFélix Saparelli-1/+1
2021-10-27Add tracking issue number to const_cstr_uncheckedKonrad Borowski-1/+1
2021-10-27Rollup merge of #90154 - camelid:remove-getdefid, r=jyn514Matthias Krüger-1/+1
rustdoc: Remove `GetDefId` See the individual commit messages for details. r? `@jyn514`
2021-10-26Clarify platform availability of GetTempPath2Eugene Talagrand-1/+1
Windows Server 2022 is a different version from Win11, breaking precent
2021-10-26Rollup merge of #90296 - CAD97:rip-lerp, r=Mark-SimulacrumMatthias Krüger-191/+0
Remove fNN::lerp Lerp is [surprisingly complex with multiple tradeoffs depending on what guarantees you want to provide](https://github.com/rust-lang/rust/issues/86269#issuecomment-869108301) (and what you're willing to drop for raw speed), so we don't have consensus on what implementation to use, let alone what signature - `t.lerp(a, b)` nicely puts `a, b` together, but makes dispatch to lerp custom types with the same signature basically impossible, and major ecosystem crates (e.g. nalgebra, glium) use `a.lerp(b, t)`, which is easily confusable. It was suggested to maybe provide a `Lerp<T>` trait and `t.lerp([a, b])`, which _could_ be implemented by downstream math libraries for their types, but also significantly raises the bar from a simple fNN method to a full trait, and does nothing to solve the implementation question. (It also raises the question of whether we'd support higher-order bezier interpolation.) The only consensus we have is the lack of consensus, and the [general temperature](https://github.com/rust-lang/rust/issues/86269#issuecomment-951347135) is that we should just remove this method (giving the method space back to 3rd party libs) and revisit this if (and likely only if) IEEE adds lerp to their specification. If people want a lerp, they're _probably_ already using (or writing) a math support library, which provides a lerp function for its custom math types and can provide the same lerp implementation for the primitive types via an extension trait. See also [previous Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/lerp.20API.20design) cc ``@clarfonthey`` (original PR author), ``@m-ou-se`` (original r+), ``@scottmcm`` (last voice in tracking issue, prompted me to post this) Closes #86269 (removed)
2021-10-26Remove redundant AlignerTony Yang-5/+2
The `Aligner` struct seems to be unnecessary. Previously noted by @arthurprs https://github.com/rust-lang/rust/pull/44963#discussion_r145340754 Reddit discussion: https://www.reddit.com/r/rust/comments/pfvvz2/aligner_and_cachealigned/ Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fa7ca554922755f9d1b62b017d785c6f
2021-10-25Remove fNN::lerp - consensus unlikelyCAD97-191/+0
2021-10-25Clean up special function const checksGary Guo-1/+3
Mark them as const and `#[rustc_do_not_const_check]` instead of hard-coding them in const-eval checks.
2021-10-25Auto merge of #90042 - pietroalbini:1.56-master, r=Mark-Simulacrumbors-2/+2
Bump bootstrap compiler to 1.57 Fixes https://github.com/rust-lang/rust/issues/90152 r? `@Mark-Simulacrum`
2021-10-24Rollup merge of #89558 - lcnr:query-stable-lint, r=estebankMatthias Krüger-0/+20
Add rustc lint, warning when iterating over hashmaps r? rust-lang/wg-incr-comp
2021-10-23update cfg(bootstrap)Pietro Albini-2/+2
2021-10-23Fix typoChris Denton-1/+1
Co-authored-by: Ruslan Sayfutdinov <ruslan@sayfutdinov.com>
2021-10-23Make sure `CreateDirectoryW` works for path lengths > 247Chris Denton-1/+41
2021-10-23Add caveat about changing parallelism and function call overheadThe8472-0/+4
2021-10-23Rollup merge of #90166 - smmalis37:patch-1, r=joshtriplettMatthias Krüger-0/+4
Add comment documenting why we can't use a simpler solution See #90144 for context. r? ```@joshtriplett```
2021-10-23Rollup merge of #88300 - ijackson:exitstatusext-methods, r=yaahcMatthias Krüger-4/+4
Stabilise unix_process_wait_more, extra ExitStatusExt methods This stabilises the feature `unix_process_wait_more`. Tracking issue #80695, FCP needed. This was implemented in #79982 and merged in January.
2021-10-22docs: Escape brackets to satisfy the linkcheckerNoah Lev-1/+1
My change to use `Type::def_id()` (formerly `Type::def_id_full()`) in more places caused some docs to show up that used to be missed by rustdoc. Those docs contained unescaped square brackets, which triggered linkcheck errors. This commit escapes the square brackets and adds this particular instance to the linkcheck exception list.
2021-10-22Auto merge of #90007 - xfix:inline-cstr-from-str, r=kennytmbors-0/+1
Inline CStr::from_ptr Inlining this function is valuable, as it allows LLVM to apply `strlen`-specific optimizations without having to enable LTO. For instance, the following function: ```rust pub fn f(p: *const c_char) -> Option<u8> { unsafe { CStr::from_ptr(p) }.to_bytes().get(0).copied() } ``` Looks like this if `CStr::from_ptr` is allowed to be inlined. ```asm before: push rax call qword ptr [rip + std::ffi::c_str::CStr::from_ptr@GOTPCREL] mov rcx, rax cmp rdx, 1 sete dl test rax, rax sete al or al, dl jne .LBB1_2 mov dl, byte ptr [rcx] .LBB1_2: xor al, 1 pop rcx ret after: mov dl, byte ptr [rdi] test dl, dl setne al ret ``` Note that optimization turned this from O(N) to O(1) in terms of performance, as LLVM knows that it doesn't really need to call `strlen` to determine whether a string is empty or not.
2021-10-22Change `source` field to `error`Sean Chen-8/+8
2021-10-22Have `pretty` and `show_backtrace` accept booleansSean Chen-5/+5
2021-10-22Apply suggestions from code reviewJane Lusby-4/+4
2021-10-22Try commiting againSean Chen-1/+244
2021-10-22Add comment documenting why we can't use a simpler solutionSteven-0/+4
See #90144 for context. r? @joshtriplett
2021-10-22Rollup merge of #89665 - seanyoung:push-empty, r=m-ou-seYuki Okushi-1/+5
Ensure that pushing empty path works as before on verbatim paths Fixes: https://github.com/rust-lang/rust/issues/89658 Signed-off-by: Sean Young <sean@mess.org>
2021-10-22Rollup merge of #88624 - kellerkindt:master, r=JohnTitorYuki Okushi-1/+0
Stabilize feature `saturating_div` for rust 1.58.0 The tracking issue is #89381 This seems like a reasonable simple change(?). The feature `saturating_div` was added as part of the ongoing effort to implement a `Saturating` integer type (see #87921). The implementation has been discussed [here](https://github.com/rust-lang/rust/pull/87921#issuecomment-899357720) and [here](https://github.com/rust-lang/rust/pull/87921#discussion_r691888556). It extends the list of saturating operations on integer types (like `saturating_add`, `saturating_sub`, `saturating_mul`, ...) by the function `fn saturating_div(self, rhs: Self) -> Self`. The stabilization of the feature `saturating_int_impl` (for the `Saturating` type) needs to have this stabilized first. Closes #89381
2021-10-21Stabilize feature saturating_div for rust 1.58Michael Watzko-1/+0
2021-10-21Clarify undefined behaviour for binary heap, btree and hashsetWilfred Hughes-2/+2
Previously, it wasn't clear whether "This could include" was referring to logic errors, or undefined behaviour. Tweak wording to clarify this sentence does not relate to UB.
2021-10-21Rollup merge of #89292 - CleanCut:stabilize-cstring_from_vec_with_nul, ↵Yuki Okushi-13/+9
r=JohnTitor Stabilize CString::from_vec_with_nul[_unchecked] Closes the tracking issue #73179. I am keeping this in _draft_ mode until the FCP has ended. This is my first time stabilizing a feature, so I would appreciate any guidance on things I should do differently. Closes #73179
2021-10-21Rollup merge of #87440 - twetzel59:fix-barrier-no-op, r=yaahcYuki Okushi-1/+1
Remove unnecessary condition in Barrier::wait() This is my first pull request for Rust, so feel free to call me out if anything is amiss. After some examination, I realized that the second condition of the "spurious-wakeup-handler" loop in ``std::sync::Barrier::wait()`` should always evaluate to ``true``, making it redundant in the ``&&`` expression. Here is the affected function before the fix: ```rust #[stable(feature = "rust1", since = "1.0.0")] pub fn wait(&self) -> BarrierWaitResult { let mut lock = self.lock.lock().unwrap(); let local_gen = lock.generation_id; lock.count += 1; if lock.count < self.num_threads { // We need a while loop to guard against spurious wakeups. // https://en.wikipedia.org/wiki/Spurious_wakeup while local_gen == lock.generation_id && lock.count < self.num_threads { // fixme lock = self.cvar.wait(lock).unwrap(); } BarrierWaitResult(false) } else { lock.count = 0; lock.generation_id = lock.generation_id.wrapping_add(1); self.cvar.notify_all(); BarrierWaitResult(true) } } ``` At first glance, it seems that the check that ``lock.count < self.num_threads`` would be necessary in order for a thread A to detect when another thread B has caused the barrier to reach its thread count, making thread B the "leader". However, the control flow implicitly results in an invariant that makes observing ``!(lock.count < self.num_threads)``, i.e. ``lock.count >= self.num_threads`` impossible from thread A. When thread B, which will be the leader, calls ``.wait()`` on this shared instance of the ``Barrier``, it locks the mutex in the first line and saves the ``MutexGuard`` in the ``lock`` variable. It then increments the value of ``lock.count``. However, it then proceeds to check if ``lock.count < self.num_threads``. Since it is the leader, it is the case that (after the increment of ``lock.count``), the lock count is *equal* to the number of threads. Thus, the second branch is immediately taken and ``lock.count`` is zeroed. Additionally, the generation ID is incremented (with wrap). Then, the condition variable is signalled. But, the other threads are waiting at the line ``lock = self.cvar.wait(lock).unwrap();``, so they cannot resume until thread B's call to ``Barrier::wait()`` returns, which drops the ``MutexGuard`` acquired in the first ``let`` statement and unlocks the mutex. The order of events is thus: 1. A thread A calls `.wait()` 2. `.wait()` acquires the mutex, increments `lock.count`, and takes the first branch 3. Thread A enters the ``while`` loop since the generation ID has not changed and the count is less than the number of threads for the ``Barrier`` 3. Spurious wakeups occur, but both conditions hold, so the thread A waits on the condition variable 4. This process repeats for N - 2 additional times for non-leader threads A' 5. *Meanwhile*, Thread B calls ``Barrier::wait()`` on the same barrier that threads A, A', A'', etc. are waiting on. The thread count reaches the number of threads for the ``Barrier``, so all threads should now proceed, with B being the leader. B acquires the mutex and increments the value ``lock.count`` only to find that it is not less than ``self.num_threads``. Thus, it immediately clamps ``self.num_threads`` back down to 0 and increments the generation. Then, it signals the condvar to tell the A (prime) threads that they may continue. 6. The A, A', A''... threads wake up and attempt to re-acquire the ``lock`` as per the internal operation of a condition variable. When each A has exclusive access to the mutex, it finds that ``lock.generation_id`` no longer matches ``local_generation`` **and the ``&&`` expression short-circuits -- and even if it were to evaluate it, ``self.count`` is definitely less than ``self.num_threads`` because it has been reset to ``0`` by thread B *before* B dropped its ``MutexGuard``**. Therefore, it my understanding that it would be impossible for the non-leader threads to ever see the second boolean expression evaluate to anything other than ``true``. This PR simply removes that condition. Any input would be appreciated. Sorry if this is terribly verbose. I'm new to the Rust community and concurrency can be hard to explain in words. Thanks!
2021-10-21Rollup merge of #86984 - Smittyvb:ipv4-octal-zero, r=m-ou-seYuki Okushi-10/+32
Reject octal zeros in IPv4 addresses This fixes #86964 by rejecting octal zeros in IP addresses, such that `192.168.00.00000000` is rejected with a parse error, since having leading zeros in front of another zero indicates it is a zero written in octal notation, which is not allowed in the strict mode specified by RFC 6943 3.1.1. Octal rejection was implemented in #83652, but due to the way it was implemented octal zeros were still allowed.
2021-10-20fix 'since' version numberNathan Stocks-1/+1
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
2021-10-20stabilize CString::from_vec_with_nul[_unchecked]Nathan Stocks-13/+9
2021-10-20Rollup merge of #88860 - nbdd0121:panic, r=m-ou-seYuki Okushi-27/+5
Deduplicate panic_fmt std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2021-10-19Deduplicate panic_fmtGary Guo-27/+5
std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2021-10-18Update std::env::temp_dir to use GetTempPath2 on Windows when available.Eugene Talagrand-13/+16
As a security measure, Windows 11 introduces a new temporary directory API, GetTempPath2. When the calling process is running as SYSTEM, a separate temporary directory will be returned inaccessible to non-SYSTEM processes. For non-SYSTEM processes the behavior will be the same as before.
2021-10-19Rollup merge of #89941 - hermitcore:kernel, r=joshtriplettMatthias Krüger-1/+1
removing TLS support in x86_64-unknown-none-hermitkernel HermitCore's kernel itself doesn't support TLS. Consequently, the entries in x86_64-unknown-none-hermitkernel should be removed. This commit should help to finalize #89062.
2021-10-18Inline CStr::from_ptrKonrad Borowski-0/+1
2021-10-17Auto merge of #88652 - AGSaidi:linux-aarch64-should-be-actually-monotonic, ↵bors-0/+15
r=yaahc linux/aarch64 Now() should be actually_monotonic() While issues have been seen on arm64 platforms the Arm architecture requires that the counter monotonically increases and that it must provide a uniform view of system time (e.g. it must not be possible for a core to receive a message from another core with a time stamp and observe time going backwards (ARM DDI 0487G.b D11.1.2). While there have been a few 64bit SoCs that have bugs (#49281, #56940) which cause time to not monotonically increase, these have been fixed in the Linux kernel and we shouldn't penalize all Arm SoCs for those who refuse to update their kernels: SUN50I_ERRATUM_UNKNOWN1 - Allwinner A64 / Pine A64 - fixed in 5.1 FSL_ERRATUM_A008585 - Freescale LS2080A/LS1043A - fixed in 4.10 HISILICON_ERRATUM_161010101 - Hisilicon 1610 - fixed in 4.11 ARM64_ERRATUM_858921 - Cortex A73 - fixed in 4.12 255a3f3e183 std: Force `Instant::now()` to be monotonic added a Mutex to work around this problem and a small test program using glommio shows the majority of time spent acquiring and releasing this Mutex. 3914a7b0da8 tries to improve this, but actually makes it worse on big systems as for 128b atomics a ldxp/stxp pair (and successful loop) for v8.4 systems that don't support FEAT_LSE2 is required which is expensive as a lock and because of how the load/store-exclusives scale on large Arm systems is both unfair to threads and tends to go backwards in performance. A small sample program using glommio improves by 70x on a 32 core Graviton2 system with this change.
2021-10-16remove compiler warningsStefan Lankes-1/+1
2021-10-16Rollup merge of #89921 - joshuaseaton:zircon-process, r=tmandryMatthias Krüger-4/+7
[fuchsia] Update process info struct The fuchsia platform is in the process of softly transitioning over to using a new value for ZX_INFO_PROCESS with a new corresponding struct. This change migrates libstd. See [fxrev.dev/510478](https://fxrev.dev/510478) and [fxbug.dev/30751](https://fxbug.dev/30751) for more detail.