about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2020-03-19add basic IP support in HermitCoreStefan Lankes-87/+156
- add initial version to support sockets - use TcpStream as test case - HermitCore uses smoltcp as IP stack for pure Rust applications - further functionalities (e.g. UDP support) will be added step by step
2020-03-19add basic support of OsStrExt for HermitCoreStefan Lankes-1/+54
this patch increases the compatibility to other operating systems
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-16make safety comments more explicitTyPR124-4/+4
2020-03-16corrections on safety commentsTyPR124-3/+3
2020-03-16remove #[inline] for consistency in windows/os_strTyPR124-1/+0
2020-03-16add comments about safetyTyPR124-0/+16
2020-03-16allowing getting &mut OsStr from OsStringTyPR124-0/+31
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
2020-03-12return a pointer to the end of the valid part of the sigstack, no furtheriximeow-5/+7
also unmap the whole thing when cleaning up, rather than leaving a spare page floating around.
2020-03-12unix: Set a guard page at the end of signal stacksiximeow-2/+7
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.
2020-03-12Rollup merge of #69792 - LenaWil:try_reserve_error/impl-error, r=sfacklerMazdak Farrokhzad-0/+3
Implement Error for TryReserveError I noticed that the Error trait wasn't implemented for TryReserveError. (#48043) Not sure if the error messages and code style are 100% correct, it's my first time contributing to the Rust std.
2020-03-10Remove deprecated description function of TryReserveErrorLena Wildervanck-5/+1
2020-03-10Rollup merge of #69799 - TimDiekmann:zst, r=AmanieuMazdak Farrokhzad-11/+36
Allow ZSTs in `AllocRef` Allows ZSTs in all `AllocRef` methods. The implementation of `AllocRef` for `Global` and `System` were adjusted to reflect those changes. This is the second item on the roadmap to support ZSTs in `AllocRef`: https://github.com/rust-lang/wg-allocators/issues/38#issuecomment-595861542 After this has landed, I will adapt `RawVec`, but since this will be a pretty big overhaul, it makes sense to do a different PR for it. ~~Requires #69794 to land first~~ r? @Amanieu
2020-03-10Rollup merge of #69514 - GuillaumeGomez:remove-spotlight, r=kinnisonMazdak Farrokhzad-3/+0
Remove spotlight I had a few comments saying that this feature was at best misunderstood or not even used so I decided to organize a poll about on [twitter](https://twitter.com/imperioworld_/status/1232769353503956994). After 87 votes, the result is very clear: it's not useful. Considering the amount of code we have just to run it, I think it's definitely worth it to remove it. r? @kinnison cc @ollie27
2020-03-10builtin_macros: Add attribute macro `#[cfg_accessible(path)]`Vadim Petrochenkov-0/+10
2020-03-09Write backtrace fmt test using relative pathsDavid Tolnay-5/+5
For some reason the absolute paths were formatted differently on the armhf-gnu target. thread '<unnamed>' panicked at 'assertion failed: `(left == right)` left: `"Backtrace [\n { fn: \"__rust_maybe_catch_panic\" },\n { fn: \"std::rt::lang_start_internal\", file: \"./rust/rt.rs\", line: 300 },\n { fn: \"std::rt::lang_start\", file: \"./rust/rt.rs\", line: 400 },\n]"`, right: `"Backtrace [\n { fn: \"__rust_maybe_catch_panic\" },\n { fn: \"std::rt::lang_start_internal\", file: \"/rust/rt.rs\", line: 300 },\n { fn: \"std::rt::lang_start\", file: \"/rust/rt.rs\", line: 400 },\n]"`', src/libstd/backtrace.rs:486:5
2020-03-09Add test of Debug representation of BacktraceDavid Tolnay-0/+52
2020-03-09Make it possible to instantiate hardcoded Backtrace from testDavid Tolnay-3/+28
2020-03-09Change disabled and unsupported backtraces to print using placeholder styleDavid Tolnay-2/+2
2020-03-09Add quotes around filename in Backtrace debugDavid Tolnay-1/+1
2020-03-09Remove quotes around unknown fn placeholder in backtraceDavid Tolnay-1/+1
2020-03-09Use GetSystemTimePreciseAsFileTime if it is availableDan Aloni-1/+5
2020-03-08unix: Don't override existing SIGSEGV/BUS handlersJosh Stone-8/+20
Although `stack_overflow::init` runs very early in the process, even before `main`, there may already be signal handlers installed for things like the address sanitizer. In that case, just leave it alone, and don't bother trying to allocate our own signal stacks either.
2020-03-08Rollup merge of #69777 - lukas-code:patch-1, r=jonas-schievinkMazdak Farrokhzad-1/+1
Add missing ` in doc for File::with_options()
2020-03-08Allow ZSTs in `AllocRef`Tim Diekmann-11/+36
2020-03-07reduce references on match patterns (clippy::match_ref_pats)Matthias Krüger-5/+5