1981 Commits

Author SHA1 Message Date
Jake Goulding
6600cf6040 Add {String,Vec}::into_raw_parts 2019-10-25 11:25:52 -04:00
Jake Goulding
dce8fabc62 Use ManuallyDrop in examples for {Vec,String}::from_raw_parts 2019-10-25 11:22:53 -04:00
Jake Goulding
0d21d257c9 Remove unneeded pointer casting 2019-10-25 11:20:47 -04:00
Mazdak Farrokhzad
4b9fbfbc29
Rollup merge of #65144 - clarfon:moo, r=sfackler
Add Cow::is_borrowed and Cow::is_owned

Implements #65143.
2019-10-23 22:19:08 +02:00
Clar Fon
eeb549bfc3 Add Cow::is_borrowed and Cow::is_owned 2019-10-22 19:56:41 -04:00
Mateusz Mikuła
95c06a2970 Apply clippy::needless_return suggestions 2019-10-22 19:23:10 +02:00
Mazdak Farrokhzad
2de4f4335e
Rollup merge of #65505 - RalfJung:rc, r=Centril
Rc: value -> allocation

See https://github.com/rust-lang/rust/issues/64484. This does not yet edit `Arc` as I first wanted to be sure we agree on the terminology the way it actually ends up. "value" as a term appears a lot in this file, and sometimes it refers to the value stored inside the `RcBox` while sometimes it refers to the `RcBox` itself. I tried to properly tease these apart but may have made some mistakes. The former should now always be called "inner value" and the latter "allocation".

One area where I was very unsure of which terminology is dropping: the `value` field of the `RcBox` will get dropped *earlier* than the `RcBox` itself if there are weak references. I decided that "dropping the value stored in the allocation" refers to dropping the value field, while "destroying the allocation" refers to actually freeing its backing memory.

r? @Centril
2019-10-19 16:00:56 +02:00
Mazdak Farrokhzad
a6b5c80dbc
Rollup merge of #65226 - ssomers:master, r=bluss
BTreeSet symmetric_difference & union optimized

No scalability changes, but:
- Grew the cmp_opt function (shared by symmetric_difference & union) into a MergeIter, with less memory overhead than the pairs of Peekable iterators now, speeding up ~20% on my machine (not so clear on Travis though, I actually switched it off there because it wasn't consistent about identical code). Mainly meant to improve readability by sharing code, though it does end up using more lines of code. Extending and reusing the MergeIter in btree_map might be better, but I'm not sure that's possible or desirable. This MergeIter probably pretends to be more generic than it is, yet doesn't declare to be an iterator because there's no need to, it's only there to help construct genuine iterators SymmetricDifference & Union.
- Compact the code of #64820 by moving if/else into match guards.

r? @bluss
2019-10-19 16:00:53 +02:00
Ralf Jung
1b3846359a do all the same edits with Arc 2019-10-19 13:48:02 +02:00
Ralf Jung
52a31f7a00 some more Rc tweaks 2019-10-19 13:47:32 +02:00
Ralf Jung
696cba6e25 the exampleis about drop, not (de)allocation 2019-10-19 10:14:10 +02:00
Mazdak Farrokhzad
beec0a5db4
Rollup merge of #65174 - SimonSapin:zero-box, r=alexcrichton
Fix zero-size uninitialized boxes

Requesting a zero-size allocation is not allowed, return a dangling pointer instead.

CC https://github.com/rust-lang/rust/issues/63291#issuecomment-538692745
2019-10-19 07:10:03 +02:00
Simon Sapin
227db40a98 Uninitialized boxes: add test for zero-size allocations 2019-10-18 23:57:22 +02:00
Stein Somers
56974329d1 BTreeSet symmetric_difference & union optimized, cleaned 2019-10-18 00:11:32 +02:00
Ralf Jung
c0b7e769a0 example for padding any format 2019-10-17 23:02:09 +02:00
Ralf Jung
4e6efe4811 reorder fmt docs for more clarity 2019-10-17 21:22:46 +02:00
Ralf Jung
868a77263a more consistency and clarification 2019-10-17 19:51:42 +02:00
Ralf Jung
470e9d2789 Rc: value -> allocation 2019-10-17 19:37:05 +02:00
Thomas Lively
2bf59bea48 Upgrade Emscripten targets to use upstream LLVM backend
- Compatible with Emscripten 1.38.46-upstream or later upstream.
 - Refactors the Emscripten target spec to share code with other wasm
   targets.
 - Replaces the old incorrect wasm32 C call ABI with the correct one,
   preserving the old one as wasm32_bindgen_compat for wasm-bindgen
   compatibility.
 - Updates the varargs ABI used by Emscripten and deletes the old one.
 - Removes the obsolete wasm32-experimental-emscripten target.
 - Uses EMCC_CFLAGS on CI to avoid the timeout problems with #63649.
2019-10-16 17:06:48 -07:00
Simon Sapin
ca1cfdab78 Uninitialized boxes: check for zero-size allocation based on Layout::size 2019-10-16 20:32:58 +02:00
Tyler Mandry
e38639fe12
Rollup merge of #65332 - RalfJung:fmt, r=cramertj
std::fmt: reorder docs

This moves the "Formatting Parameters" section up above right after the discussion of named and positional arguments. Then comes the "Syntax" section, summarizing the discussion of format string syntax.
And only *then* we get to "Formatting Traits" -- that section has some *huge* code examples, so it really should not interrupt the discussion of the grammar. Also users are much more likely to come here to learn about the format string grammar than to come here to learn about the `Binary` trait.
2019-10-14 17:52:37 -07:00
Mazdak Farrokhzad
92b36ce4a7
Rollup merge of #65373 - kalabukdima:patch-1, r=jonas-schievink
Fix typo in docs for `Rc`

r? @czipperz
2019-10-13 19:17:17 +02:00
Mazdak Farrokhzad
7c20a8ddb8
Rollup merge of #65214 - Amanieu:cfg_atomic, r=alexcrichton
Split non-CAS atomic support off into target_has_atomic_load_store

This PR implements my proposed changes in https://github.com/rust-lang/rust/issues/32976#issuecomment-518542029 by removing `target_has_atomic = "cas"` and splitting `target_has_atomic` into two separate `cfg`s:

* `target_has_atomic = 8/16/32/64/128`: This indicates the largest width that the target can atomically CAS (which implies support for all atomic operations).
* ` target_has_atomic_load_store = 8/16/32/64/128`: This indicates the largest width that the target can support loading or storing atomically (but may not support CAS).

cc #32976

r? @alexcrichton
2019-10-13 19:17:04 +02:00
kalabukdima
e67fa776ee
Fix typo in docs for Rc 2019-10-13 15:46:28 +03:00
Mazdak Farrokhzad
4dc0b8aa5b
Rollup merge of #65069 - crgl:clone-from-vec-deque, r=bluss
Implement Clone::clone_from for VecDeque

See #28481. For simple data types with the target much longer than the source, this implementation can be significantly slower than the default (probably due to the use of truncate). However, it should be substantially faster when cloning from nested data structures with similar shapes or when cloning from VecDeques with similar lengths, hopefully more common use cases for clone_from.
2019-10-13 13:34:29 +02:00
Ralf Jung
504cc20844 remove confusing and redundant subsection 2019-10-12 15:35:15 +02:00
Ralf Jung
f727f8ae5e move Formatting Traits down 2019-10-12 13:31:58 +02:00
Ralf Jung
a14601e06c std::fmt: move format string grammar to the bottom 2019-10-12 13:26:31 +02:00
bors
6767d9b90b Auto merge of #64877 - lzutao:stabilize-repeat_generic_slice, r=SimonSapin
Stabilize `slice::repeat` (feature `repeat_generic_slice`)

Closes #48784
r? @SimonSapin
2019-10-11 18:03:20 +00:00
Charles Gleason
d21eeb110c Override nth for VecDeque Iter and IterMut 2019-10-10 22:49:21 -04:00
Charles Gleason
10671f10c3 Add tests for VecDeque clone_from 2019-10-10 22:49:20 -04:00
Charles Gleason
91cf02cfa7 Implement Clone::clone_from for VecDeque 2019-10-10 22:49:17 -04:00
Jon Gjengset
45aca119a6
Stabilize mem::take (mem_take)
Tracking issue: https://github.com/rust-lang/rust/issues/61129
2019-10-08 18:04:18 -04:00
Amanieu d'Antras
dfe76a1093 Split non-CAS atomic support off into target_has_atomic_load_store 2019-10-08 20:34:30 +01:00
Simon Sapin
23d3ff1b97 Fix zero-size uninitialized boxes
Requesting a zero-size allocation is not allowed,
return a dangling pointer instead.

CC https://github.com/rust-lang/rust/issues/63291#issuecomment-538692745
2019-10-06 23:48:55 +02:00
Jonas Schievink
02f36e52a6 Hide the Iterator specialization behind a trait 2019-10-05 15:33:25 +02:00
Jonas Schievink
2cd5030ef5 Deny specializing items not in the parent impl 2019-10-05 15:33:24 +02:00
Mazdak Farrokhzad
c4f8fd2bf5
Rollup merge of #64975 - crgl:clone-from-linked-list, r=bluss
Implement Clone::clone_from for LinkedList

See #28481. This represents a substantial speedup when the list sizes are comparable, and shouldn't ever be significantly worse. Technically split_off is doing an unnecessary search, but the code is hopefully cleaner as a result. I'm happy to rework anything that needs to be changed as well!
2019-10-03 04:08:15 +02:00
Charles Gleason
864e6feaf8 Add test for LinkedList clone_from 2019-10-02 15:18:31 -04:00
Charles Gleason
5055d4b1c6 Use zipped iterators in clone_from for LinkedList 2019-10-02 11:29:12 -04:00
Lzu Tao
4a2ae451e3 Stabilize slice::repeat (feature repeat_generic_slice) 2019-10-02 04:48:15 +00:00
Charles Gleason
7b480cdec6 Implement Clone::clone_from for LinkedList 2019-10-01 18:23:08 -04:00
Mazdak Farrokhzad
7628cada4f
Rollup merge of #64912 - lzutao:unneeded-main-doc, r=jonas-schievink
Remove unneeded `fn main` blocks from docs

## [No whitespace diff](https://github.com/rust-lang/rust/pull/64912/files?w=1)
2019-10-01 23:56:23 +02:00
Stein Somers
d132a70bf4 BTreeSet intersection, difference & is_subnet optimizations 2019-10-01 15:50:11 +02:00
Lzu Tao
6c1b447f2e Remove unneeded fn main blocks from docs 2019-10-01 11:55:46 +00:00
Tyler Mandry
a8ed9bfe02
Rollup merge of #64893 - SimonSapin:vec-of-option-box, r=sfackler
Zero-initialize `vec![None; n]` for `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>`
2019-09-30 14:38:27 -07:00
Simon Sapin
6c01c0e9b5 Zero-initialize vec![None; n] for Option<&T>, Option<&mut T> and Option<Box<T>> 2019-09-29 11:14:59 +02:00
Simon Sapin
ce60da497b Fix vec![x; n] with null raw fat pointer zeroing the pointer metadata
https://github.com/rust-lang/rust/pull/49496 introduced specialization based on:

```
unsafe impl<T: ?Sized> IsZero for *mut T {
    fn is_zero(&self) -> bool {
        (*self).is_null()
    }
}
```

… to call `RawVec::with_capacity_zeroed` for creating `Vec<*mut T>`,
which is incorrect for fat pointers
since `<*mut T>::is_null` only looks at the data component.
That is, a fat pointer can be “null” without being made entirely of zero bits.

This commit fixes it by removing the `?Sized` bound on this impl
(and the corresponding `*const T` one).
This regresses `vec![x; n]` with `x` a null raw slice of length zero,
but that seems exceptionally uncommon.
(Vtable pointers are never null, so raw trait objects would not take
the fast path anyway.

An alternative to keep the `?Sized` bound
(or even generalize to `impl<U: Copy> IsZero for U`)
would be to cast to `&[u8]` of length `size_of::<U>()`,
but the optimizer seems not to be able to propagate alignment information
and sticks with comparing one byte at a time:

https://rust.godbolt.org/z/xQFkwL

----

Without the library change, the new test fails as follows:

```
---- vec::vec_macro_repeating_null_raw_fat_pointer stdout ----
[src/liballoc/tests/vec.rs:1301] ptr_metadata(raw_dyn) = 0x00005596ef95f9a8
[src/liballoc/tests/vec.rs:1306] ptr_metadata(vec[0]) = 0x0000000000000000
thread 'vec::vec_macro_repeating_null_raw_fat_pointer' panicked at 'assertion failed: vec[0] == null_raw_dyn', src/liballoc/tests/vec.rs:1307:5
```
2019-09-29 11:06:53 +02:00
Lzu Tao
c482c84142 Stabilize map_get_key_value feature 2019-09-27 11:21:57 +00:00
Mark Rousskov
f359a94849 Snap cfgs to new beta 2019-09-25 08:42:46 -04:00