Commit graph

2504 commits

Author SHA1 Message Date
Camelid
4af11126a8
Update bool and ! docs 2021-01-01 10:09:56 -08:00
bors
b33e234155 Auto merge of #79895 - Kerollmops:slice-group-by, r=m-ou-se
The return of the GroupBy and GroupByMut iterators on slice

According to https://github.com/rust-lang/rfcs/pull/2477#issuecomment-742034372, I am opening this PR again, this time I implemented it in safe Rust only, it is therefore much easier to read and is completely safe.

This PR proposes to add two new methods to the slice, the `group_by` and `group_by_mut`. These two methods provide a way to iterate over non-overlapping sub-slices of a base slice that are separated by the predicate given by the user (e.g. `Partial::eq`, `|a, b| a.abs() < b.abs()`).

```rust
let slice = &[1, 1, 1, 3, 3, 2, 2, 2];

let mut iter = slice.group_by(|a, b| a == b);
assert_eq!(iter.next(), Some(&[1, 1, 1][..]));
assert_eq!(iter.next(), Some(&[3, 3][..]));
assert_eq!(iter.next(), Some(&[2, 2, 2][..]));
assert_eq!(iter.next(), None);
```

[An RFC](https://github.com/rust-lang/rfcs/pull/2477) was open 2 years ago but wasn't necessary.
2020-12-31 12:00:43 +00:00
Clément Renault
8b53be6604
Replace the tracking issue for the slice_group_by feature 2020-12-31 12:13:03 +01:00
Clément Renault
a2d55d70c4
Add an extra example to the two methods 2020-12-31 11:57:40 +01:00
bors
8b002d5c34 Auto merge of #79150 - m-ou-se:bye-bye-doc-comment-hack, r=jyn514
Remove all doc_comment!{} hacks by using #[doc = expr] where needed.

This replaces about 200 cases of

`````rust
        doc_comment! {
            concat!("The smallest value that can be represented by this integer type.

# Examples

Basic usage:

```
", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");",
$EndFeature, "
```"),
            #[stable(feature = "assoc_int_consts", since = "1.43.0")]
            pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self;
        }
`````
by
```rust
        /// The smallest value that can be represented by this integer type.
        ///
        /// # Examples
        ///
        /// Basic usage:
        ///
        /// ```
        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");")]
        /// ```
        #[stable(feature = "assoc_int_consts", since = "1.43.0")]
        pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self;
```

---

**Note:** For a usable diff, make sure to enable 'ignore whitspace': https://github.com/rust-lang/rust/pull/79150/files?diff=unified&w=1
2020-12-31 06:14:41 +00:00
Mara Bos
4614cdd230 Fix typos. 2020-12-30 23:23:02 +01:00
Mara Bos
5694b8e471 Don't use doc_comment!{} hack in nonzero_leading_trailing_zeros!{}. 2020-12-30 22:49:08 +01:00
Mara Bos
27b81bf97a Remove all doc_comment!{} hacks by using #[doc = expr] where needed. 2020-12-30 22:49:08 +01:00
bors
9775ffef2a Auto merge of #80530 - m-ou-se:rollup-zit69ko, r=m-ou-se
Rollup of 9 pull requests

Successful merges:

 - #78934 (refactor: removing library/alloc/src/vec/mod.rs ignore-tidy-filelength)
 - #79479 (Add `Iterator::intersperse`)
 - #80128 (Edit rustc_ast::ast::FieldPat docs)
 - #80424 (Don't give an error when creating a file for the first time)
 - #80458 (Some Promotion Refactoring)
 - #80488 (Do not create dangling &T in Weak<T>::drop)
 - #80491 (Miri: make size/align_of_val work for dangling raw ptrs)
 - #80495 (Rename kw::Invalid -> kw::Empty)
 - #80513 (Add regression test for #80062)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-30 21:25:15 +00:00
Mara Bos
067f1b7030
Rollup merge of #80491 - RalfJung:dangling-of-val, r=oli-obk
Miri: make size/align_of_val work for dangling raw ptrs

This is needed for https://github.com/rust-lang/rust/issues/80365#issuecomment-752128105.

r? `@oli-obk`
2020-12-30 20:56:56 +00:00
Mara Bos
3d93dfdf6e
Rollup merge of #80488 - CAD97:drop-weak-without-reference, r=m-ou-se
Do not create dangling &T in Weak<T>::drop

Since at this point all strong pointers have been dropped, the wrapped `T` has also been dropped. As such, creating a `&T` to the dropped place is negligent at best (language UB at worst). Since we have `Layout::for_value_raw` now, use that instead of `Layout::for_value` to avoid creating the `&T`.

This does have implications for custom (potentially thin) DSTs, though much less severe than those discussed in #80407. Specifically, one of two things has to be true:

- It has to be possible to use a `*const T` to a dropped (potentially custom, potentially thin) unsized tailed object to determine the layout (size/align) of the object. This is what is currently implemented (though with `&T` instead of `&T`). The validity of reading some location after it has been dropped is an open question IIUC (https://github.com/rust-lang/unsafe-code-guidelines/issues/188) (except when the whole type is `Copy`, per `drop_in_place`'s docs).
  In this design, custom DSTs would get a `*mut T` and use that to return layout, and must be able to do so while in the "zombie" (post-drop, pre-free) state.
- `RcBox`/`ArcInner` compute and store layout eagerly, so that they don't have to ask the type for its layout after dropping it.

Importantly, this is already true today, as you can construct `Rc<DST>`, create a `Weak<DST>`, and drop the `Rc` before the `Weak`. This PR is a strict improvement over the status quo, and the above question about potentially thin DSTs will need to be resolved by any custom DST proposal.
2020-12-30 20:56:54 +00:00
Mara Bos
9cf24388d1
Rollup merge of #79479 - camelid:intersperse, r=m-ou-se
Add `Iterator::intersperse`

This is a rebase of #75784. I'm hoping to push this past the finish line!

cc `@jonas-schievink`
2020-12-30 20:56:47 +00:00
Mara Bos
242a252687
Rollup merge of #78934 - DeveloperC286:issue_60302_vec, r=m-ou-se
refactor: removing library/alloc/src/vec/mod.rs ignore-tidy-filelength

This PR removes the need for ignore-tidy-filelength for library/alloc/src/vec/mod.rs which is part of the issue #60302

It is probably easiest to review this PR by looking at it commit by commit rather than looking at the overall diff.
2020-12-30 20:56:45 +00:00
Camelid
40bbb7fad4 Add tracking issue 2020-12-30 12:07:28 -08:00
Jonas Schievink
7786a6b334 Add Iterator::intersperse 2020-12-30 12:07:19 -08:00
bors
e226704685 Auto merge of #80511 - Mark-Simulacrum:bump-stage0, r=pietroalbini
Bump bootstrap compiler to 1.50 beta

r? `@pietroalbini`
2020-12-30 18:32:31 +00:00
Mara Bos
16834a8f52
Fix rustdoc link in vec/into_iter.rs. 2020-12-30 15:35:02 +00:00
bors
507bff92fa Auto merge of #80510 - JohnTitor:rollup-gow7y0l, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #80185 (Fix ICE when pointing at multi bytes character)
 - #80260 (slightly more typed interface to panic implementation)
 - #80311 (Improvements to NatVis support)
 - #80337 (Use `desc` as a doc-comment for queries if there are no doc comments)
 - #80381 (Revert "Cleanup markdown span handling")
 - #80492 (remove empty wraps, don't return Results from from infallible functions)
 - #80509 (where possible, pass slices instead of &Vec or &String (clippy::ptr_arg))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-30 15:30:56 +00:00
Mark Rousskov
fe031180d0 Bump bootstrap compiler to 1.50 beta 2020-12-30 09:27:19 -05:00
Yuki Okushi
00741b8810
Rollup merge of #80260 - RalfJung:less-untyped-panics, r=m-ou-se
slightly more typed interface to panic implementation

The panic payload is currently being passed around as a `usize`. However, it actually is a pointer, and the involved types are available on all ends of this API, so I propose we use the proper pointer type to avoid some casts. Avoiding int-to-ptr casts also makes this code work with `miri -Zmiri-track-raw-pointers`.
2020-12-30 22:49:17 +09:00
Ralf Jung
f76bae9244 CTFE: test size/align_of_val_raw on dangling pointers 2020-12-30 14:29:33 +01:00
bors
bbcaed03bf Auto merge of #79684 - usbalbin:const_copy, r=oli-obk
Make copy[_nonoverlapping] const

Constifies
* `intrinsics::copy` and `intrinsics::copy_nonoverlapping`
* `ptr::read` and `ptr::read_unaligned`
  * `*const T::read` and `*const T::read_unaligned`
  * `*mut T::read` and `*mut T::read_unaligned`
* `MaybeUninit::assume_init_read`
2020-12-30 12:43:02 +00:00
Yuki Okushi
9576ee97d1
Rollup merge of #80477 - tmiasko:safe-forget, r=oli-obk
Make forget intrinsic safe
2020-12-30 18:15:25 +09:00
CAD97
81685e9ad8 Do not create dangling &T in Weak<T>::drop 2020-12-29 15:42:41 -05:00
C
f7a6f0cae3 docs: fixing references 2020-12-29 14:03:30 +00:00
C
80f10d7aa7 fix: moved import into #[cfg(test)] 2020-12-29 14:03:30 +00:00
C
2de8356f60 style: applying Rust style 2020-12-29 14:03:30 +00:00
C
6002b280f1 refactor: removing // ignore-tidy-filelength 2020-12-29 14:03:30 +00:00
C
bd49a60f29 refactor: moved SpecExtend into spec_extend.rs 2020-12-29 14:03:30 +00:00
C
d24a27797d refactor: moving SpecFromIter into spec_from_iter.rs 2020-12-29 14:03:30 +00:00
C
56d82b3dcc refactor: moved SpecFromIterNested to spec_from_iter_nested.rs 2020-12-29 14:03:30 +00:00
C
9e08ce7190 refactor: moved InPlaceDrop into in_place_drop.rs 2020-12-29 14:03:30 +00:00
C
a3f3fc5aed refactor: moved SetLenOnDrop to set_len_on_drop 2020-12-29 14:03:30 +00:00
C
a2f4bc0d18 refactor: moved SpecFromElem to spec_from_elem.rs 2020-12-29 14:03:30 +00:00
C
dc46013248 refactor: moved PartialEq into partial_eq 2020-12-29 14:03:30 +00:00
C
5ac6709b95 refactor: moving SourceIterMarker into source_iter_marker.rs 2020-12-29 14:03:30 +00:00
C
840c4e2873 refactor: moved IsZero into is_zero.rs 2020-12-29 14:03:30 +00:00
C
2a1248976a refactor: moving AsIntoIter into into_iter.rs 2020-12-29 14:03:29 +00:00
C
93613901d0 refactor: moved IntoIter into into_iter.rs 2020-12-29 14:03:29 +00:00
C
2580822b91 refactor: moved Vec impl Cow into cow.rs 2020-12-29 14:03:29 +00:00
C
6bf9608f9f refactor: moving Drain into drain.rs 2020-12-29 14:03:29 +00:00
C
17593f258b refactor: moving Splice into splice.rs 2020-12-29 14:03:29 +00:00
C
434e5d1422 refactor: moving DrainFilter into drain_filter.rs 2020-12-29 14:03:29 +00:00
C
5182776c6c refactor: moving vec.rs to vec/mod.rs 2020-12-29 14:03:29 +00:00
BlackHoleFox
5449a42a1c Fix small typo in time comment 2020-12-29 02:10:29 -06:00
Tomasz Miąsko
5718cc2f9b Make forget intrinsic safe 2020-12-29 00:00:00 +00:00
Mara Bos
e3d26e007c
Rollup merge of #80448 - m-ou-se:deque-range-version, r=m-ou-se
Fix stabilization version of deque_range feature.

See https://github.com/rust-lang/rust/pull/79022#issuecomment-751315315
2020-12-28 19:09:35 +00:00
Mara Bos
5a081620b0
Rollup merge of #80431 - xfix:add-chr-as-doc-alias, r=steveklabnik
Add "chr" as doc alias to char::from_u32

Many programming languages provide a function called `chr` - Perl, Python, PHP, Visual Basic, SQL. This change makes `char::from_u32` easier to discover in the documentation.

`ord` is not added as its name conflicts with `Ord` trait, and it's not exactly clear what it could point to (`<u32 as From<char>>::from`?). I don't think it's exactly necessary, as `char::from_u32` documentation page says you can do reverse conversion with `as` operator anyway.
2020-12-28 19:09:34 +00:00
Mara Bos
e351a3b2ec
Rollup merge of #80430 - xfix:add-length-as-doc-alias, r=steveklabnik
Add "length" as doc alias to len methods

Currently when searching for `length` there are no results: https://doc.rust-lang.org/std/?search=length. This makes `len` methods appear when searching for `length`.
2020-12-28 19:09:32 +00:00
Mara Bos
7003537df6
Rollup merge of #80398 - CAD97:fix-80365, r=dtolnay
Use raw version of align_of in rc data_offset

This was missed in #73845 when switching to use the raw operators.
Fixes #80365
2020-12-28 19:09:24 +00:00