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.
bors [Fri, 1 Jun 2018 08:46:38 +0000 (08:46 +0000)]
Auto merge of #51060 - michaelwoerister:thread-safe-consts, r=Zoxc
Make const decoding thread-safe.
This is an alternative to https://github.com/rust-lang/rust/pull/50957. It's a proof of concept (e.g. it doesn't adapt metadata decoding, just the incr. comp. cache) but I think it turned out nice. It's rather simple and does not require passing around a bunch of weird closures, like we currently do.
If you (@Zoxc & @oli-obk) think this approach is good then I'm happy to finish and clean this up.
Note: The current version just spins when it encounters an in-progress decoding. I don't have a strong preference for this approach. Decoding concurrently is equally fine by me (or maybe even better because it doesn't require poisoning).
bors [Fri, 1 Jun 2018 03:24:54 +0000 (03:24 +0000)]
Auto merge of #51171 - faern:const-bswap-ctpop-cttz-ctlz, r=oli-obk
Make some std::intrinsics `const fn`s
Making some rustc intrinsics (`ctpop`, `cttz`, `ctlz` and `bswap`) `const fn`s.
This is a pre-step to being able to make `swap_bytes`, `to_be` and `from_be` constant functions. That in itself could be ergonomic and useful. But even better is that it would allow `Ipv4Addr::new` etc becoming `const fn`s as well. Which might be really useful since I find it quite common to want to define them as constants.
CrLF0710 [Tue, 29 May 2018 07:58:50 +0000 (15:58 +0800)]
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.
bors [Fri, 1 Jun 2018 01:09:25 +0000 (01:09 +0000)]
Auto merge of #50836 - jsgf:arc-downcast, r=SimonSapin
Arc downcast
Implement `downcast` for `Arc<Any + Send + Sync>` as part of #44608, and gated by the same `rc_downcast` feature.
This PR is mostly lightly-edited cut'n'paste.
This has two additional changes:
- The `downcast` implementation needs `Any + Send + Sync` implementations for `is` and `Debug`, and I added `downcast_ref` and `downcast_mut` for completeness/consistency. (Can these be insta-stabilized?)
- At @SimonSapin's suggestion, I converted `Arc` and `Rc` to use `NonNull::cast` to avoid an `unsafe` block in each which tidied things up nicely.
Mike Hommey [Thu, 31 May 2018 23:50:07 +0000 (08:50 +0900)]
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.
bors [Thu, 31 May 2018 20:44:04 +0000 (20:44 +0000)]
Auto merge of #51257 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests
Successful merges:
- #49546 (Stabilize short error format)
- #51123 (Update build instructions)
- #51146 (typeck: Do not pass the field check on field error)
- #51193 (Fixes some style issues in rustdoc "implementations on Foreign types")
- #51213 (fs: copy: Use File::set_permissions instead of fs::set_permissions)
- #51227 (mod.rs isn't beautiful)
- #51240 (Two minor parsing tweaks)
Guillaume Gomez [Thu, 31 May 2018 20:17:10 +0000 (22:17 +0200)]
Rollup merge of #51123 - akoserwal:master, r=Mark-Simulacrum
Update build instructions
It get stuck at the cloning step.
`./x.py build `
Updating only changed submodules
Updating submodule src/llvm
Submodule 'src/llvm' (https://github.com/rust-lang/llvm.git) registered for path 'src/llvm'
Cloning into '/home/username/rust/src/llvm'...
bors [Thu, 31 May 2018 17:47:12 +0000 (17:47 +0000)]
Auto merge of #51050 - symphorien:fstatat, r=kennytm
std::fs::DirEntry.metadata(): use fstatat instead of lstat when possible
When reading a directory with `read_dir`, querying metadata for a resulting `DirEntry` is done by building the whole path and then `lstat`ing it, which requires the kernel to resolve the whole path. Instead, one
can use the file descriptor to the enumerated directory and use `fstatat`. This make the resolving step
unnecessary.
This PR implements using `fstatat` on linux, android and emscripten.
## Compatibility across targets
`fstatat` is POSIX.
* Linux >= 2.6.19 according to https://linux.die.net/man/2/fstatat
* android according to https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt#392
* emscripten according to https://github.com/kripken/emscripten/blob/7f89560101843198787530731f40a65288f6f15f/system/include/libc/sys/stat.h#L76
The man page says "A similar system call exists on Solaris." but I haven't found it.
## Compatibility with old platforms
This was introduced with glibc 2.4 according to the man page. The only information I could find about the minimal version of glibc rust must support is this discussion https://internals.rust-lang.org/t/bumping-glibc-requirements-for-the-rust-toolchain/5111/10
The conclusion, if I understand correctly, is that currently rust supports glibc >= 2.3.4 but the "real" requirement is Centos 5 with glibc 2.5. This PR would make the minimal version 2.4, so this should be fine.
## Benefit
I did the following silly benchmark:
```rust
use std::io;
use std::fs;
use std::os::linux::fs::MetadataExt;
use std::time::Instant;
fn main() -> Result<(), io::Error> {
let mut n = 0;
let mut size = 0;
let start = Instant::now();
for entry in fs::read_dir("/nix/store/.links")? {
let entry = entry?;
let stat = entry.metadata()?;
size += stat.st_size();
n+=1;
}
println!("{} files, size {}, time {:?}", n, size, Instant::now().duration_since(start));
Ok(())
}
```
On warm cache, with current rust nightly:
``` 1014099 files, size 76895290022, time Duration { secs: 2, nanos: 65832118 }
```
(between 2.1 and 2.9 seconds usually)
With this PR:
``` 1014099 files, size 76895290022, time Duration { secs: 1, nanos: 581662953 }
```
(1.5 to 1.6 seconds usually).
approximately 40% faster :)
On cold cache there is not much to gain because path lookup (which we spare) would have been a cache hit:
Before
``` 1014099 files, size 76895290022, time Duration { secs: 391, nanos: 739874992 }
```
After
``` 1014099 files, size 76895290022, time Duration { secs: 388, nanos: 431567396 }
```
## Testing
The tests were run on linux `x86_64`
```
python x.py test src/tools/tidy
./x.py test src/libstd
```
and the above benchmark.
I did not test any other target.