Commit Graph

405 Commits

Author SHA1 Message Date
Felix S. Klock II
48af7189c2 Expand impl FromIterator for Option doc to include example of early termination. 2019-03-22 12:44:08 +01:00
kennytm
7c009a4df7
Rollup merge of #59231 - matklad:copied, r=Centril
Stabilize Option::copied

closes https://github.com/rust-lang/rust/issues/57126
2019-03-16 22:42:00 +08:00
Aleksey Kladov
08f264d576 Stabilize Option::copied
closes https://github.com/rust-lang/rust/issues/57126
2019-03-16 14:11:23 +03:00
Chris Gregory
9a61580d40 Option and Result: Add references to documentation of as_ref and as_mut 2019-03-15 16:42:10 -04:00
Alexandra V
020539e230 Remove stray ` in the documentation for the FromIterator implementation for Option 2019-03-03 13:25:55 +01:00
kennytm
e3a8f7db47
Rollup merge of #58553 - scottmcm:more-ihle, r=Centril
Use more impl header lifetime elision

Inspired by seeing explicit lifetimes on these two:

- https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator
- https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not

And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore.

Most of the changes in here fall into two big categories:

- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`)

- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)

I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm).

I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-20 11:59:10 +08:00
Scott McMurray
3bea2ca49d Use more impl header lifetime elision
There are two big categories of changes in here

- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)

I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-17 19:42:36 -08:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad
6d7a4a6e4c stabilize transpose_result in 1.33 2019-01-13 06:15:44 +01:00
bors
a7be40c65a Auto merge of #56534 - xfix:copied, r=@SimonSapin
Add unstable Iterator::copied()

Initially suggested at https://github.com/bluss/rust-itertools/pull/289, however the maintainers of itertools suggested this may be better of in a standard library.

The intent of `copied` is to avoid accidentally cloning iterator elements after doing a code refactoring which causes a structure to be no longer `Copy`. This is a relatively common pattern, as it can be seen by calling `rg --pcre2 '[.]map[(][|](?:(\w+)[|] [*]\1|&(\w+)[|] \2)[)]'` on Rust main repository. Additionally, many uses of `cloned` actually want to simply `Copy`, and changing something to be no longer copyable may introduce unnoticeable performance penalty.

Also, this makes sense because the standard library includes `[T].copy_from_slice` to pair with `[T].clone_from_slice`.

This also adds `Option::copied`, because it makes sense to pair it with `Iterator::copied`. I don't think this feature is particularly important, but it makes sense to update `Option` along with `Iterator` for consistency.
2018-12-26 19:39:19 +00:00
Konrad Borowski
2fcdc9c15d Add a tracking issue for Option::copied 2018-12-26 10:13:02 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Mazdak Farrokhzad
93af1e7369
Rollup merge of #56939 - cramertj:pin-stabilization, r=alexcrichton
Pin stabilization

This implements the changes suggested in https://github.com/rust-lang/rust/issues/55766#issue-378417538 and stabilizes the `pin` feature. @alexcrichton also listed several "blockers" in that issue, but then in [this comment](https://github.com/rust-lang/rust/issues/55766#issuecomment-445074980) mentioned that they're more "TODO items":
>  In that vein I think it's fine for a stabilization PR to be posted at any time now with FCP lapsed for a week or so now. The final points about self/pin/pinned can be briefly discussed there (if even necessary, they could be left as the proposal above).

Let's settle these last bits here and get this thing stabilized! :)

r? @alexcrichton
cc @withoutboats
2018-12-23 23:09:04 +01:00
Konrad Borowski
8ac5380ea0
Merge branch 'master' into copied 2018-12-23 16:47:11 +01:00
Pascal Hertleif
2c0f011ca2 Improve docs for collecting into Options
Changes the original example to use more idiomatic formatting as well
as `.checked_add`. Also adds a second example to show a case where the
`.collect` returns `None`.
2018-12-23 15:41:49 +01:00
Taylor Cramer
610bcaf6f3 Stabilize Pin 2018-12-21 20:42:50 -08:00
Taylor Cramer
20d694a95f Update Pin API to match the one proposed for stabilization
Remove pin::Unpin reexport and add Unpin to the prelude.
Change Pin associated functions to methods.
Rename get_mut_unchecked_ to get_unchecked_mut
Remove impl Unpin for Pin
Mark Pin repr(transparent)
2018-12-21 20:41:24 -08:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Konrad Borowski
705383adb0 Add unstable Option::copied() 2018-12-05 15:40:14 +01:00
Clément Renault
c232ea1276 Bump the Option::replace stabilize version to 1.31.0 2018-10-08 10:18:43 +02:00
Clément Renault
8c01c225ce Stabilize the Option::replace method 2018-10-08 10:06:45 +02:00
Scott McMurray
0a3bd9b6ab Use impl_header_lifetime_elision in libcore 2018-09-29 21:33:35 -07:00
bors
1e21c9a297 Auto merge of #53877 - withoutboats:compositional-pin, r=aturon
Update to a new pinning API.

~~Blocked on #53843 because of method resolution problems with new pin type.~~

@r? @cramertj

cc @RalfJung @pythonesque anyone interested in #49150
2018-09-19 06:56:19 +00:00
Taylor Cramer
3ec1810e32 Cleanup and fix method resolution issue 2018-09-17 16:31:33 -07:00
kennytm
b3303edba6
Rollup merge of #53218 - weiznich:feature/option_ref_into, r=KodrAus
Add a implementation of `From` for converting `&'a Option<T>` into `Option<&'a T>`

I'm not sure if any annotations regarding the stabilization are needed or in general what's the correct process of adding such an impl.

cc @sgrif (We have talked about this)
2018-09-14 14:50:09 +08:00
Guillaume Gomez
c1ad1b0338 Fix invalid urls 2018-09-06 23:32:30 +02:00
Without Boats
974bdc80fe
Update to a new pinning API. 2018-09-01 06:57:58 +02:00
Niv Kaminer
13da951868 move PinMut into pin module and export through std 2018-08-23 01:37:03 +03:00
Georg Semmler
a7a0225a28
Also add a From implementation for &mut Option<T> -> `Option<&mut T>' 2018-08-10 14:21:17 +02:00
Georg Semmler
0cde1cbb10
Add stability attribute 2018-08-09 12:48:55 +02:00
M Farkas-Dyck
b78201aee5 inline some short functions 2018-08-09 01:27:48 -08:00
Georg Semmler
ef519c1de5
Add a implementation of From for converting &'a Option<T> into
`Option<&'a T>`
2018-08-09 11:02:08 +02:00
Brad Gibson
56016cb1e0 resolved upstream merge conflicts 2018-07-29 22:13:12 -07:00
kennytm
21f7d2b674
Rollup merge of #52218 - rivertam:patch-1, r=withoutboats
Amend option.take examples

It wasn't abundantly clear to me what `.take` returned. Perhaps this is a slightly frivolous change, but I think it's an improvement. =)

Apologies if I'm not following proper procedures.
2018-07-18 22:34:56 +08:00
Ben Berman
ede1a5d5ed
Amend option.take examples
It wasn't abundantly clear to me what `.take` returned. Perhaps this is a slightly frivolous change, but I think it's an improvement. =)

Apologies if I'm not following proper procedures.
2018-07-10 13:26:44 -04:00
Clément RENAULT
c8f0e6f210
Fix the documentation of Option::replace 2018-07-09 14:52:32 +02:00
Kerollmops
6035534586
Implement Option::replace in the core library 2018-07-04 21:54:45 +02:00
Pietro Albini
b71f6df5dd
Rollup merge of #51730 - MajorBreakfast:pin-get-mut-unchecked, r=withoutboats
New safe associated functions for PinMut

- Add safe `get_mut` and `map`
- Rename unsafe equivalents to `get_mut_unchecked` and `map_unchecked`

The discussion about this starts [in this comment](https://github.com/rust-lang/rust/issues/49150#issuecomment-399604573) on the tracking issue.
2018-06-26 11:35:37 +02:00
Josef Reinhard Brandl
3bcb85ee65 PinMut: Add safe get_mut and rename unsafe fns to get_mut_unchecked and map_unchecked 2018-06-23 18:29:56 +02:00
Martin Glagla
11341e2b06 Replace unreachable! with unreachable_unchecked 2018-06-20 10:08:11 +02:00
Taylor Cramer
15d2f965d8 Add Option::as_pin_mut 2018-05-22 17:24:49 -07:00
Clar Charr
8ab2d15f67 Add Option::xor method 2018-05-15 12:49:31 -04:00
Brad Gibson
c025fdebba fixed some and added more tests 2018-04-30 13:56:52 -07:00
Brad Gibson
6c7ea4ca9b refactored to implement without trait 2018-04-26 20:02:32 -07:00
Brad Gibson
4c2e3144a9 added DerefOption and DerefResult + tests to std 2018-04-26 18:14:23 -07:00
Thayne McCombs
c7ac32a1c1 Remove uses of option_filter feature 2018-04-05 00:02:33 -06:00
Thayne McCombs
5152a6f285 Stabilize Option::filter.
Fixes #45860
2018-04-01 22:11:51 -06:00
Phlosioneer
5057e3c9e1 Commit code for option size hint 2018-03-31 01:13:02 -04:00
Phlosioneer
619003d1d4 Implement some trivial size_hints for various iterators
This also implements ExactSizeIterator where applicable.

Addresses most of the Iterator traits mentioned in #23708.
2018-03-20 05:33:59 -04:00
Matt Brubeck
d04362f23d Stabilize option_ref_mut_cloned
Closes #43738.
2018-03-06 14:40:26 -08:00