Commit Graph

467 Commits

Author SHA1 Message Date
Steven Fackler
8a22bc3b30 Revert "Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators."
This reverts commit 3e86cf36b5.
2019-05-22 14:09:34 -07:00
Mazdak Farrokhzad
088c99410b Rollup merge of #60443 - RalfJung:as_ptr, r=SimonSapin
as_ptr returns a read-only pointer

Add comments to `as_ptr` methods to warn that these are read-only pointers, and writing to them is UB.

[It was pointed out](https://internals.rust-lang.org/t/as-ptr-vs-as-mut-ptr/9940) that `CStr` does not even have an `as_mut_ptr`. I originally was going to add one, but there is no method at all that would mutate a `CStr`. Was that a deliberate choice or should I add an `as_mut_ptr` (similar to [what I did for `str`](https://github.com/rust-lang/rust/pull/58200))?
2019-05-14 22:00:11 +02:00
Mazdak Farrokhzad
bab03cecfe Rollup merge of #60130 - khuey:efficient_last, r=sfackler
Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators

Provided a `DoubleEndedIterator` has finite length, `Iterator::last` is equivalent to `DoubleEndedIterator::next_back`. But searching forwards through the iterator when it's unnecessary is obviously not good for performance. I ran into this on one of the collection iterators.

I tried adding appropriate overloads for a bunch of the iterator adapters like filter, map, etc, but I ran into a lot of type inference failures after doing so.

The other interesting case is what to do with `Repeat`. Do we consider it part of the contract that `Iterator::last` will loop forever on it? The docs do say that the iterator will be evaluated until it returns None. This is also relevant for the adapters, it's trivially easy to observe whether a `Map` adapter invoked its closure a zillion times or just once for the last element.
2019-05-14 22:00:09 +02:00
Ralf Jung
30cf0e4251 clarify wording 2019-05-02 13:36:30 +02:00
Ralf Jung
1e47250540 as_ptr returns a read-only pointer 2019-05-01 17:59:48 +02:00
Mazdak Farrokhzad
c9b70144a3 Rollup merge of #60356 - JohnTitor:stabilize-as-mut-ptr, r=Centril
Stabilize str::as_mut_ptr

Closes #58215
2019-04-29 22:22:42 +02:00
Mazdak Farrokhzad
eb3c53071a Rollup merge of #59946 - mernen:patch-2, r=ehuss
Fix equivalent string in escape_default docs

This newline should be escaped.
2019-04-29 22:22:34 +02:00
Yuki OKUSHI
4c0f01cc27 Stabilize str::as_mut_ptr 2019-04-29 02:33:50 +09:00
varkor
aa388f1d11 ignore-tidy-filelength on all files with greater than 3000 lines 2019-04-25 21:39:09 +01:00
Kyle Huey
3e86cf36b5 Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators.
r?Manishearth
2019-04-19 21:52:43 -07:00
Mazdak Farrokhzad
3ad9fcccbb Rollup merge of #60098 - Centril:libcore-deny-more, r=varkor
libcore: deny `elided_lifetimes_in_paths`

r? @varkor
2019-04-19 06:03:30 +02:00
Mazdak Farrokhzad
291e44b381 Rollup merge of #60023 - koalatux:nth-back, r=scottmcm
implement specialized nth_back() for Bytes, Fuse and Enumerate

Hi,

After my first PR has been successfully merged, here is my second pull request :-)

Also this PR contains some specializations for the problem discussed in #54054.
2019-04-19 06:03:12 +02:00
Mazdak Farrokhzad
dbfbadeac4 libcore: deny more... 2019-04-19 01:37:12 +02:00
Taiki Endo
360432f1e8 libcore => 2018 2019-04-18 14:47:35 +09:00
Adrian Friedli
cc2689a253 implement nth_back for Bytes 2019-04-16 20:41:23 +02:00
Daniel Luz
e2613f521a Fix equivalent string in escape_default 2019-04-13 16:44:21 -03:00
Scott Olson
b27bcc0a17 Fix paste error in split_ascii_whitespace docs. 2019-04-12 13:57:45 -06:00
Andy Russell
b34a71b7da add suggestions to trim_{left,right} deprecations 2019-03-22 14:56:08 -04:00
Alexander Regueiro
8629fd3e4e Improvements to comments in libstd, libcore, liballoc. 2019-03-11 02:25:44 +00:00
Trevor Spiteri
b70a9532a9 Replace s with self in docs for str methods taking self. 2019-02-27 17:07:35 +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
Mazdak Farrokhzad
ecb6503169 Rollup merge of #58200 - RalfJung:str-as-mut-ptr, r=SimonSapin
fix str mutating through a ptr derived from &self

Found by Miri: In `get_unchecked_mut` (also used by the checked variants internally) uses `str::as_ptr` to create a mutable reference, but `as_ptr` takes `&self`.  This means the mutable references we return here got created from a shared reference, which violates the shared-references-are-read-only discipline!

For this by using a newly introduced `as_mut_ptr` instead.
2019-02-13 04:37:03 +01:00
bors
0f949c2fcc Auto merge of #58051 - SimonSapin:str_escape, r=alexcrichton
Stabilize str::escape_* methods with new return types…

… that implement `Display` and `Iterator<Item=char>`, as proposed in FCP: https://github.com/rust-lang/rust/issues/27791#issuecomment-376864727
2019-02-12 23:30:16 +00:00
Simon Sapin
eb158f9350 Add doctests for str::escape_* 2019-02-12 09:55:30 +01:00
Simon Sapin
92cce78d06 Move str::escape_* to libcore 2019-02-12 09:55:30 +01:00
Simon Sapin
92dcae4742 Add internal impl_fn_for_zst macro for "named closure types" 2019-02-12 09:55:20 +01:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Alexander Regueiro
b87363e763 tests: doc comments 2019-02-10 23:42:32 +00:00
Alexander Regueiro
c3e182cf43 rustc: doc comments 2019-02-10 23:42:32 +00:00
Ralf Jung
66c894e07f also fix bad use of shared ref in split_at_mut 2019-02-07 17:55:42 +01:00
Ralf Jung
a996f2c8dc add tracking issue 2019-02-06 12:55:50 +01:00
Ralf Jung
13bbba273c remove now-unneeded raw ptr casts 2019-02-06 11:23:10 +01:00
Ralf Jung
346dc37aee fix str mutating through a ptr derived from &self 2019-02-05 20:07:45 +01:00
garyemerson
75b19579fb update split docs
Some confusion about split popped up at https://news.ycombinator.com/item?id=19080931 since the docs sorta sound like `&str`, `char` and closures are the only types that can be patterns.

cc @steveklabnik
2019-02-04 15:26:33 -08:00
Simon Sapin
6a01f8aecd Stabilize split_ascii_whitespace
Tracking issue FCP to merge: https://github.com/rust-lang/rust/issues/48656#issuecomment-442372750
2019-02-01 11:24:12 +01:00
Mazdak Farrokhzad
c76456c253 Rollup merge of #58005 - vitiral:docs_trim_start_matches, r=Manishearth
update docs for fix_start/end_matches

fixes #57686:
2019-01-31 02:10:51 +01:00
Mazdak Farrokhzad
7ebb0a8c8e Rollup merge of #57106 - matthiaskrgr:trim_must_use, r=sfackler
Mark str::trim.* functions as #[must_use].

The functions return a reference to a new object and do not modify in-place
as the following code shows:
````
let s = String::from("   hello   ");
s.trim();
assert_eq!(s, "   hello   ");
````

The new reference should be bound to a variable as now indicated by #[must_use].
2019-01-31 02:10:41 +01:00
Rett Berg
4a3caca978 fix #57686: update docs for fix_start/end_matches 2019-01-30 10:12:49 -08:00
Clar Fon
520e8b001e Move TrustedRandomAccess into Zip module 2019-01-22 17:45:11 -05:00
Alexis Hunt
c7d25a2a40 Make str indexing generic on SliceIndex. 2019-01-19 04:16:05 -05:00
Steve Klabnik
beb6495862 note that FromStr does not work for borrowed types
Fixes #47757
2019-01-10 17:08:27 -05:00
Matthias Krüger
74e9057905 modify remaining #[must_use[ messages 2018-12-26 22:03:04 +01:00
Zack M. Davis
e7ce868f8e Update src/libcore/str/mod.rs, tweak must_use message
trimmed string is returned as a slice instead of a new allocation

Co-Authored-By: matthiaskrgr <matthias.krueger@famsik.de>
2018-12-26 20:01:52 +01:00
Matthias Krüger
809a1a86e0 mark str::string::String.trim.* functions as #[must_use].
The functions return a reference to a new object and do not modify in-place
as the following code shows:
````
let s = String::from("   hello   ");
s.trim();
assert_eq!(s, "   hello   ");
````

The new reference should be bound to a variable as now indicated by #[must_use].
2018-12-26 20:01:52 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Pietro Albini
64371f1cfe Rollup merge of #56119 - frewsxcv:frewsxcv-option-carrier, r=TimNN
Utilize `?` instead of `return None`.

None
2018-12-05 23:54:25 +01:00
Corey Farwell
9012af6f19 Utilize ? instead of return None. 2018-12-04 08:57:34 -08:00
Adrian Heine né Lang
37f719e0d3 std::str Adapt documentation to reality 2018-11-22 15:26:16 +01:00