about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2020-03-26introduce `negative_impls` feature gate and documentNiko Matsakis-0/+1
They used to be covered by `optin_builtin_traits` but negative impls are now applicable to all traits, not just auto traits. This also adds docs in the unstable book for the current state of auto traits.
2020-03-25Rollup merge of #70361 - tmiasko:backtrace, r=Mark-SimulacrumMazdak Farrokhzad-1/+1
Update backtrace crate to 0.3.46 * Support line-tables-only when using libbacktrace * Update libbacktrace to latest master * Define HAVE_KERN_PROC on FreeBSD to fix rust-lang/rust#54434
2020-03-24spaces between braces really ruin readabilityWithout Boats-4/+4
2020-03-24Update backtrace crate to 0.3.46Tomasz Miąsko-1/+1
2020-03-24correct rustc versionWithout Boats-2/+2
2020-03-24IoSlice/IoSliceMut should be Send and SyncWithout Boats-0/+12
2020-03-23Update src/libstd/lib.rsSaoirse Shipwreckt-1/+1
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
2020-03-23Add `wake_trait` feature directive to stdWithout Boats-0/+1
2020-03-23Add Wake trait for safe construction of Wakers.Without Boats-0/+5
Currently, constructing a waker requires calling the unsafe `Waker::from_raw` API. This API requires the user to manually construct a vtable for the waker themself - which is both cumbersome and very error prone. This API would provide an ergonomic, straightforward and guaranteed memory-safe way of constructing a waker. It has been our longstanding intention that the `Waker` type essentially function as an `Arc<dyn Wake>`, with a `Wake` trait as defined here. Two considerations prevented the original API from being shipped as simply an `Arc<dyn Wake>`: - We want to support futures on embedded systems, which may not have an allocator, and in optimized executors for which this API may not be best-suited. Therefore, we have always explicitly supported the maximally-flexible (but also memory-unsafe) `RawWaker` API, and `Waker` has always lived in libcore. - Because `Waker` lives in libcore and `Arc` lives in liballoc, it has not been feasible to provide a constructor for `Waker` from `Arc<dyn Wake>`. Therefore, the Wake trait was left out of the initial version of the task waker API. However, as Rust 1.41, it is possible under the more flexible orphan rules to implement `From<Arc<W>> for Waker where W: Wake` in liballoc. Therefore, we can now define this constructor even though `Waker` lives in libcore. This PR adds these APIs: - A `Wake` trait, which contains two methods - A required method `wake`, which is called by `Waker::wake` - A provided method `wake_by_ref`, which is called by `Waker::wake_by_ref` and which implementors can override if they can optimize this use case. - An implementation of `From<Arc<W>> for Waker where W: Wake + Send + Sync + 'static` - A similar implementation of `From<Arc<W>> for RawWaker`.
2020-03-23Rollup merge of #70207 - hatoo:macos-getentropy, r=dtolnayMazdak Farrokhzad-0/+37
Use getentropy(2) on macos resolves #70179
2020-03-22Rollup merge of #70240 - brain0:thread_id, r=Mark-SimulacrumDylan DPC-2/+2
Return NonZeroU64 from ThreadId::as_u64. As discussed in #67939, this allows turning Option<ThreadId> into Option<NonZeroU64> which can then be stored inside an AtomicU64.
2020-03-21Rollup merge of #70232 - adrian5:patch-1, r=Dylan-DPCDylan DPC-1/+1
Tweak wording for std::io::Read::read function I think the sentence as a whole reads smoother that way.
2020-03-21Rollup merge of #70218 - intgr:fix-deprecated-method-in-docs, r=jonas-schievinkDylan DPC-1/+1
Fix deprecated Error.description() usage in docs
2020-03-21Rollup merge of #70197 - pnkfelix:issue-53957-revise-test-of-23076, ↵Dylan DPC-4/+19
r=LukasKalbertodt For issue 53957: revise unit test to focus on underlying bug of 23076. Fix #53957 by revising unit test to focus on underlying bug of #23076. Namely, this version focuses on the end-to-end behavior that the attempt to create the UDP binding will fail, regardless of the semantics of how particular DNS servers handle junk inputs. (I spent some time trying to create a second more-focused test that would sidestep the DNS resolution, but this is not possible without more invasive changes to the internal infrastructure of `ToSocketAddrs` and what not. It is not worth it.)
2020-03-21Return NonZeroU64 from ThreadId::as_u64.Thomas Bächler-2/+2
As discussed in #67939, this allows turning Option<ThreadId> into Option<NonZeroU64> which can then be stored inside an AtomicU64.
2020-03-21Tweak wording for std::io::Read::read functionadrian5-1/+1
2020-03-21Rollup merge of #69955 - alexcrichton:stderr-infallible, r=sfacklerDylan DPC-100/+101
Fix abort-on-eprintln during process shutdown This commit fixes an issue where if `eprintln!` is used in a TLS destructor it can accidentally cause the process to abort. TLS destructors are executed after `main` returns on the main thread, and at this point we've also deinitialized global `Lazy` values like those which store the `Stderr` and `Stdout` internals. This means that despite handling TLS not being accessible in `eprintln!`, we will fail due to not being able to call `stderr()`. This means that we'll double-panic quickly because panicking also attempt to write to stderr. The fix here is to reimplement the global stderr handle to avoid the need for destruction. This avoids the need for `Lazy` as well as the hidden panic inside of the `stderr` function. Overall this should improve the robustness of printing errors and/or panics in weird situations, since the `stderr` accessor should be infallible in more situations.
2020-03-21Fix deprecated Error.description() usage in docsMarti Raudsepp-1/+1
2020-03-21Use getentropy(2) on macoshatoo-0/+37
2020-03-21Rollup merge of #70187 - matthiaskrgr:cl2ppy, r=Mark-SimulacrumMazdak Farrokhzad-2/+2
more clippy fixes * remove redundant returns (clippy::needless_return) * remove redundant import (clippy::single_component_path_imports) * remove redundant format!() call (clippy::useless_format) * don't use ok() before calling expect() (clippy::ok_expect)
2020-03-21Rollup merge of #69033 - jonas-schievink:resume-with-context, r=tmandryMazdak Farrokhzad-7/+18
Use generator resume arguments in the async/await lowering This removes the TLS requirement from async/await and enables it in `#![no_std]` crates. Closes https://github.com/rust-lang/rust/issues/56974 I'm not confident the HIR lowering is completely correct, there seem to be quite a few undocumented invariants in there. The `async-std` and tokio test suites are passing with these changes though.
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-2/+2
2020-03-20For issue 53957: revise unit tests to focus on underlying bug of 23076.Felix S. Klock II-4/+19
Namely, this version focuses on the end-to-end behavior that the attempt to create the UDP binding will fail, regardless of the semantics of how particular DNS servers handle junk inputs. (I spent some time trying to create a second more-focused test that would sidestep the DNS resolution, but this is not possible without more invasive changes to the internal infrastructure of `ToSocketAddrs` and what not. It is not worth it.)
2020-03-20Fix abort-on-eprintln during process shutdownAlex Crichton-100/+101
This commit fixes an issue where if `eprintln!` is used in a TLS destructor it can accidentally cause the process to abort. TLS destructors are executed after `main` returns on the main thread, and at this point we've also deinitialized global `Lazy` values like those which store the `Stderr` and `Stdout` internals. This means that despite handling TLS not being accessible in `eprintln!`, we will fail due to not being able to call `stderr()`. This means that we'll double-panic quickly because panicking also attempt to write to stderr. The fix here is to reimplement the global stderr handle to avoid the need for destruction. This avoids the need for `Lazy` as well as the hidden panic inside of the `stderr` function. Overall this should improve the robustness of printing errors and/or panics in weird situations, since the `stderr` accessor should be infallible in more situations.
2020-03-19doc: Add quote to .init_arraylzutao-4/+4
2020-03-19Rollup merge of #69969 - iximeow:sigstack-guard-page, r=cuviperMazdak Farrokhzad-5/+18
unix: Set a guard page at the end of signal stacks This mitigates possible issues when signal stacks overflow, which could manifest as segfaults or in unlucky circumstances possible clobbering of other memory values as stack overflows tend to enable. I went ahead and made a PR for this because it's a pretty small change, though if I should open an issue/RFC for this and discuss there first I'll happily do so. I've also added some example programs that demonstrate the uncomfortably clobber-happy behavior we currently have, and the segfaults that could/should result instead, [here](https://github.com/iximeow/jubilant-train).
2020-03-19Rollup merge of #69959 - alexcrichton:fix-panic-in-print, r=Mark-SimulacrumMazdak Farrokhzad-4/+8
std: Don't abort process when printing panics in tests This commit fixes an issue when using `set_print` and friends, notably used by libtest, to avoid aborting the process if printing panics. This previously panicked due to borrowing a mutable `RefCell` twice, and this is worked around by borrowing these cells for less time, instead taking out and removing contents temporarily. Closes #69558
2020-03-18Rollup merge of #67749 - gilescope:keyword-in, r=Dylan-DPCMazdak Farrokhzad-5/+56
keyword docs for else and inkeyword docs for else and in. First cut of else and in keyword docs. Comments and suggestions more than welcome.
2020-03-18std: Don't abort process when printing panics in testsAlex Crichton-4/+8
This commit fixes an issue when using `set_print` and friends, notably used by libtest, to avoid aborting the process if printing panics. This previously panicked due to borrowing a mutable `RefCell` twice, and this is worked around by borrowing these cells for less time, instead taking out and removing contents temporarily. Closes #69558
2020-03-17Add futures scaffolding to libcoreJonas Schievink-7/+18
2020-03-17Rollup merge of #70046 - lzutao:patch-1, r=CentrilMazdak Farrokhzad-12/+4
Use sublice patterns to avoid computing the len r? @Centril
2020-03-17Rollup merge of #70029 - jonas-schievink:bootstrap, r=CentrilMazdak Farrokhzad-4/+1
Bump the bootstrap compiler
2020-03-17Rollup merge of #69870 - petrochenkov:cfgacc, r=matthewjasperMazdak Farrokhzad-0/+10
expand: Implement something similar to `#[cfg(accessible(path))]` cc https://github.com/rust-lang/rust/issues/64797 The feature is implemented as a `#[cfg_accessible(path)]` attribute macro rather than as `#[cfg(accessible(path))]` because it needs to wait until `path` becomes resolvable, and `cfg` cannot wait, but macros can wait. Later we can think about desugaring or not desugaring `#[cfg(accessible(path))]` into `#[cfg_accessible(path)]`. This implementation is also incomplete in the sense that it never returns "false" from `cfg_accessible(path)`, it requires some tweaks to resolve, which is not quite ready to answer queries like this during early resolution. However, the most important part of this PR is not `cfg_accessible` itself, but expansion infrastructure for retrying expansions. Before this PR we could say "we cannot resolve this macro path, let's try it later", with this PR we can say "we cannot expand this macro, let's try it later" as well. This is a pre-requisite for - turning `#[derive(...)]` into a regular attribute macro, - properly supporting eager expansion for macros that cannot yet be resolved like ``` fn main() { println!(not_available_yet!()); } macro_rules! make_available { () => { #[macro_export] macro_rules! not_available_yet { () => { "Hello world!" } }} } make_available!(); ```
2020-03-16Auto merge of #68970 - matthewjasper:min-spec, r=nikomatsakisbors-1/+2
Implement a feature for a sound specialization subset This implements a new feature (`min_specialization`) that restricts specialization to a subset that is reasonable for the standard library to use. The plan is to then: * Update `libcore` and `liballoc` to compile with `min_specialization`. * Add a lint to forbid use of `feature(specialization)` (and other unsound, type system extending features) in the standard library. * Fix the soundness issues around `specialization`. * Remove `min_specialization` The rest of this is an overview from a comment in this PR ## Basic approach To enforce this requirement on specializations we take the following approach: 1. Match up the substs for `impl2` so that the implemented trait and self-type match those for `impl1`. 2. Check for any direct use of `'static` in the substs of `impl2`. 3. Check that all of the generic parameters of `impl1` occur at most once in the *unconstrained* substs for `impl2`. A parameter is constrained if its value is completely determined by an associated type projection predicate. 4. Check that all predicates on `impl1` also exist on `impl2` (after matching substs). ## Example Suppose we have the following always applicable impl: ```rust impl<T> SpecExtend<T> for std::vec::IntoIter<T> { /* specialized impl */ } impl<T, I: Iterator<Item=T>> SpecExtend<T> for I { /* default impl */ } ``` We get that the subst for `impl2` are `[T, std::vec::IntoIter<T>]`. `T` is constrained to be `<I as Iterator>::Item`, so we check only `std::vec::IntoIter<T>` for repeated parameters, which it doesn't have. The predicates of `impl1` are only `T: Sized`, which is also a predicate of impl2`. So this specialization is sound. ## Extensions Unfortunately not all specializations in the standard library are allowed by this. So there are two extensions to these rules that allow specializing on some traits. ### rustc_specialization_trait If a trait is always applicable, then it's sound to specialize on it. We check trait is always applicable in the same way as impls, except that step 4 is now "all predicates on `impl1` are always applicable". We require that `specialization` or `min_specialization` is enabled to implement these traits. ### rustc_specialization_marker There are also some specialization on traits with no methods, including the `FusedIterator` trait which is advertised as allowing optimizations. We allow marking marker traits with an unstable attribute that means we ignore them in point 3 of the checks above. This is unsound but we allow it in the short term because it can't cause use after frees with purely safe code in the same way as specializing on traits methods can. r? @nikomatsakis cc #31844 #67194
2020-03-16Fix wrong dereflzutao-2/+2
2020-03-16Use sublice patterns to avoid computing the lenlzutao-12/+4
2020-03-16Rollup merge of #69122 - dtolnay:backtrace, r=cramertjDylan DPC-7/+84
Backtrace Debug tweaks - Change Debug representation of disabled and unsupported backtraces to use \<placeholder\> style, same as what we do for debug printing locked mutexes and mutably borrowed refcells; ```diff - Error { msg: "...", backtrace: disabled backtrace } + Error { msg: "...", backtrace: <disabled> } ``` - Remove quotes around unresolved symbol names; ```diff - Backtrace [{ fn: "<unknown>" }] + Backtrace [{ fn: <unknown> }] ``` - Add quotes around file paths; ```diff - Backtrace [{ fn: "krate::main", file: /path/to/main.rs, line: 10 }] + Backtrace [{ fn: "krate::main", file: "/path/to/main.rs", line: 10 }] ``` - Add test.
2020-03-16Auto merge of #70010 - Amanieu:fix-opt-catch, r=Mark-Simulacrumbors-26/+28
Add a workaround for catch_unwind in stage1 mingw target Fixes #70001 cc @petrochenkov r? @Mark-Simulacrum
2020-03-16Rollup merge of #69858 - da-x:windows-precise-time, r=Dylan-DPCDylan DPC-1/+5
std: on Windows, use GetSystemTimePreciseAsFileTime if it is available This implements #67266.
2020-03-15Bump the bootstrap compilerJonas Schievink-4/+1
2020-03-15Use min_specialization in libstd and libproc_macroMatthew Jasper-1/+2
2020-03-15Fix "since" field for `Once::is_complete`'s `#[stable]` attributeLukas Kalbertodt-1/+1
It was accidentally merged with the wrong version.
2020-03-14Add a workaround for catch_unwind in stage1 mingw targetAmanieu d'Antras-26/+28
Fixes #70001
2020-03-14update panicking comments in libstdRalf Jung-8/+7
2020-03-13Auto merge of #67502 - Mark-Simulacrum:opt-catch, r=Mark-Simulacrumbors-26/+66
Optimize catch_unwind to match C++ try/catch This refactors the implementation of catching unwinds to allow LLVM to inline the "try" closure directly into the happy path, avoiding indirection. This means that the catch_unwind implementation is (after this PR) zero-cost unless a panic is thrown. https://rust.godbolt.org/z/cZcUSB is an example of the current codegen in a simple case. Notably, the codegen is *exactly the same* if `-Cpanic=abort` is passed, which is clearly not great. This PR, on the other hand, generates the following assembly: ```asm # -Cpanic=unwind: push rbx mov ebx,0x2a call QWORD PTR [rip+0x1c53c] # <happy> mov eax,ebx pop rbx ret mov rdi,rax call QWORD PTR [rip+0x1c537] # cleanup function call call QWORD PTR [rip+0x1c539] # <unfortunate> mov ebx,0xd mov eax,ebx pop rbx ret # -Cpanic=abort: push rax call QWORD PTR [rip+0x20a1] # <happy> mov eax,0x2a pop rcx ret ``` Fixes #64224, and resolves #64222.
2020-03-14Rollup merge of #69802 - matthiaskrgr:cl1ppy, r=Dylan-DPCYuki Okushi-6/+6
fix more clippy findings * reduce references on match patterns (clippy::match_ref_pats) * Use writeln!(fmt, "word") instead of write!(fmt, "word\n") (clippy::write_with_newline) * libtest: remove redundant argument to writeln!() (clippy::writeln_empty_string) * remove unneeded mutable references (cippy::unnecessary_mut_passed) * libtest: declare variables as floats instead of casting them (clippy::unnecessary_cast) * rustdoc: remove redundant static lifetimes (clippy::redundant_static_lifetimes) * call .as_deref() instead of .as_ref().map(Deref::deref) (clippy::option_as_ref_deref) * iterate over a maps values directly. (clippy::for_kv_map) * rustdoc: simplify boolean condition (clippy::nonminimal_bool) * Use ?-operator in more places (clippy::question_mark, had some false negatives fixed recently) * rustdoc: Use .any(p) instead of find(p).is_some(). (clippy::search_is_some) * rustdoc: don't call into_iter() on iterator. (clippy::identity_conversion)
2020-03-14Rollup merge of #69723 - sjud:sjud-doc-request, r=Mark-SimulacrumYuki Okushi-2/+8
Added doc on keyword Pub. Hi, this is my first pull request. I hope it's OK. Please let me know if it would benefit from any changes. Thank you.
2020-03-14Rollup merge of #69403 - LeSeulArtichaut:copy-ioslice, r=sfacklerYuki Okushi-0/+10
Implement `Copy` for `IoSlice` Resolves #69395 r? @sfackler
2020-03-13Add documentation for pub keywordsjud-2/+8
2020-03-12fix formattingiximeow-2/+8