Commit Graph

15 Commits

Author SHA1 Message Date
Corey Farwell
b1a6c8bdd3 Stabilize [T]::rotate_{left,right}
https://github.com/rust-lang/rust/issues/41891
2018-02-22 20:12:38 -05:00
Cameron Hart
651ea8ea44 Stabilized #[repr(align(x))] attribute (RFC 1358) 2018-01-23 08:36:13 +11:00
Sebastian Dröge
5f4fc82142 Add unit tests for exact_chunks/exact_chunks_mut
These are basically modified copies of the chunks/chunks_mut tests.
2018-01-13 12:19:01 +02:00
Simon Sapin
21d899272a alloc_system: don’t assume MIN_ALIGN for small sizes, fix #45955
The GNU C library (glibc) is documented to always allocate with an alignment
of at least 8 or 16 bytes, on 32-bit or 64-bit platforms:
https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html

This matches our use of `MIN_ALIGN` before this commit.
However, even when libc is glibc, the program might be linked
with another allocator that redefines the `malloc` symbol and friends.
(The `alloc_jemalloc` crate does, in some cases.)

So `alloc_system` doesn’t know which allocator it calls,
and needs to be conservative in assumptions it makes.

The C standard says:

https://port70.net/%7Ensz/c/c11/n1570.html#7.22.3
> The pointer returned if the allocation succeeds is suitably aligned
> so that it may be assigned to a pointer to any type of object
> with a fundamental alignment requirement

https://port70.net/~nsz/c/c11/n1570.html#6.2.8p2
> A fundamental alignment is represented by an alignment less than
> or equal to the greatest alignment supported by the implementation
> in all contexts, which is equal to `_Alignof (max_align_t)`.

`_Alignof (max_align_t)` depends on the ABI and doesn’t seem to have
a clear definition, but it seems to match our `MIN_ALIGN` in practice.

However, the size of objects is rounded up to the next multiple
of their alignment (since that size is also the stride used in arrays).
Conversely, the alignment of a non-zero-size object is at most its size.
So for example it seems ot be legal for `malloc(8)` to return a pointer
that’s only 8-bytes-aligned, even if `_Alignof (max_align_t)` is 16.
2017-11-20 15:56:53 +01:00
Alex Crichton
6bc8f164b0 std: Remove rand crate and module
This commit removes the `rand` crate from the standard library facade as
well as the `__rand` module in the standard library. Neither of these
were used in any meaningful way in the standard library itself. The only
need for randomness in libstd is to initialize the thread-local keys of
a `HashMap`, and that unconditionally used `OsRng` defined in the
standard library anyway.

The cruft of the `rand` crate and the extra `rand` support in the
standard library makes libstd slightly more difficult to port to new
platforms, namely WebAssembly which doesn't have any randomness at all
(without interfacing with JS). The purpose of this commit is to clarify
and streamline randomness in libstd, focusing on how it's only required
in one location, hashmap seeds.

Note that the `rand` crate out of tree has almost always been a drop-in
replacement for the `rand` crate in-tree, so any usage (accidental or
purposeful) of the crate in-tree should switch to the `rand` crate on
crates.io. This then also has the further benefit of avoiding
duplication (mostly) between the two crates!
2017-11-08 20:41:17 -08:00
kennytm
143e2dcd5c
Disable the new Hasher tests on Emscripten. 2017-09-12 17:28:07 +08:00
kennytm
0bbe468271
impl Hasher for {&mut Hasher, Box<Hasher>} 2017-09-12 17:28:07 +08:00
Tatsuyuki Ishi
611b111139 Move unused-extern-crate to late pass 2017-08-27 19:02:24 +09:00
bors
1e60a477a3 Auto merge of #43245 - Gankro:drain-filter, r=sfackler
Add Vec::drain_filter

This implements the API proposed in #43244.

So I spent like half a day figuring out how to implement this in some awesome super-optimized unsafe way, which had me very confident this was worth putting into the stdlib.

Then I looked at the impl for `retain`, and was like "oh dang". I compared the two and they basically ended up being the same speed. And the `retain` impl probably translates to DoubleEndedIter a lot more cleanly if we ever want that.

So now I'm not totally confident this needs to go in the stdlib, but I've got two implementations and an amazingly robust test suite, so I figured I might as well toss it over the fence for discussion.
2017-08-15 22:28:23 +00:00
bors
82be83cf74 Auto merge of #43500 - murarth:string-retain, r=alexcrichton
Add method `String::retain`

Behaves like `Vec::retain`, accepting a predicate `FnMut(char) -> bool`
and reducing the string to only characters for which the predicate
returns `true`.
2017-08-15 16:21:28 +00:00
Murarth
618ac89d25 Add method String::retain
Behaves like `Vec::retain`, accepting a predicate `FnMut(char) -> bool`
and reducing the string to only characters for which the predicate
returns `true`.
2017-08-14 20:42:26 -07:00
Alex Crichton
3fae48107f std: Stabilize utf8_error_error_len feature
Stabilizes:

* `Utf8Error::error_len`

Closes #40494
2017-07-25 07:09:31 -07:00
Alex Crichton
46de2af063 std: Stabilize str_checked_slicing feature
Stabilized

* `<str>::get`
* `<str>::get_mut`
* `<str>::get_unchecked`
* `<str>::get_unchecked_mut`

Closes #39932
2017-07-25 07:09:31 -07:00
Alexis Beingessner
1af42261e1 Add Vec::drain_filter 2017-07-19 10:46:22 -04:00
Murarth
eadda7665e Merge crate collections into alloc 2017-06-13 23:37:34 -07:00