about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2017-12-10Update never_type docs based on feedbackAndrew Cann-1/+2
2017-12-09Use Try syntax for Option in place of macros or matchMatt Brubeck-35/+13
2017-12-08Auto merge of #45837 - SimonSapin:file_read_write, r=dtolnaybors-1/+134
Add read, read_string, and write functions to std::fs New APIs in `std::fs`: ```rust pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { … } pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> { … } pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { ... } ``` (`read_string` is based on `read_to_string` and so returns an error on non-UTF-8 content.) Before: ```rust use std::fs::File; use std::io::Read; let mut bytes = Vec::new(); File::open(filename)?.read_to_end(&mut bytes)?; do_something_with(bytes) ``` After: ```rust use std::fs; do_something_with(fs::read(filename)?) ```
2017-12-08fs::{read, read_string, write}: add tracking issue numberSimon Sapin-3/+3
2017-12-07Rollup merge of #46416 - liigo:cfg-macro, r=steveklabnikGuillaume Gomez-1/+1
doc: macro `cfg!` evaluating at compile-time
2017-12-06Rename fs::read_utf8 to read_stringSimon Sapin-4/+4
2017-12-06Update miri to rustc changesOliver Schneider-2454/+5628
2017-12-05compile_error example blurbsHavvy-0/+5
2017-12-05No unused macro warning in compile_error example.Havvy-1/+4
2017-12-04Give compile_error macro examplesHavvy-2/+19
2017-12-04Auto merge of #46485 - khuey:cursor-read_exact, r=Manishearthbors-0/+25
Add a specialization of read_exact for Cursor. The read_exact implementation for &[u8] is optimized and usually allows LLVM to reduce a read_exact call for small numbers of bytes to a bounds check and a register load instead of a generic memcpy. On a workload I have that decompresses, deserializes (via bincode), and processes some data, this leads to a 40% speedup by essentially eliminating the deserialization overhead entirely.
2017-12-03Add a specialization of read_exact for Cursor.Kyle Huey-0/+25
The read_exact implementation for &[u8] is optimized and usually allows LLVM to reduce a read_exact call for small numbers of bytes to a bounds check and a register load instead of a generic memcpy. On a workload I have that decompresses, deserializes (via bincode), and processes some data, this leads to a 40% speedup by essentially eliminating the deserialization overhead entirely.
2017-12-03Rollup merge of #46260 - ExpHP:builtin-macro-doc-sync, r=steveklabnikCorey Farwell-6/+14
Make doc stubs for builtin macros reflect existing support for trailing commas This modifies the `macro_rules!` stubs in `std` for some of the compiler builtin macros in order to better reflect their currently supported grammar. To my understanding these stubs have no impact on compiler output whatsoever, and only exist so that they may appear in the documentation. P.S. It is in fact true that `env!` supports trailing commas while `option_env!` currently does not. (I have another issue for this) I don't imagine there's any way to automatically test these stubs, but I did *informally* test the new definitions on the playpen to see that they accept the desired invocations, as well as inspect the updated doc output.
2017-12-02Auto merge of #46382 - alexcrichton:thinlto-default, r=michaelwoeristerbors-2/+20
rustc: Prepare to enable ThinLTO by default This commit *almost* enables ThinLTO and multiple codegen units in release mode by default but is blocked on #46346 now before pulling the trigger.
2017-12-02Auto merge of #46288 - alexcrichton:bump-bootstrap, r=Mark-Simulacrumbors-200/+0
Bump to 1.24.0 * Update the in-tree version number * Update the bootstrap compiler * Remove `cfg(stage0)` annotations * Update crate dependencies * Update Cargo itself
2017-12-01doc: macro `cfg!` evaluating at compile-timeLiigo Zhuang-1/+1
2017-11-30NetBSD: add sysctl backend for std::env::current_exeJonathan A. Kollasch-1/+28
Use the CTL_KERN.KERN_PROC_ARGS.-1.KERN_PROC_PATHNAME sysctl in preference over the /proc/curproc/exe symlink. Additionally, perform more validation of aformentioned symlink. Particularly on pre-8.x NetBSD this symlink will point to '/' when accurate information is unavailable.
2017-11-30rustc: Prepare to enable ThinLTO by defaultAlex Crichton-2/+20
This commit prepares to enable ThinLTO and multiple codegen units in release mode by default. We've still got a debuginfo bug or two to sort out before actually turning it on by default.
2017-11-29Update bootstrap compilerAlex Crichton-200/+0
Also remove a number of `stage0` annotations and such
2017-11-29Generalize fs::write from &[u8] to AsRef<[u8]>Simon Sapin-3/+3
2017-11-29Rollup merge of #46323 - ia0:fix_mpsc_error_conv, r=kennytmkennytm-3/+3
Fix since for mpsc_error_conversions This is a followup of #45506.
2017-11-29Rollup merge of #46287 - SimonSapin:stable-constness, r=aturonkennytm-12/+0
Stabilize const-calling existing const-fns in std Fixes #46038
2017-11-29Rollup merge of #46077 - LukasKalbertodt:stabilize-ascii-ctype, r=alexcrichtonkennytm-43/+166
Stabilize some `ascii_ctype` methods As discussed in #39658, this PR stabilizes those methods for `u8` and `char`. All inherent `ascii_ctype` for `[u8]` and `str` are removed as we prefer the more explicit version `s.chars().all(|c| c.is_ascii_())`. This PR doesn't modify the `AsciiExt` trait. There, the `ascii_ctype` methods are still unstable. It is planned to remove those in the future (I think). I had to modify some code in `ascii.rs` to properly implement `AsciiExt` for all types. Fixes #39658.
2017-11-29Rollup merge of #45969 - ia0:mpsc_recv_deadline, r=alexcrichtonkennytm-2/+63
Add std::sync::mpsc::Receiver::recv_deadline() Essentially renames recv_max_until to recv_deadline (mostly copying recv_timeout documentation). This function is useful to avoid the often unnecessary call to Instant::now in recv_timeout (e.g. when the user already has a deadline). A concrete example would be something along those lines: ```rust use std::sync::mpsc::Receiver; use std::time::{Duration, Instant}; /// Reads a batch of elements /// /// Returns as soon as `max_size` elements have been received or `timeout` expires. fn recv_batch_timeout<T>(receiver: &Receiver<T>, timeout: Duration, max_size: usize) -> Vec<T> { recv_batch_deadline(receiver, Instant::now() + timeout, max_size) } /// Reads a batch of elements /// /// Returns as soon as `max_size` elements have been received or `deadline` is reached. fn recv_batch_deadline<T>(receiver: &Receiver<T>, deadline: Instant, max_size: usize) -> Vec<T> { let mut result = Vec::new(); while let Ok(x) = receiver.recv_deadline(deadline) { result.push(x); if result.len() == max_size { break; } } result } ```
2017-11-28Fix doc test of previous commitJulien Cretin-0/+2
2017-11-28Add more links to `!` doc textAndrew Cann-18/+28
2017-11-28Fix since for mpsc_error_conversionsJulien Cretin-3/+3
2017-11-27Use an unstable feature linked to #46316Julien Cretin-1/+1
2017-11-28Rollup merge of #45506 - ia0:mpsc_recv_error_from, r=alexcrichtonkennytm-0/+27
Implement From<RecvError> for TryRecvError and RecvTimeoutError According to the documentation, it looks to me that `TryRecvError` and `RecvTimeoutError` are strict extensions of `RecvError`. As such, it makes sense to allow conversion from the latter type to the two former types without constraining future developments. This permits to write `input.recv()?` and `input.recv_timeout(timeout)?` in the same function for example.
2017-11-26Stabilize const-calling existing const-fns in stdSimon Sapin-12/+0
Fixes #46038
2017-11-26fix NetBSDAriel Ben-Yehuda-1/+2
2017-11-26Auto merge of #46272 - kennytm:rollup, r=kennytmbors-2/+1
Rollup of 7 pull requests - Successful merges: #46201, #46224, #46234, #46252, #46259, #46264, #46269 - Failed merges:
2017-11-26Rollup merge of #46224 - GuillaumeGomez:io-missing-link, r=QuietMisdreavuskennytm-2/+1
Remove invalid doc link r? @rust-lang/docs
2017-11-25Implement `Rc`/`Arc` conversions for string-like typesMurarth-0/+283
Provides the following conversion implementations: * `From<`{`CString`,`&CStr`}`>` for {`Arc`,`Rc`}`<CStr>` * `From<`{`OsString`,`&OsStr`}`>` for {`Arc`,`Rc`}`<OsStr>` * `From<`{`PathBuf`,`&Path`}`>` for {`Arc`,`Rc`}`<Path>`
2017-11-25Make builtin macro doc stubs more accurateMichael Lamparski-6/+14
See #46242.
2017-11-25rustbuild: Enable WebAssembly backend by defaultAlex Crichton-76/+111
This commit alters how we compile LLVM by default enabling the WebAssembly backend. This then also adds the wasm32-unknown-unknown target to get compiled on the `cross` builder and distributed through rustup. Tests are not yet enabled for this target but that should hopefully be coming soon!
2017-11-24std: Flag Windows TLS dtor symbol as #[used]Alex Crichton-1/+3
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if you compiled with LTO turns out no TLS destructors would run on Windows! The `#[used]` annotation should be a more bulletproof implementation (in the face of LTO) of preserving this symbol all the way through in LLVM and ensuring it makes it all the way to the linker which will take care of it.
2017-11-24Auto merge of #46012 - Gankro:float-conv-transmute, r=sfacklerbors-76/+86
Make float::from_bits transmute See commit message for details. See also this discussion here: https://github.com/rust-lang/rust/issues/40470#issuecomment-343803381 (may require libs team discussion before merging)
2017-11-24Fix doc testsAndrew Cann-9/+22
2017-11-24change stability of prim_neverAndrew Cann-1/+1
2017-11-24Add docs for never primitiveAndrew Cann-0/+104
2017-11-23Make float::from_bits transmute (and update the documentation to reflect this).Alexis Beingessner-76/+86
The current implementation/documentation was made to avoid sNaN because of potential safety issues implied by old/bad LLVM documentation. These issues aren't real, so we can just make the implementation transmute (as permitted by the existing documentation of this method). Also the documentation didn't actually match the behaviour: it said we may change sNaNs, but in fact we canonicalized *all* NaNs. Also an example in the documentation was wrong: it said we *always* change sNaNs, when the documentation was explicitly written to indicate it was implementation-defined. This makes to_bits and from_bits perfectly roundtrip cross-platform, except for one caveat: although the 2008 edition of IEEE-754 specifies how to interpet the signaling bit, earlier editions didn't. This lead to some platforms picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet on MIPS, and vice-versa. NaN-boxing is a fairly important optimization, while we don't even guarantee that float operations properly preserve signalingness. As such, this seems like the more natural strategy to take (as opposed to trying to mangle the signaling bit on a per-platform basis). This implementation is also, of course, faster.
2017-11-23Rollup merge of #46220 - rust-lang:frewsxcv-issue-44929, r=kennytmGuillaume Gomez-2/+4
Clarify stdin behavior of `Command::output`. Fixes #44929.
2017-11-23Remove invalid doc linkGuillaume Gomez-2/+1
2017-11-22Clarify stdin behavior of `Command::output`.Corey Farwell-2/+4
Fixes #44929.
2017-11-22Rollup merge of #46157 - martinlindhe:master, r=kennytmkennytm-1/+1
fix some typos This is the result of me testing out a WIP source code typo-finder and your project was the random target this time.
2017-11-22Rollup merge of #46141 - aqrln:tosocketaddrs-doc-fix-typo, r=frewsxcvkennytm-1/+1
Fix a typo in ToSocketAddrs documentation Fix a typo in `ToSocketAddrs` documentation: s/ToSocketsAddr/ToSocketAddrs
2017-11-22Rollup merge of #46050 - sunfishcode:read_to_end, r=sfacklerkennytm-6/+3
Optimize `read_to_end`. This patch makes `read_to_end` use Vec's memory-growth pattern rather than using a custom pattern. This has some interesting effects: - If memory is reserved up front, `read_to_end` can be faster, as it starts reading at the buffer size, rather than always starting at 32 bytes. This speeds up file reading by 2x in one of my use cases. - It can reduce the number of syscalls when reading large files. Previously, `read_to_end` would settle into a sequence of 8192-byte reads. With this patch, the read size follows Vec's allocation pattern. For example, on a 16MiB file, it can do 21 read syscalls instead of 2057. In simple benchmarks of large files though, overall speed is still dominated by the actual I/O. - A downside is that Read implementations that don't implement `initializer()` may see increased memory zeroing overhead. I benchmarked this on a variety of data sizes, with and without preallocated buffers. Most benchmarks see no difference, but reading a small/medium file with a pre-allocated buffer is faster.
2017-11-21fix some typosMartin Lindhe-1/+1
2017-11-21Auto merge of #45039 - QuietMisdreavus:doc-spotlight, ↵bors-0/+3
r=GuillaumeGomez,QuietMisdreavus show in docs whether the return type of a function impls Iterator/Read/Write Closes #25928 This PR makes it so that when rustdoc documents a function, it checks the return type to see whether it implements a handful of specific traits. If so, it will print the impl and any associated types. Rather than doing this via a whitelist within rustdoc, i chose to do this by a new `#[doc]` attribute parameter, so things like `Future` could tap into this if desired. ### Known shortcomings ~~The printing of impls currently uses the `where` class over the whole thing to shrink the font size relative to the function definition itself. Naturally, when the impl has a where clause of its own, it gets shrunken even further:~~ (This is no longer a problem because the design changed and rendered this concern moot.) The lookup currently just looks at the top-level type, not looking inside things like Result or Option, which renders the spotlights on Read/Write a little less useful: <details><summary>`File::{open, create}` don't have spotlight info (pic of old design)</summary> ![image](https://user-images.githubusercontent.com/5217170/31209495-e59d027e-a950-11e7-9998-ceefceb71c07.png) </details> All three of the initially spotlighted traits are generically implemented on `&mut` references. Rustdoc currently treats a `&mut T` reference-to-a-generic as an impl on the reference primitive itself. `&mut Self` counts as a generic in the eyes of rustdoc. All this combines to create this lovely scene on `Iterator::by_ref`: <details><summary>`Iterator::by_ref` spotlights Iterator, Read, and Write (pic of old design)</summary> ![image](https://user-images.githubusercontent.com/5217170/31209554-50b271ca-a951-11e7-928b-4f83416c8681.png) </details>