Commit Graph

5815 Commits

Author SHA1 Message Date
Manish Goregaokar
6234610252 Rollup merge of #35058 - jethrogb:no_panic_abs, r=alexcrichton
Add non-panicking abs() functions to all signed integer types.

Currently, calling abs() on one of the signed integer types might panic (in
debug mode at least) because the absolute value of the largest negative value
can not be represented in that signed type. Unlike all other integer
operations, there is currently not a non-panicking version on this function.
This seems to just be an oversight in the design, therefore just adding it now.
2016-07-30 13:44:46 +05:30
Guillaume Gomez
3f06bf9afb Rollup merge of #35072 - munyari:assert_debug, r=steveklabnik
Update docs for assert! and debug_assert!

Refer to #34455
2016-07-29 11:57:54 +02:00
Guillaume Gomez
41c8d3f630 Rollup merge of #35062 - frewsxcv:chars-as-str, r=GuillaumeGomez
Add documentation example for `str::Chars::as_str`.

None
2016-07-29 11:57:53 +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
Jethro Beekman
cdc6afed38 Add non-panicking abs() functions to all signed integer types.
Currently, calling abs() on one of the signed integer types might panic (in
debug mode at least) because the absolute value of the largest negative value
can not be represented in that signed type. Unlike all other integer
operations, there is currently not a non-panicking version on this function.
This seems to just be an oversight in the design, therefore just adding it now.
2016-07-28 09:05:43 -07:00
Corey Farwell
f98c55d933 Add documentation example for str::Chars::as_str. 2016-07-28 08:54:48 -04:00
Tobias Bucher
3d09b4a0d5 Rename char::escape to char::escape_debug and add tracking issue 2016-07-28 02:20:49 +02:00
Panashe M. Fundira
9a7367b960
Mention debug_assert! in assert! doc 2016-07-27 15:16:11 -04:00
Panashe M. Fundira
8760b1dd26
Revert section about panic! in assert! doc 2016-07-27 15:03:23 -04:00
Panashe M. Fundira
91acc3977b
Correct minor typo in debug_assert doc 2016-07-27 15:01:43 -04:00
Panashe M. Fundira
a72767970a
Update docs for assert! and debug_assert! 2016-07-27 13:12:35 -04:00
Steve Klabnik
f57388844d Rollup merge of #34732 - durka:patch-27, r=steveklabnik
document DoubleEndedIterator::next_back

document DoubleEndedIterator::next_back

fixes #34726
2016-07-26 17:21:11 -04:00
Steve Klabnik
4c95b66465 Rollup merge of #34609 - ubsan:transmute_docs, r=steveklabnik
Add more docs - mostly warnings - to std::mem::transmute
2016-07-26 17:21:11 -04:00
Tobias Bucher
68efea08fa Restore char::escape_default and add char::escape instead 2016-07-26 15:15:00 +02:00
Manish Goregaokar
10be6e6c9e Rollup merge of #34976 - GuillaumeGomez:build_hasher_doc, r=steveklabnik
Add BuildHasher example

r? @steveklabnik
2016-07-24 15:18:48 +05:30
Tobias Bucher
34f766e341 Fix indentation in src/libcore/lib.rs 2016-07-23 00:18:44 +02:00
Tobias Bucher
e7d16580f5 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.

[PEP 3138]: https://www.python.org/dev/peps/pep-3138/
2016-07-23 00:18:44 +02:00
ggomez
890706070d Add BuildHasher example 2016-07-22 16:38:16 +02:00
bors
62690b3c3f Auto merge of #34544 - 3Hren:issue/xx/reinterpret-format-precision-for-strings, r=alexcrichton
feat: reinterpret `precision` field for strings

This commit changes the behavior of formatting string arguments with both width and precision fields set.

Documentation says that the `width` field is the "minimum width" that the format should take up. If the value's string does not fill up this many characters, then the padding specified by fill/alignment will be used to take up the required space.

This is true for all formatted types except string, which is truncated down to `precision` number of chars and then all of `fill`, `align` and `width` fields are completely ignored.

For example: `format!("{:/^10.8}", "1234567890);` emits "12345678". In the contrast Python version works as the expected:
```python
>>> '{:/^10.8}'.format('1234567890')
'/12345678/'
```

This commit gives back the `Python` behavior by changing the `precision` field meaning to the truncation and nothing more. The result string *will* be prepended/appended up to the `width` field with the proper `fill` char.

__However, this is the breaking change, I admit.__ Feel free to close it, but otherwise it should be mentioned in the `std::fmt` documentation somewhere near of `fill/align/width` fields description.
2016-07-21 16:19:54 -07:00
ubsan
24f8589bf3 Fix nits 2016-07-21 12:57:42 -07:00
Guillaume Gomez
bcbe27cbf9 Rollup merge of #34828 - seanmonstar:into-opton, r=alexcrichton
core: impl From<T> for Option<T>

First, the semantics of this `impl` seem spot on. If I have a value `T`, and I wish to make a `Option<T>`, then `Option::from(val)` should always give `Some(val)`.

Second, this allows improvement for several APIs that currently take `Option<T>` as arguments. Consider:

```rust
fn set_read_timeout(&mut self, timeout: Option<u32>) {
    // ...
}

x.set_read_timeout(Some(30));
x.set_read_timeout(Some(10));
x.set_read_timeout(None);
```

With this `impl`:

```rust
fn set_read_timeout<T: Into<Option<u32>>>(&mut self, timeout: T) {
    let timeout = timeout.into();
    // ...
}

x.set_read_timeout(30);
x.set_read_timeout(10);
x.set_read_timeout(Some(10)); // backwards compatible
x.set_read_timeout(None);
```

The change to those methods aren't included, but could be modified later.

r? @sfackler
2016-07-21 11:26:57 +02:00
Sean McArthur
fbfee42a2f core: impl From<T> for Option<T> 2016-07-20 15:54:54 -07:00
bors
27e766d7bc Auto merge of #34898 - sanxiyn:rollup, r=sanxiyn
Rollup of 5 pull requests

- Successful merges: #34807, #34853, #34875, #34884, #34889
- Failed merges:
2016-07-19 05:12:51 -07:00
bors
8052f73d7b Auto merge of #34879 - petrochenkov:fnptr, r=alexcrichton
Implement traits for variadic function pointers

Closes https://github.com/rust-lang/rust/issues/34874
cc https://github.com/rust-lang/rust/pull/28268

r? @alexcrichton
2016-07-18 18:09:25 -07:00
bors
bbfcb471db Auto merge of #34357 - tbu-:pr_exact_size_is_empty, r=brson
Add `is_empty` function to `ExactSizeIterator`

All other types implementing a `len` functions have `is_empty` already.
2016-07-18 14:26:22 -07:00
Tobias Bucher
7b2a03f08e Fix doctest of ExactSizeIterator::is_empty 2016-07-18 18:35:08 +02:00
Seo Sanghyeon
b7138494ef Rollup merge of #34875 - frewsxcv:std-slice-struct, r=GuillaumeGomez
Indicate where `std::slice` structs originate from.

None
2016-07-18 22:44:56 +09:00
Corey Farwell
b2f5b5a812 Indicate where std::slice structs originate from. 2016-07-17 09:16:47 -04:00
Vadim Petrochenkov
9c5039a128 Implement traits for variadic function pointers 2016-07-17 10:21:07 +03:00
Guillaume Gomez
689fde2735 Rollup merge of #34838 - steveklabnik:gh33677, r=alexcrichton
Fix up documentation around no_std

1. Fix the sections in the book to have the correct signatures. I've
   also marked them as `ignore`; there's no way to set the `no_std`
   feature for libc, so it pulls in the stdlib, so this wasn't even
   testing the actual thing it was testing. Better to just ignore.
2. Correcting libcore's docs for factual inaccuracy, and add a note
   about language items.

Fixes #33677

r? @alexcrichton
2016-07-16 16:55:59 +02:00
Guillaume Gomez
6a7596a328 Rollup merge of #34837 - GuillaumeGomez:better_example, r=nagisa
Improve float number example

r? @nagisa
2016-07-16 16:55:59 +02:00
Guillaume Gomez
ad7a697a62 Rollup merge of #34768 - alexcrichton:issue-audit, r=aturon
std: Correct tracking issue for SipHash{13,24}

The referenced tracking issue was closed and was actually about changing the
algorithm.

cc #34767
2016-07-16 16:55:58 +02:00
Steve Klabnik
fcecdac96d Fix up documentation around no_std
1. Fix the sections in the book to have the correct signatures. I've
   also marked them as `ignore`; there's no way to set the `no_std`
   feature for libc, so it pulls in the stdlib, so this wasn't even
   testing the actual thing it was testing. Better to just ignore.
2. Correcting libcore's docs for factual inaccuracy, and add a note
   about language items.

Fixes #33677
2016-07-15 15:41:31 -04:00
Guillaume Gomez
b10ac8a450 Improve float number example 2016-07-15 17:51:27 +02:00
Guillaume Gomez
1544ebee28 Rollup merge of #34804 - GuillaumeGomez:fix_ret, r=steveklabnik
Add examples for FpCategory

Fixes #29364.

r? @steveklabnik
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
bors
6998018bce Auto merge of #33907 - strake:decode_utf8, r=alexcrichton
add core::char::DecodeUtf8

See [issue](https://github.com/rust-lang/rust/issues/33906)
2016-07-14 02:45:29 -07:00
M Farkas-Dyck
837029fec1 add core::char::DecodeUtf8 2016-07-13 17:40:16 -08:00
ggomez
6b58baa5c8 Add examples for FpCategory 2016-07-13 17:32:23 +02: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
Guillaume Gomez
ea6cb8744a Rollup merge of #34749 - GuillaumeGomez:any_doc, r=steveklabnik
Improve std::any module doc

Fixes #29340.

r? @steveklabnik
2016-07-12 12:08:23 +02:00
Guillaume Gomez
9f4d2b6cd9 Rollup merge of #34736 - GuillaumeGomez:cells_doc, r=steveklabnik
Add missing examples for std::cell types

Fixes #29344.

r? @steveklabnik
2016-07-12 12:08:22 +02:00
Mike Hommey
4bfaa43eed doc: Mention that writeln! and println! always use LF
Fixes #34697
2016-07-12 14:39:16 +09:00
Alex Crichton
767e14983e std: Correct tracking issue for SipHash{13,24}
The referenced tracking issue was closed and was actually about changing the
algorithm.

cc #34767
2016-07-11 13:09:44 -07: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
Guillaume Gomez
76dd02025c Add missing examples for std::cell types 2016-07-11 17:13:36 +02:00
ubsan
c0bee60adb Make it nicer from @alexandermerritt 2016-07-10 23:17:02 +02:00
Guillaume Gomez
4c3cff6c65 Improve std::any module doc 2016-07-10 19:41:50 +02:00
ubsan
97003e5699 Switch around Examples and Alternatives 2016-07-10 06:13:34 +02:00
bors
f93aaf84cb Auto merge of #34365 - petrochenkov:deferr, r=eddyb
Some more pattern cleanup and bugfixing

The next part of https://github.com/rust-lang/rust/pull/34095

The most significant fixed mistake is definitions for partially resolved associated types not being updated after full resolution.
```
fn f<T: Fn()>(arg: T::Output) { .... } // <- the definition of T::Output was not updated in def_map
```
For this reason unstable associated types of stable traits, like `FnOnce::Output`, could be used in stable code when written in unqualified form. Now they are properly checked, this is a **[breaking-change]** (pretty minor one, but a crater run would be nice). The fix is not to use unstable library features in stable code, alternatively `FnOnce::Output` can be stabilized.

Besides that, paths in struct patterns and expressions `S::A { .. }` are now fully resolved as associated types. Such types cannot be identified as structs at the moment, i.e. the change doesn't make previously invalid code valid, but it improves error diagnostics.

Other changes: `Def::Err` is supported better (less chances for ICEs for erroneous code), some incorrect error messages are corrected, some duplicated error messages are not reported, ADT definitions are now available through constructor IDs, everything else is cleanup and code audit.

Fixes https://github.com/rust-lang/rust/issues/34209
Closes https://github.com/rust-lang/rust/issues/22933 (adds tests)

r? @eddyb
2016-07-09 15:16:21 -07:00