Commit Graph

9563 Commits

Author SHA1 Message Date
Jonathan Turner
d5595d1f3e Rollup merge of #35234 - nrc:rustdoc-macros, r=steveklabnik
rustdoc: remove the `!` from macro URLs and titles

Because the `!` is part of a macro use, not the macro's name. E.g., you write `macro_rules! foo` not `macro_rules! foo!`, also `#[macro_import(foo)]`.

(Pulled out of #35020).
2016-08-20 07:09:33 -07:00
Andrew Paseltiner
f7961126b5
Fix typos in unix/rwlock.rs 2016-08-19 21:12:36 -04:00
Alex Crichton
afeeadeae5 std: Stabilize APIs for the 1.12 release
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes #27708
cc #27709
Closes #32313
Closes #32630
Closes #32713
Closes #34029
Closes #34392
Closes #34285
Closes #34529
2016-08-19 11:59:56 -07:00
Tomasz Miąsko
8dae1b6625 Document that Condvar makes the best effort to use monotonic clock. 2016-08-19 14:11:51 +02:00
Steven Allen
de91872a33 Add a FusedIterator trait.
This trait can be used to avoid the overhead of a fuse wrapper when an iterator
is already well-behaved.

Conforming to: RFC 1581
Closes: #35602
2016-08-18 12:16:29 -04:00
Corey Farwell
c2b6f72114 Add a few doc examples for std::ffi::OsStr.
* `std::ffi::OsStr::new`.
* `std::ffi::OsStr::is_empty`.
* `std::ffi::OsStr::len`.
2016-08-18 10:34:54 -04:00
Nick Cameron
e6cc4c5d13 Fix links 2016-08-18 15:43:35 +12:00
Jonathan Turner
b444ac69c0 Rollup merge of #35621 - frewsxcv:cstring-from-vec-doc, r=peschkaj
Add doc example for `std::ffi::CString::from_vec_unchecked`.

None
2016-08-17 06:25:24 -07:00
Jonathan Turner
559bfd68e3 Rollup merge of #35613 - matthew-piziak:array-docs-trait-justification, r=steveklabnik
provide additional justification for array interface design

Explain why Rust does not implement traits for large arrays.

Explain why most methods are implemented on slices rather than arrays.

Note: I'm dipping my toes in the water with a tiny PR. Especially looking for feedback on wording and style. Points of concern: appropriate level of top-level explanation; foreshadowing (is it appropriate to imply that we expect Rust's type system to eventually support size-generic arrays?); using `Foo` and `Bar` as type variables instead of e.g. `T` and `S`.

@peschkaj
2016-08-17 06:25:24 -07:00
Jonathan Turner
997a248c01 Rollup merge of #35610 - JessRudder:33637-doc-update-for-str-representaton, r=steveklabnik
Add note to docs for &str that example is to demo internals only

r? @steveklabnik

This adds a note below the &str representation example explaining that the example provided should not be used under normal circumstances..

Would it make sense to point people in the direction of the method(s) they should use instead?  I left it out in the interest of not complicating the documentation, but, there's definitely an argument to be made for adding a bit of guidance in there.
2016-08-17 06:25:24 -07:00
bors
514d4cef24 Auto merge of #35354 - tomgarcia:covariant-drain, r=alexcrichton
Made vec_deque::Drain, hash_map::Drain, and hash_set::Drain covariant

Fixed the rest of the Drain iterators.
2016-08-16 13:26:15 -07:00
Eduard-Mihai Burtescu
8ade28e9a2 Rollup merge of #35574 - badboy:emscripten-test-fixes, r=brson
Emscripten test fixes

This picks up parts of #31623 to disable certain tests that emscripten can't run, as threads/processes are not supported.
I re-applied @tomaka's changes manually, I can rebase those commits with his credentials if he wants.

It also disables jemalloc for emscripten (at least in Rustbuild, I have to check if there is another setting for the same thing in the old makefile approach).

This should not impact anything for normal builds.
2016-08-14 20:29:49 +03:00
Eduard-Mihai Burtescu
41e0f2d5e3 Rollup merge of #35444 - alexcrichton:optimize-catch-unwind, r=brson
std: Optimize panic::catch_unwind slightly

The previous implementation of this function was overly conservative with
liberal usage of `Option` and `.unwrap()` which in theory never triggers. This
commit essentially removes the `Option`s in favor of unsafe implementations,
improving the code generation of the fast path for LLVM to see through what's
happening more clearly.

cc #34727
2016-08-14 20:29:48 +03:00
Eduard-Mihai Burtescu
9d1900b417 Rollup merge of #34941 - qolop:patch-2, r=apasel422
Fix typo (privledge->privilege)
2016-08-14 20:29:47 +03:00
Matthew Piziak
e173ead684 provide additional justification for array interface design
Explain why Rust does not implement traits for large arrays.

Explain why most methods are implemented on slices rather than arrays.
2016-08-12 12:12:54 -04:00
JessRudder
758aff7883 Update note to include recommendation to use .as_slice() 2016-08-12 10:39:40 -04:00
Corey Farwell
4e4d8baf7b Add doc example for std::ffi::CString::from_vec_unchecked. 2016-08-12 09:08:37 -04:00
Patrick McCann
629f2aafcf Fix typo
Didn't see this one at first.
2016-08-11 19:04:11 -04:00
JessRudder
91a2c25e2e Add note to docs for &str that example is to demo internals only 2016-08-11 18:47:47 -04:00
Alex Crichton
045c8c8624 std: Optimize panic::catch_unwind slightly
The previous implementation of this function was overly conservative with
liberal usage of `Option` and `.unwrap()` which in theory never triggers. This
commit essentially removes the `Option`s in favor of unsafe implementations,
improving the code generation of the fast path for LLVM to see through what's
happening more clearly.

cc #34727
2016-08-11 11:19:30 -07:00
Jonathan Turner
0e92c5e8b2 Rollup merge of #35569 - pietroalbini:fix-typo, r=steveklabnik
Fix docs typo in std::os::unix::net::SocketAddr::is_unnamed
2016-08-11 06:34:02 -07:00
Jonathan Turner
d423c25e08 Rollup merge of #35482 - frewsxcv:patch-31, r=GuillaumeGomez
Remove unnecessary `main` functions in doc examples.
2016-08-11 06:33:58 -07:00
bors
695b3d8279 Auto merge of #34866 - cynicaldevil:panic-counter, r=alexcrichton
Refactored code to access TLS only in case of panic (II)

Fixes #34787
r? @alexcrichton
Do it **very** carefully this time!
2016-08-11 01:58:48 -07:00
bors
1f2ae3849c Auto merge of #35525 - jonathandturner:rollup, r=jonathandturner
Rollup of 15 pull requests

- Successful merges: #35371, #35396, #35446, #35449, #35452, #35458, #35465, #35466, #35470, #35475, #35477, #35484, #35504, #35507, #35524
- Failed merges: #35395, #35415
2016-08-10 10:03:08 -07:00
Nikhil Shagrithaya
ea2216cba8 Added an update_panic_count function to handle access to PANIC_COUNT 2016-08-10 22:04:41 +05:30
Nikhil Shagrithaya
00b1e88680 Added a shim around rust_panic to update panic counter 2016-08-10 22:04:41 +05:30
Nikhil Shagrithaya
221000abbe Refactored code to access TLS only in case of panic 2016-08-10 22:04:41 +05:30
Pietro Albini
907a20c9e4
Clarify std::os::unix::net::SocketAddr::is_unnamed's docstring 2016-08-10 17:53:25 +02:00
Pietro Albini
e3ebe8bc02
Fix docs typo in std::os::unix::net::SocketAddr::is_unnamed 2016-08-10 17:34:50 +02:00
Jan-Erik Rediger
60599df03b [emscripten] Disable code paths that don't work on emscripten 2016-08-10 16:39:32 +02:00
bors
f0139140f6 Auto merge of #35426 - frewsxcv:os-sys-env-args-phantoms, r=alexcrichton
Utilize `PhantomData` to enforce `!Sync` and `!Send` field.

None
2016-08-09 05:26:50 -07:00
bors
c2b03f8ba9 Auto merge of #35425 - apasel422:refcell, r=alexcrichton
Implement `RefCell::{try_borrow, try_borrow_mut}`

CC #35070

r? @alexcrichton
2016-08-09 02:11:50 -07:00
Andrew Paseltiner
a20a1db54a
Implement RefCell::{try_borrow, try_borrow_mut} 2016-08-08 23:59:56 -04:00
Jonathan Turner
75efffe7fb Rollup merge of #35371 - mgattozzi:master, r=steveklabnik
Update HashMap docs regarding DoS protection

Because of changes to how Rust acquires randomness HashMap is not
guaranteed to be DoS resistant. This commit reflects these changes in
the docs themselves and provides an alternative method to creating
a hash that is resistant if needed.

This fixes #33817 and includes relevant information regarding changes made in #33086
2016-08-08 13:25:55 -07:00
Corey Farwell
e28521ede7 Remove unnecessary main functions in doc examples. 2016-08-08 00:07:36 -04:00
Jonathan Turner
3917d0e033 Rollup merge of #35436 - frewsxcv:into-vec, r=GuillaumeGomez
Add doc example for `std::ffi::NulError::into_vec`.

None
2016-08-07 09:59:44 -07:00
Jonathan Turner
56ffcbd321 Rollup merge of #35433 - mneumann:dragonfly-fix-libstd-errno-location, r=alexcrichton
Fix build on DragonFly (unused function errno_location)

Function errno_location() is not used on DragonFly. As warnings are
errors, this breaks the build.
2016-08-07 09:59:43 -07:00
Corey Farwell
28218bed8f Utilize PhantomData to enforce !Sync and !Send field. 2016-08-07 09:06:19 -04:00
bors
877dfeb572 Auto merge of #35378 - Amanieu:rwlock_eagain, r=alexcrichton
Handle RwLock reader count overflow

`pthread_rwlock_rdlock` may return `EAGAIN` if the maximum reader count overflows. We shouldn't return a successful lock in that case.
2016-08-06 19:50:48 -07:00
Corey Farwell
0a6b862ccd Add doc example for std::ffi::NulError::into_vec. 2016-08-06 17:50:37 -04:00
Michael Neumann
e8da9159fb Fix build on DragonFly (unused function errno_location)
Function errno_location() is not used on DragonFly. As warnings are
errors, this breaks the build.
2016-08-06 22:01:51 +02:00
Eduard-Mihai Burtescu
68f7b26504 Rollup merge of #34916 - tbu-:pr_comment_on_seek_cast, r=GuillaumeGomez
Comment on the casts in the `seek` implementations on files
2016-08-06 15:01:20 +03:00
Amanieu d'Antras
dff62c19ce Handle RwLock reader count overflow 2016-08-05 19:26:23 +01:00
Tobias Bucher
291b6f16bb Comment on the casts in the seek implementations on files 2016-08-05 20:18:31 +02:00
Michael Gattozzi
2683e8494c
Update HashMap docs regarding DoS protection
Because of changes to how Rust acquires randomness HashMap is not
guaranteed to be DoS resistant. This commit reflects these changes in
the docs themselves and provides an alternative method to creating
a hash that is resistant if needed.
2016-08-05 11:34:41 -04:00
Guillaume Gomez
5780595e27 Rollup merge of #35239 - dns2utf8:doc_park_timeout, r=steveklabnik
Doc `std:🧵:park_timeout`

r? @steveklabnik
2016-08-05 16:12:55 +02:00
Guillaume Gomez
8a923d48e2 Rollup merge of #35182 - frewsxcv:nulerror, r=steveklabnik
Add doc example for `std::ffi::NulError::nul_position`.

None
2016-08-05 16:12:55 +02:00
Guillaume Gomez
e377049262 Rollup merge of #35175 - frewsxcv:tcp, r=GuillaumeGomez
A couple `std::net` doc improvements.

None
2016-08-05 16:12:54 +02:00
Guillaume Gomez
4cf6c00322 Rollup merge of #35109 - GuillaumeGomez:io_docs, r=steveklabnik
Add io::Error doc examples

Fixes #29359.

r? @steveklabnik
2016-08-05 16:12:54 +02:00
Guillaume Gomez
56a89f5314 Rollup merge of #35076 - GuillaumeGomez:file_type_docs, r=steveklabnik
Add doc examples for FileType struct

Part of #29356.

r? @steveklabnik
2016-08-05 16:12:53 +02:00
Thomas Garcia
bf592cefde Made vec_deque::Drain, hash_map::Drain, and hash_set::Drain covariant 2016-08-04 21:33:57 -07:00
Stefan Schindler
20721a4923 Add link to replacement function 2016-08-03 23:12:25 +02:00
Stefan Schindler
4fc6f5ac26 Add an example to std:🧵:park_timeout 2016-08-03 23:12:25 +02:00
Guillaume Gomez
3e46c9dfcc Add doc examples for FileType struct 2016-08-03 12:52:36 +02:00
Corey Farwell
3081dd8637 Add doc example for std::ffi::NulError::nul_position. 2016-08-02 08:50:04 -04:00
bors
97d5be9819 Auto merge of #35084 - tbu-:pr_lowercase_wtf8_debug, r=brson
Escape the unmatched surrogates with lower-case hexadecimal numbers

It's done the same way for the rest of the codepoint escapes.
2016-08-02 02:30:17 -07:00
Corey Farwell
f2d8db15df Link to relevant method/struct for std::net::Shutdown docs. 2016-08-01 20:21:08 -04:00
Corey Farwell
57e3b9eb71 Indicate where the std::net::Incoming struct is created. 2016-08-01 20:16:56 -04:00
Tomasz Miąsko
8ec47261e1 Use monotonic time with condition variables.
Configure condition variables to use monotonic time using
pthread_condattr_setclock on systems where this is possible.
This fixes the issue when thread waiting on condition variable is
woken up too late when system time is moved backwards.
2016-07-31 12:47:52 +02:00
Jorge Aparicio
ea00993990 remove some anys that are no longer necessary 2016-07-30 15:39:13 -05:00
Jorge Aparicio
9ffd0fe5a7 arm-musl targets now use cfg(env = "musl") 2016-07-30 15:39:13 -05:00
Timon Van Overveldt
f7247d1071 Add ARM MUSL targets.
The targets are:
- `arm-unknown-linux-musleabi`
- `arm-unknown-linux-musleabihf`
- `armv7-unknown-linux-musleabihf`

These mirror the existing `gnueabi` targets.

All of these targets produce fully static binaries, similar to the
x86 MUSL targets.

For now these targets can only be used with `--rustbuild` builds, as
https://github.com/rust-lang/compiler-rt/pull/22 only made the
necessary compiler-rt changes in the CMake configs, not the plain
GNU Make configs.

I've tested these targets GCC 5.3.0 compiled again musl-1.1.12
(downloaded from http://musl.codu.org/). An example `./configure`
invocation is:

```
./configure \
    --enable-rustbuild
    --target=arm-unknown-linux-musleabi \
    --musl-root="$MUSL_ROOT"
```

where `MUSL_ROOT` points to the `arm-linux-musleabi` prefix.
Usually that path will be of the form
`/foobar/arm-linux-musleabi/arm-linux-musleabi`.

Usually the cross-compile toolchain will live under
`/foobar/arm-linux-musleabi/bin`. That path should either by added
to your `PATH` variable, or you should add a section to your
`config.toml` as follows:

```
[target.arm-unknown-linux-musleabi]
cc = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-gcc"
cxx = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-g++"
```

As a prerequisite you'll also have to put a cross-compiled static
`libunwind.a` library in `$MUSL_ROOT/lib`. This is similar to [how
the x86_64 MUSL targets are built]
(https://doc.rust-lang.org/book/advanced-linking.html).
2016-07-30 15:39:13 -05:00
Timon Van Overveldt
57cad5722d Update gcc crate dependency to 0.3.27.
This is to pull in changes to support ARM MUSL targets.

This change also commits a couple of other cargo-generated changes
to other dependencies in the various Cargo.toml files.
2016-07-30 15:39:13 -05:00
Guillaume Gomez
fda473f00f Add urls in std::io types 2016-07-30 13:38:04 +02:00
Guillaume Gomez
2bed205d3b Add io::Take doc example 2016-07-30 13:30:41 +02:00
bors
7580534c3a Auto merge of #35051 - japaric:backtrace, r=alexcrichton
rustbuild: make backtraces (RUST_BACKTRACE) optional

but keep them enabled by default to maintain the status quo.

When disabled shaves ~56KB off every x86_64-unknown-linux-gnu
binary.

To disable backtraces you have to use a config.toml (see
src/bootstrap/config.toml.example for details) when building rustc/std:

$ python bootstrap.py --config=config.toml

---

r? @alexcrichton
cc rust-lang/rfcs#1417
2016-07-30 00:08:24 -07:00
Guillaume Gomez
aeb3af898a Add doc example for Stdout 2016-07-30 00:57:20 +02:00
Guillaume Gomez
451683f0ee Add doc example for Stdin 2016-07-30 00:56:14 +02:00
Guillaume Gomez
aad5f6f912 Add doc example for io::Stderr 2016-07-30 00:53:18 +02:00
Guillaume Gomez
e805cb6374 Add io::Error doc examples 2016-07-29 14:32:35 +02:00
Guillaume Gomez
d69161c119 Rollup merge of #35087 - GuillaumeGomez:fs_docs, r=steveklabnik
Fs docs

Fixes #29356.

r? @steveklabnik
2016-07-29 11:57:54 +02:00
Tobias Bucher
bb6c27e74d Escape the unmatched surrogates with lower-case hexadecimal numbers
It's done the same way for the rest of the codepoint escapes.
2016-07-29 00:52:03 +02:00
bors
d1df3fecdf Auto merge of #34485 - tbu-:pr_unicode_debug_str, r=alexcrichton
Escape fewer Unicode codepoints in `Debug` impl of `str`

Use the same procedure as Python to determine whether a character is
printable, described in [PEP 3138]. In particular, this means that the
following character classes are escaped:

- Cc (Other, Control)
- Cf (Other, Format)
- Cs (Other, Surrogate), even though they can't appear in Rust strings
- Co (Other, Private Use)
- Cn (Other, Not Assigned)
- Zl (Separator, Line)
- Zp (Separator, Paragraph)
- Zs (Separator, Space), except for the ASCII space `' '` `0x20`

This allows for user-friendly inspection of strings that are not
English (e.g. compare `"\u{e9}\u{e8}\u{ea}"` to `"éèê"`).

Fixes #34318.
CC #34422.

[PEP 3138]: https://www.python.org/dev/peps/pep-3138/
2016-07-28 11:20:33 -07:00
Guillaume Gomez
123bf1e95d Add OpenOptionsExt doc examples 2016-07-28 13:04:24 +02:00
Guillaume Gomez
8d3f20f906 Add doc examples for std::fs::unix::OpenOptionsExt 2016-07-28 12:55:58 +02:00
bors
f5d79521ae Auto merge of #34946 - alexcrichton:fix-cfg, r=brson
std: Fix usage of SOCK_CLOEXEC

This code path was intended to only get executed on Linux, but unfortunately the
`cfg!` was malformed so it actually never got executed.
2016-07-27 18:58:04 -07:00
Guillaume Gomez
52c50ba276 Add doc examples for std::fs::Metadata 2016-07-28 02:53:34 +02:00
Tobias Bucher
3d09b4a0d5 Rename char::escape to char::escape_debug and add tracking issue 2016-07-28 02:20:49 +02:00
bors
422ebd5328 Auto merge of #33312 - Byron:double-ended-iterator-for-args, r=alexcrichton
DoubleEndedIterator for Args

This PR implements the DoubleEndedIterator trait for the `std::env::Args[Os]` structure, as well
as the internal implementations.

It is primarily motivated by me, as I happened to implement a simple `reversor` program many times
now, which so far had to use code like this:

```Rust
for arg in std::env::args().skip(1).collect::<Vec<_>>().iter().rev() {}
```

... even though I would have loved to do this instead:

```Rust
for arg in std::env::args().skip(1).rev() {}
```

The latter is more natural, and I did not find a reason for not implementing it.
After all, on every system, the number of arguments passed to the program are known
at runtime.

To my mind, it follows KISS, and does not try to be smart at all. Also, there are no unit-tests,
primarily as I did not find any existing tests for the `Args` struct either.

The windows implementation is basically a copy-pasted variant of the `next()` method implementation,
and I could imagine sharing most of the code instead. Actually I would be happy if the reviewer would
ask for it.
2016-07-27 02:26:37 -07:00
Jorge Aparicio
774fbdf40d keep backtraces if using the old build system 2016-07-26 22:33:45 -05:00
Steve Klabnik
8de36f1423 Rollup merge of #35010 - GuillaumeGomez:file_doc, r=steveklabnik
Improve Open doc

Part of #29356.

r? @steveklabnik
2016-07-26 17:21:13 -04:00
Steve Klabnik
57d50299a7 Rollup merge of #35009 - GuillaumeGomez:dir_entry_doc, r=steveklabnik
Dir entry doc

Part of #29356.

r? @steveklabnik
2016-07-26 17:21:13 -04:00
Steve Klabnik
905e35f30b Rollup merge of #35001 - rdwilliamson:patch-1, r=alexcrichton
Fix HashMap's values_mut example to use println!

Fix HashMap's values_mut example to use println!
2016-07-26 17:21:13 -04:00
Steve Klabnik
ae05e62ede Rollup merge of #34995 - GuillaumeGomez:dir_builder_doc, r=steveklabnik
Add DirBuilder doc examples

r? @steveklabnik

Part of #29329 and of #29356.
2016-07-26 17:21:12 -04:00
Steve Klabnik
69d282ab50 Rollup merge of #34935 - GuillaumeGomez:hash_map_doc, r=steveklabnik
Add HashMap Entry enums examples

Part of #29348.

r? @steveklabnik
2016-07-26 17:21:12 -04:00
Jorge Aparicio
d464422c0a rustbuild: make backtraces (RUST_BACKTRACE) optional
but keep them enabled by default to maintain the status quo.

When disabled shaves ~56KB off every x86_64-unknown-linux-gnu
binary.

To disable backtraces you have to use a config.toml (see
src/bootstrap/config.toml.example for details) when building rustc/std:

$ python bootstrap.py --config=config.toml
2016-07-26 15:21:25 -05:00
Sebastian Thiel
1aa8dad854 DoubleEndedIterator for Args
The number of arguments given to a process is always known, which
makes implementing DoubleEndedIterator possible.

That way, the Iterator::rev() method becomes usable, among others.

Signed-off-by: Sebastian Thiel <byronimo@gmail.com>

Tidy for DoubleEndedIterator

I chose to not create a new feature for it, even though
technically, this makes me lie about the original availability
of the implementation.

Verify with @alexchrichton

Setup feature flag for new std::env::Args iterators

Add test for Args reverse iterator

It's somewhat depending on the input of the test program,
but made in such a way that should be somewhat flexible to changes
to the way it is called.

Deduplicate windows ArgsOS code for DEI

DEI = DoubleEndedIterator

Move env::args().rev() test to run-pass

It must be controlling it's arguments for full isolation.

Remove superfluous feature name

Assert all arguments returned by env::args().rev()

Let's be very sure it works as we expect, why take chances.

Fix rval of os_string_from_ptr

A trait cannot be returned, but only the corresponding object.

Deref pointers to actually operate on the argument

Put unsafe to correct location
2016-07-26 12:12:43 +02:00
Guillaume Gomez
debb2ac76b Improve Open doc 2016-07-24 17:00:49 +02:00
Guillaume Gomez
16699635bc Add DirEntry doc examples 2016-07-24 16:52:28 +02:00
Guillaume Gomez
dad29a6d03 Add missing links 2016-07-24 16:07:06 +02:00
Manish Goregaokar
33ad70521b Rollup merge of #34975 - GuillaumeGomez:random_state_doc, r=steveklabnik
Add Random state doc

Last part of #29348.

r? @steveklabnik
2016-07-24 15:18:47 +05:30
Robert Williamson
ccc955c84c Fix HashMap's values_mut example to use println! 2016-07-23 16:13:25 -06:00
Guillaume Gomez
90bb8d469c Add DirBuilder doc examples 2016-07-23 01:57:21 +02:00
ggomez
3c8fae369f Add Random state doc 2016-07-22 14:57:52 +02:00
ggomez
ec33dab062 Add HashMap Entry enums examples 2016-07-22 14:46:21 +02:00
bors
0d7597588d Auto merge of #34724 - mitchmindtree:mpsc_receiver_try_recv, r=alexcrichton
Add a method to the mpsc::Receiver for producing a non-blocking iterator

Currently, the `mpsc::Receiver` offers methods for receiving values in both blocking (`recv`) and non-blocking (`try_recv`) flavours. However only blocking iteration over values is supported. This PR adds a non-blocking iterator to complement the `try_recv` method, just as the blocking iterator complements the `recv` method.

Use-case
-------------

I predominantly use rust in my work on real-time systems and in particular real-time audio generation/processing. I use `mpsc::channel`s to communicate between threads in a purely non-blocking manner. I.e. I might send messages from the GUI thread to the audio thread to update the state of the dsp-graph, or from the audio thread to the GUI thread to display the RMS of each node. These are just a couple examples (I'm probably using 30+ channels across my various projects). I almost exclusively use the `mpsc::Receiver::try_recv` method to avoid blocking any of the real-time threads and causing unwanted glitching/stuttering. Now that I mention it, I can't think of a single time that I personally have used the `recv` method (though I can of course see why it would be useful, and perhaps the common case for many people).

As a result of this experience, I can't help but feel there is a large hole in the `Receiver` API.

| blocking | non-blocking |
|------------|--------------------|
| `recv` | `try_recv` |
| `iter` | 🙀   |

For the most part, I've been working around this using `while let Ok(v) = r.try_recv() { ... }`, however as nice as this is, it is clearly no match for the Iterator API.

As an example, in the majority of my channel use cases I only want to check for *n* number of messages before breaking from the loop so that I don't miss the audio IO callback or hog the GUI thread for too long when an unexpectedly large number of messages are sent. Currently, I have to write something like this:

```rust
let mut take = 100;
while let Ok(msg) = rx.try_recv() {
    // Do stuff with msg
    if take == 0 {
        break;
    }
    take -= 1;
}
```

or wrap the `try_recv` call in a `Range<usize>`/`FilterMap` iterator combo.

On the other hand, this PR would allow for the following:

```rust
for msg in rx.try_iter().take(100) {
    // Do stuff with msg
}
```

I imagine this might also be useful to game devs, embedded or anyone doing message passing across real-time threads.
2016-07-21 22:39:48 -07:00
mitchmindtree
05af033b7f Fix issue in receiver_try_iter test where response sender would panic instead of break from the loop 2016-07-21 19:32:24 +10:00
Guillaume Gomez
22a14a8389 Rollup merge of #34937 - GuillaumeGomez:hash_map_entry_debug, r=apasel422
Add debug for hash_map::{Entry, VacantEntry, OccupiedEntry}

r? @alexcrichton
2016-07-21 11:27:01 +02:00
Guillaume Gomez
271230f347 Rollup merge of #34895 - mark-buer:patch-1, r=steveklabnik
Remove rustdoc reference to `walk_dir`
2016-07-21 11:27:00 +02:00
Alex Crichton
15cd5a18a6 std: Fix usage of SOCK_CLOEXEC
This code path was intended to only get executed on Linux, but unfortunately the
`cfg!` was malformed so it actually never got executed.
2016-07-20 17:26:12 -07:00
Patrick McCann
e91b625e86 Fix typo (privledge->privilege) 2016-07-20 16:43:53 -04:00
bors
9d5965a5e8 Auto merge of #34694 - mathphreak:master, r=alexcrichton
Add IpAddr common methods

Per https://github.com/rust-lang/rfcs/pull/1668#issuecomment-230867962 no RFC is needed here.

The generated documentation for these methods is being weird. It shows a deprecation message referencing #27709 for each of them even though two of the referenced methods were stabilized as part of that issue. I don't know how best to address that.
2016-07-20 07:10:09 -07:00
bors
a63e3fac8f Auto merge of #33526 - steveklabnik:gh21889, r=alexcrichton
Add some warnings to std::env::current_exe

/cc #21889 @rust-lang/libs @semarie

I started writing this up. I'm not sure if we want to go into other things and in what depth; we don't currently have a lot of security-specific documentation to model after.

Thoughts?
2016-07-20 00:48:21 -07:00
mitchmindtree
aed2e5c1e5 Add the missing tracking issue field for #34931 to the receiver_try_iter stability attributes 2016-07-20 14:49:40 +10:00
Steve Klabnik
c4730daf45 re-work example 2016-07-19 12:32:56 -04:00
bors
92400cf8dc Auto merge of #33974 - habnabit:eintr-retry-for-read-iterators, r=alexcrichton
Retry on EINTR in Bytes and Chars.

>Since Bytes and Chars called directly into Read::read, they didn't use any of the retrying wrappers. This allows both iterator types to retry.
2016-07-19 01:20:50 -07:00
Mark Buer
d820fcba12 Remove rustdoc reference to walk_dir 2016-07-18 17:54:15 +09:30
ggomez
ce442b4f51 Add debug for hash_map::{Entry, VacantEntry, OccupiedEntry} 2016-07-18 01:38:19 +02:00
Tim Neumann
dd72785af5 Revert "Refactored code to access TLS only in case of panic" 2016-07-16 22:19:43 +02:00
Alex Crichton
d5b9850d79 Merge pull request #34836 from cynicaldevil/panic-counter
Refactored code to access TLS only in case of panic
2016-07-16 10:10:17 -07:00
Nikhil Shagrithaya
b28e9dcae8 Refactored code to access TLS only in case of panic 2016-07-16 00:34:50 +05:30
Guillaume Gomez
367f942ce4 Rollup merge of #34794 - frewsxcv:exitstatus-success, r=GuillaumeGomez
Add doc example for `std::process::ExitStatus::success`.

None
2016-07-15 10:56:43 +02:00
Guillaume Gomez
d607e284c8 Rollup merge of #34777 - glandium:issue34697, r=GuillaumeGomez
doc: Mention that writeln! and println! always use LF

Fixes #34697

I'm not really satisfied with the wording, but I didn't have a better idea. Suggestions welcome.
2016-07-15 10:56:42 +02:00
Guillaume Gomez
6f07b6ca4b Rollup merge of #34456 - tbu-:pr_ptr_null, r=aturon
Use `ptr::{null, null_mut}` instead of `0 as *{const, mut}`
2016-07-15 10:56:42 +02:00
bors
935bd76367 Auto merge of #34776 - cuviper:solaris-readdir, r=alexcrichton
std: fix `readdir` errors for solaris

A `NULL` from `readdir` could be the end of stream or an error.  The only
way to know is to check `errno`, so it must be set to a known value first,
like a 0 that POSIX will never use.

This currently only matters for solaris targets, as the other unix platforms
are using `readdir_r` with a direct error return indication.  However, this is
getting deprecated (#34668) so they should all eventually switch to `readdir`.

This PR adds `set_errno`, uses it to clear the value before calling `readdir`,
then checks it again after to see the reason for a `NULL`.  A few other small
fixes are included just to get solaris compiling at all.

I couldn't get cross-compilation completely going, so I don't have a good way
to test this beyond a smoke-test cargo build of std.  I'd appreciate input from
someone more familiar with solaris -- cc @nbaksalyar?
2016-07-13 19:32:17 -07:00
bors
617039bff0 Auto merge of #34756 - habnabit:mutex-refunwindsafe, r=alexcrichton
Mutex and RwLock need RefUnwindSafe too

Incomplete, because I don't know what the appropriate stability annotation is here, but this is an attempt to bring the documentation for `std::panic` in line with reality. Right now, it says:

>Types like `&Mutex<T>`, however, are unwind safe because they implement poisoning by default.

But only `Mutex<T>`, not `&Mutex<T>`, is unwind-safe.
2016-07-12 22:43:31 -07:00
bors
4bbb1c5c99 Auto merge of #34739 - therealbstern:ipv4unspec, r=alexcrichton
Mark Ipv4Addr is_unspecified as stable and provide reference.

Per [#27709 (comment)](https://github.com/rust-lang/rust/issues/27709#issuecomment-231280999), no RFC is needed here.

IPv4 "unspecified" has been defined in [Stevens], and has been part of the IPv4 stack for quite some time.  This property should become stable, since this use of 0.0.0.0 is not going anywhere.

[Stevens][_UNIX Network Programming Volume 1, Second Edition_.  Stevens, W. Richard.  Prentice-Hall, 1998.  p. 891]

Please let me know if I got the rustdoc wrong or something.  I tried to be as terse as possible while still conveying the appropriate information.

This also has a slight impact on PR #34694, but that one came first, so this shouldn't block it, IMO.
2016-07-12 19:11:02 -07:00
Corey Farwell
27e44edb4c Add doc example for std::process::ExitStatus::success. 2016-07-12 21:32:55 -04:00
bors
26fd0117f9 Auto merge of #34705 - alexcrichton:clean-deprecated, r=brson
std: Clean out deprecated APIs

This primarily removes a lot of `sync::Static*` APIs and rejiggers the
associated implementations. While doing this it was discovered that the
`is_poisoned` method can actually result in a data race for the Mutex/RwLock
primitives, so the inner `Cell<bool>` was changed to an `AtomicBool` to prevent
the associated data race. Otherwise the usage/gurantees should be the same
they were before.
2016-07-12 15:15:56 -07:00
Alex Crichton
a7220d9046 std: Clean out deprecated APIs
This primarily removes a lot of `sync::Static*` APIs and rejiggers the
associated implementations. While doing this it was discovered that the
`is_poisoned` method can actually result in a data race for the Mutex/RwLock
primitives, so the inner `Cell<bool>` was changed to an `AtomicBool` to prevent
the associated data race. Otherwise the usage/gurantees should be the same
they were before.
2016-07-12 12:51:13 -07:00
bors
3085ec7848 Auto merge of #34757 - sourcefrog:debug-filetype, r=alexcrichton
Derive Debug on FileType.

Partially fixes #32054
2016-07-12 06:54:46 -07:00
Guillaume Gomez
1958e39cca Rollup merge of #34750 - GuillaumeGomez:error_doc, r=steveklabnik
Add examples for std::Error module

Fixes #29352.

r? @steveklabnik
2016-07-12 12:08:24 +02:00
Guillaume Gomez
a94e4c0f10 Rollup merge of #34737 - frewsxcv:libstd-process-child, r=GuillaumeGomez
Various `std::process` doc improvements.

None
2016-07-12 12:08:23 +02:00
Tobias Bucher
81e95c18b7 Use ptr::{null, null_mut} instead of 0 as *{const, mut} 2016-07-12 10:40:40 +02:00
Mike Hommey
4bfaa43eed doc: Mention that writeln! and println! always use LF
Fixes #34697
2016-07-12 14:39:16 +09:00
Josh Stone
79fb5522bd std: clear errno before readdir, then check it (solaris)
A `NULL` from `readdir` could be the end of stream or an error.  The
only way to know is to check `errno`, so it must be set to a known value
first, like a 0 that POSIX will never use.

This patch adds `set_errno`, uses it to clear the value before calling
`readdir`, then checks it again after to see the reason for a `NULL`.
2016-07-11 21:43:53 -07:00
Josh Stone
9503b130d1 std: Fix IPV6 imports for solaris
Like BSDs, Solaris maps `IPV6_ADD_MEMBERSHIP` and `IPV6_DROP_MEMBERSHIP`
from `IPV6_JOIN_GROUP` and `IPV6_LEAVE_GROUP` respectively.
2016-07-11 21:35:54 -07:00
Josh Stone
ef1bd087ee std: Fix Thread::set_name() for newlib and solaris
The `use ffi::CStr` in `unix/thread.rs` was previously guarded, but now
all platforms need it for `Thread::set_name()`.  Newlib and Solaris do
nothing here, as they have no way to set a thread name, but they still
define the same method signature.
2016-07-11 21:35:47 -07:00
Ben Stern
cd487db63f Mark Ipv4Addr is_unspecified as stable and provide reference. 2016-07-11 23:47:45 -04:00
bors
7ad125c4eb Auto merge of #34686 - alexcrichton:new-stage, r=luqmana
rustc: Update stage0 to beta-2016-07-06

Hot off the presses, let's update our stage0 compiler!
2016-07-11 11:29:52 -07:00
Corey Farwell
97d96bd40c std::process doc improvements.
* Link to `process::Command` from `process::Child`.
* Move out inline Markdown link in doc comment.
* Link to `process::Child::wait` from `process::Child`.
* Link to `process::Child` from `process::ChildStdin`.
* Link to `process::Child` from `process::ChildStdout`.
* Link to `process::Child` from `process::ChildStderr`.
2016-07-11 12:08:15 -04:00
Aaron Gallagher
fbec232df1 Set unwind_safe_lock_refs stability to 1.12.0.
This is the first (and presumably only) use of this feature.
2016-07-11 07:34:20 -07:00
Martin Pool
bba33ecd86 Derive Debug on FileType.
Partially fixes #32054
2016-07-10 15:37:41 -07:00
Aaron Gallagher
c11540587f Mutex and RwLock need RefUnwindSafe too. 2016-07-10 15:22:15 -07:00
Guillaume Gomez
e634d21ba9 Add examples for std::Error module 2016-07-10 22:29:19 +02:00
Steven Fackler
8511b6faf4 Demangle curly braces
They show up in things like
fn(&std..panic..PanicInfo<'_>) $u7b$hook$u7d$::fn_pointer_shim.8352::h01f889b2277c719d
2016-07-10 10:04:20 -07:00
bors
46e7f4b8c5 Auto merge of #34731 - GGist:fix_sync_try_recv, r=alexcrichton
Check for data in Receiver::try_recv before reporting disconnect

Fixes #34711

r? @alexcrichton
2016-07-10 00:22:33 -07:00
bors
d40c593f42 Auto merge of #34717 - frewsxcv:sink, r=apasel422
Remove unnecessarily mutable reference in doc example.

None
2016-07-09 12:16:57 -07:00
bors
459b1a4fbb Auto merge of #34709 - GuillaumeGomez:primitives, r=steveklabnik
Improve primitive integers documentation

Fixes #29335.

r? @steveklabnik
2016-07-09 06:18:55 -07:00
Andrew
2af340c0ec Check for data in Receiver::try_recv before reporting disconnect 2016-07-08 19:09:51 -07:00
bors
fdca8c2fbd Auto merge of #34700 - inejge:ai-hints, r=alexcrichton
Use hints with getaddrinfo() in std::net::lookup_host()

As noted in #24250, `std::net::lookup_host()` repeats each IPv[46] address in the result set. The number of repetitions is OS-dependent; e.g., Linux and FreeBSD give three copies, OpenBSD gives two. Filtering the duplicates can be done by the user if `lookup_host()` is used explicitly, but not with functions like `TcpStream::connect()`. What happens with the latter is that any unsuccessful connection attempt will be repeated as many times as there are duplicates of the address.

The program:

```rust
use std::net::TcpStream;

fn main() {
    let _stream = TcpStream::connect("localhost:4444").unwrap();
}
```

results in the following capture:

[capture-before.txt](https://github.com/rust-lang/rust/files/352004/capture-before.txt)

assuming that "localhost" resolves both to ::1 and 127.0.0.1, and that the listening program opens just an IPv4 socket (e.g., `nc -l 127.0.0.1 4444`.) The reason for this behavior is explained in [this comment](https://github.com/rust-lang/rust/issues/24250#issuecomment-92240152): `getaddrinfo()` is not constrained.

Various OSS projects (I checked out Postfix, OpenLDAP, Apache HTTPD and BIND) which use `getaddrinfo()` generally constrain the result set by using a non-NULL `hints` parameter and setting at least `ai_socktype` to `SOCK_STREAM`. `SOCK_DGRAM` would also work. Other parameters are unnecessary for pure name resolution.

The patch in this PR initializes a `hints` struct and passes it to `getaddrinfo()`, which eliminates the duplicates. The same test program as above with this change produces:

[capture-after.txt](https://github.com/rust-lang/rust/files/352042/capture-after.txt)

All `libstd` tests pass with this patch.
2016-07-08 19:07:45 -07:00
Guillaume Gomez
a6bbd0c1ca Improve primitive integers documentation 2016-07-08 23:03:17 +02:00
mitchmindtree
b02b38e1c4 Add the unstable attribute to the new mpsc::Receiver::try_iter API 2016-07-09 00:35:08 +10:00
mitchmindtree
b354887180 Add a test for Receiver::try_iter 2016-07-09 00:21:26 +10:00
mitchmindtree
8aeb9303e9 add a non blocking iterator for the mpsc::Receiver
Currently, the `mpsc::Receiver` offers methods for receiving values in
both blocking (`recv`) and non-blocking (`try_recv`) flavours. However
only blocking iteration over values is supported. This commit adds a
non-blocking iterator to complement the `try_recv` method, just as the
blocking iterator complements the `recv` method.
2016-07-08 22:12:36 +10:00
Ivan Nejgebauer
66bf1092a5 Add test for std::net::lookup_host() duplicates 2016-07-08 13:48:46 +02:00
Manish Goregaokar
5389ccc0c1 Rollup merge of #34700 - inejge:ai-hints, r=alexcrichton
Use hints with getaddrinfo() in std::net::lookup_host()

As noted in #24250, `std::net::lookup_host()` repeats each IPv[46] address in the result set. The number of repetitions is OS-dependent; e.g., Linux and FreeBSD give three copies, OpenBSD gives two. Filtering the duplicates can be done by the user if `lookup_host()` is used explicitly, but not with functions like `TcpStream::connect()`. What happens with the latter is that any unsuccessful connection attempt will be repeated as many times as there are duplicates of the address.

The program:

```rust
use std::net::TcpStream;

fn main() {
    let _stream = TcpStream::connect("localhost:4444").unwrap();
}
```

results in the following capture:

[capture-before.txt](https://github.com/rust-lang/rust/files/352004/capture-before.txt)

assuming that "localhost" resolves both to ::1 and 127.0.0.1, and that the listening program opens just an IPv4 socket (e.g., `nc -l 127.0.0.1 4444`.) The reason for this behavior is explained in [this comment](https://github.com/rust-lang/rust/issues/24250#issuecomment-92240152): `getaddrinfo()` is not constrained.

Various OSS projects (I checked out Postfix, OpenLDAP, Apache HTTPD and BIND) which use `getaddrinfo()` generally constrain the result set by using a non-NULL `hints` parameter and setting at least `ai_socktype` to `SOCK_STREAM`. `SOCK_DGRAM` would also work. Other parameters are unnecessary for pure name resolution.

The patch in this PR initializes a `hints` struct and passes it to `getaddrinfo()`, which eliminates the duplicates. The same test program as above with this change produces:

[capture-after.txt](https://github.com/rust-lang/rust/files/352042/capture-after.txt)

All `libstd` tests pass with this patch.
2016-07-08 14:47:00 +05:30
Manish Goregaokar
f4ae98ab8c Rollup merge of #34659 - GuillaumeGomez:path_file_name, r=steveklabnik
Fix `std::path::Path::file_name()` doc

Fixes #34632

r? @steveklabnik
2016-07-08 14:46:59 +05:30
Manish Goregaokar
75276f36fe Rollup merge of #34612 - frewsxcv:io-error-from_raw_os_error, r=steveklabnik
Add doc examples for `io::Error::from_raw_os_error`.

None
2016-07-08 14:46:58 +05:30
Corey Farwell
fc2123a69a Remove unnecessarily mutable reference in doc example. 2016-07-07 22:58:47 -04:00