Mark Simulacrum [Mon, 4 Jun 2018 00:18:03 +0000 (18:18 -0600)]
Rollup merge of #51299 - faern:const-int-ops, r=oli-obk
const fn integer operations
A follow up to #51171
Fixes #51267
Makes a lot of the integer methods (`swap_bytes`, `count_ones` etc) `const fn`s. See #51267 for a discussion about why this is wanted and the solution used.
Mark Simulacrum [Mon, 4 Jun 2018 00:18:02 +0000 (18:18 -0600)]
Rollup merge of #51288 - Mark-Simulacrum:delete-is-import, r=eddyb
Remove rustdoc-specific is_import field from HIR
Fixes #47100.
I believe that there is no need to check for the name being the same, as this
part of rustdoc seems to be strictly interested in exploring "public modules."
Re-exports from the same module cannot visit another module; and, re-exports
cannot export items with a greater visibility than that item declares.
Therefore, I think this code is either sufficient, or in fact does more than
is necessary, depending on whether rustdoc cares about the re-export itself.
bors [Sun, 3 Jun 2018 03:13:43 +0000 (03:13 +0000)]
Auto merge of #51319 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 6 pull requests
Successful merges:
- #51143 (Specify that packed types must derive, not implement, Copy)
- #51226 (Make Layout's align a NonZeroUsize)
- #51297 (Fix run button style)
- #51306 (impl Default for &mut str)
- #51312 (Clarify the difference between get_mut and into_mut for OccupiedEntry)
- #51313 (use type name in E0599 enum variant suggestion)
Mark Simulacrum [Sun, 3 Jun 2018 01:55:09 +0000 (19:55 -0600)]
Rollup merge of #51312 - frewsxcv:clarify-hash-map-entry-get-mut, r=dtolnay
Clarify the difference between get_mut and into_mut for OccupiedEntry
The examples for both hash_map::OccupiedEntry::get_mut and
hash_map::OccupiedEntry::into_mut were almost identical. This led to some
confusion over the difference, namely why you would ever use get_mut when
into_mut gives alonger lifetime. Reddit thread:
https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps
This commit adds two lines and a comment to the example, to show that the
entry object can be re-used after calling get_mut.
Mark Simulacrum [Sun, 3 Jun 2018 01:55:06 +0000 (19:55 -0600)]
Rollup merge of #51226 - gnzlbg:nonzero_align, r=SimonSapin
Make Layout's align a NonZeroUsize
This PR makes the `Layout`'s align field a `NonZeroUsize` since it cannot ever be zero, not even while building a `Layout`. It also contains some drive-by minor cleanups over the docs and the code, like updating the documented error types, or using the `size()` and `align()` methods instead of accessing the fields directly (the latter was required for the `NonZeroUsize` change anyways).
bors [Sat, 2 Jun 2018 21:32:47 +0000 (21:32 +0000)]
Auto merge of #51310 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 6 pull requests
Successful merges:
- #50167 ( Add as_nanos function to Duration)
- #50919 (Provide more context for what the {f32,f64}::EPSILON values represent.)
- #51124 (Reword {ptr,mem}::replace docs.)
- #51147 (Stabilize SliceIndex trait.)
- #51291 (Fix typos of ‘ambiguous’)
- #51302 (Permit building rustdoc without compiler artifacts)
Clarify the difference between get_mut and into_mut for OccupiedEntry
The examples for both hash_map::OccupiedEntry::get_mut and
hash_map::OccupiedEntry::into_mut were almost identical. This led
to some confusion over the difference, namely why you would ever
use get_mut when into_mut gives alonger lifetime. Reddit thread:
https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps
This commit adds two lines and a comment to the example, to show
that the entry object can be re-used after calling get_mut.
Mark Simulacrum [Sat, 2 Jun 2018 19:14:27 +0000 (13:14 -0600)]
Rollup merge of #51291 - evincarofautumn:master, r=oli-obk
Fix typos of ‘ambiguous’
I had trouble finding this code because of the typo after it was [referenced in a tweet](https://twitter.com/bstrie/status/1002751044605153280). Also fixes an identical but unrelated typo in a comment.
Mark Simulacrum [Sat, 2 Jun 2018 19:14:23 +0000 (13:14 -0600)]
Rollup merge of #50919 - frewsxcv:frewsxcv-epsilon, r=steveklabnik
Provide more context for what the {f32,f64}::EPSILON values represent.
Introduce the 'machine epsilon' term because if one googles 'epsilon', they might stumble upon https://en.wikipedia.org/wiki/Epsilon_numbers_(mathematics) instead of https://en.wikipedia.org/wiki/Machine_epsilon
Mark Simulacrum [Sat, 2 Jun 2018 19:14:22 +0000 (13:14 -0600)]
Rollup merge of #50167 - fintelia:duration-nanos, r=sfackler
Add as_nanos function to Duration
Duration has historically lacked a way to get the actual number of nanoseconds it contained as a normal Rust type because u64 was of insufficient range, and f64 of insufficient precision. The u128 type solves both issues, so I propose adding an `as_nanos` function to expose the capability.
bors [Sat, 2 Jun 2018 15:26:26 +0000 (15:26 +0000)]
Auto merge of #51063 - mixi:musl-bootstrap, r=alexcrichton
Fix building rustc on and for musl hosts.
This fixes all problems I had when trying to compile rustc on a musl-based distribution (with `crt-static = false` in `config.toml`).
This is a fixed version of what ended up being #50105, making it possible to compile rustc on musl targets.
The differences to the old (now merged and subsequently reverted) pull request are:
- The commit (6d9154a830dd9773fe8a4e34e1fc3dfb1ca6f935) that caused the regression for which the original commits were reverted in #50709 is left out. This means the corresponding bug #36710 is still not fixed with `+crt-static`.
- The test for issue 36710 is skipped for musl targets (until the issue is properly fixed).
- Building cargo-vendor if `crt-static = false` is needed was broken (cargo-vendor links to some shared libraries if they exist on the system and this produces broken binaries with `+crt-static`)
bors [Sat, 2 Jun 2018 11:14:14 +0000 (11:14 +0000)]
Auto merge of #51015 - nikomatsakis:issue-50672-remove-extern-crate-idiom, r=alexcrichton
merge unused-extern-crate and unnecessary-extern-crate lints
Extend the `unused_extern_crates` lint to offer a suggestion to remove the extern crate and remove the `unnecessary_extern_crate` lint.
Still a few minor issues to fix:
- [x] this *does* now leave a blank line... (defer to https://github.com/rust-lang/rust/issues/51176)
- idea: extend the span to be replaced by 1 character if the next character is a `\n`
- [x] what about macros? do we need to watch out for that? (defer to https://github.com/rust-lang/rust/issues/48704)
- [x] also it doesn't work for `extern crate foo; fn main() { foo::bar(); }`
- this is subtle: the `foo` might be shadowing a glob import too, can't always remove
- defer to https://github.com/rust-lang/rust/issues/51177
- [x] we also don't do the `pub use` rewrite thang (https://github.com/rust-lang/rust/issues/51013)
Spun off from https://github.com/rust-lang/rust/pull/51010
bors [Sat, 2 Jun 2018 00:58:29 +0000 (00:58 +0000)]
Auto merge of #51287 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 5 pull requests
Successful merges:
- #51135 (Tweak output on E0599 for assoc fn used as method)
- #51152 (Replace `if` with `if and only if` in the definition dox of `Sync`)
- #51262 (Add missing whitespace in num example)
- #51272 (Remove feature flag from fs::read_to_string example)
- #51286 (Pull 1.26.2 release notes into master)
Mark Simulacrum [Fri, 1 Jun 2018 23:25:14 +0000 (17:25 -0600)]
Rollup merge of #51152 - crlf0710:patch-1, r=kennytm
Replace `if` with `if and only if` in the definition dox of `Sync`
The old text was: "The precise definition is: a type `T` is `Sync` if `&T` is Send."
Since we've also got
```
impl<'a, T> Send for &'a T
where
T: Sync + ?Sized,
```
I purpose we can change the `if` to `if and only if` to make it more precise.
Mark Simulacrum [Fri, 1 Jun 2018 23:25:13 +0000 (17:25 -0600)]
Rollup merge of #51135 - estebank:sugg-7575, r=oli-obk
Tweak output on E0599 for assoc fn used as method
- Use suggestion instead of `help` when possible
- Add primary span label
- Remove incorrect `help` suggestion using incorrect syntax
- Do not refer to only one possible candidate as `candidate #1`, refer to it as `the candidate`
bors [Fri, 1 Jun 2018 18:25:19 +0000 (18:25 +0000)]
Auto merge of #51163 - Amanieu:hashmap_layout, r=SimonSapin
Simplify HashMap layout calculation by using Layout
`RawTable` uses a single allocation to hold both the array of hashes and the array of key/value pairs. This PR changes `RawTable` to use `Layout` when calculating the amount of memory to allocate instead of performing the calculation manually.
bors [Fri, 1 Jun 2018 16:16:30 +0000 (16:16 +0000)]
Auto merge of #50340 - Emerentius:master, r=alexcrichton
optimize joining for slices
This improves the speed of string joining up to 3x.
It removes the boolean flag check every iteration, eliminates repeated bounds checks and adds a fast paths for small separators up to a len of 4 bytes
These optimizations gave me ~10%, ~50% and ~80% improvements respectively over the previous speed. Those are multiplicative.
3x improvement happens for the optimal case of joining many small strings together in my microbenchmarks. Improvements flatten out for larger strings of course as more time is spent copying bits around. I've run a few benchmarks [with this code](https://github.com/Emerentius/join_bench). They are pretty noise despite high iteration counts, but in total one can see the trends.
The string joining with small or empty separators is now ~50% faster than the old concatenation (small strings). The same approach can also improve the performance of joining into vectors.
If this approach is acceptable, I can apply it for concatenation and for vectors as well. Alternatively, concat could just call `.join("")`.
Emerentius [Mon, 7 May 2018 15:37:13 +0000 (17:37 +0200)]
add more join tests
old tests cover the new fast path of str joining already
this adds tests for joining into Strings with long separators (>4 byte) and
for joining into Vec<T>, T: Clone + !Copy. Vec<T: Copy> will be
specialised when specialisation type inference bugs are fixed.
bors [Fri, 1 Jun 2018 14:05:57 +0000 (14:05 +0000)]
Auto merge of #51264 - glandium:oom, r=alexcrichton
Make the OOM hook return `()` rather than `!`
Per discussion in https://github.com/rust-lang/rust/issues/51245#issuecomment-393651083
This allows more flexibility in what can be done with the API. This also
splits `rtabort!` into `dumb_print` happening in the default hook and
`abort_internal`, happening in the actual oom handler after calling the
hook. Registering an empty function thus makes the oom handler not print
anything but still abort.