Commit Graph

330 Commits

Author SHA1 Message Date
Lzu Tao
eca1e8bd9b Inline PathBuf::deref to make it zero cost 2020-01-10 18:48:15 +00:00
Igor Aleksanov
f720469fd0 Use matches macro in libcore and libstd 2020-01-08 07:10:28 +03:00
Oliver Scherer
9525e8e6b2
Rollup merge of #67635 - Mark-Simulacrum:path-doc-unsafe, r=dtolnay
Document safety of Path casting

I would personally feel more comfortable making the relevant (internal anyway) types repr(transparent) and then documenting that we can make these casts because of that, but I believe this is a more minimal PR, so posting it first.

Resolves #45910.
2019-12-28 00:36:14 +01:00
Mark Rousskov
9c0f3f7f2a Document safety of Path casting 2019-12-26 12:12:42 -05:00
Matthew Kraai
21e636f188 Remove redundant link texts 2019-12-26 05:04:46 -08:00
David Tolnay
4646a88b7a
Deprecate Error::description for real
`description` has been documented as soft-deprecated since 1.27.0 (17
months ago). There is no longer any reason to call it or implement it.

This commit:

- adds #[rustc_deprecated(since = "1.41.0")] to Error::description;

- moves description (and cause, which is also deprecated) below the
  source and backtrace methods in the Error trait;

- reduces documentation of description and cause to take up much less
  vertical real estate in rustdocs, while preserving the example that
  shows how to render errors without needing to call description;

- removes the description function of all *currently unstable* Error
  impls in the standard library;

- marks #[allow(deprecated)] the description function of all *stable*
  Error impls in the standard library;

- replaces miscellaneous uses of description in example code and the
  compiler.
2019-12-24 22:39:49 -08:00
David Tolnay
4436c9d354
Format libstd with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd *that are not involved in any currently open PR* to
minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in outstanding_files, the
relevant commands were:

    $ find src/libstd -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of libstd.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
2019-11-29 18:43:27 -08:00
Mara Bos
18ae175d60 Prevent unnecessary allocation in PathBuf::set_extension.
It was allocating a new OsString that was immediately dropped after
using it with set_file_name. Now it directly changes the extension in
the original buffer, without touching the rest of the file name or
allocating a temporary string.
2019-10-23 21:21:25 +02:00
Tyler Mandry
48051e4a79
Rollup merge of #65266 - rust-lang:must-use-join, r=dtolnay
Mark Path::join as must_use

I've accidentally did `mut_path_buf.jon(a_path);`, expecting this to be an in-place modification. Seems like we can easily warn in such cases?
2019-10-11 15:09:53 -07:00
Aleksey Kladov
19bc0a8c67
Mark Path::join as must_use
I've accidentally did `mut_path_buf.jon(a_path);`, expecting this to be an in-place modification. Seems like we can easily warn in such cases?
2019-10-10 12:42:04 +03:00
Hsiang-Cheng Yang
897d278160 libstd: Fix typos in doc 2019-09-20 17:38:00 +08:00
Mark Rousskov
88629778e6
Rollup merge of #61969 - MikailBag:master, r=Centril
Add #[repr(transparent)] for several types

In some functions, types mentioned in this PR are transmuted into their inner value.
Example for `PathBuf`: https://github.com/rust-lang/rust/blob/master/src/libstd/path.rs#L1132.
This PR adds `#[repr(transparent)]` to those types, so their correct behavior doesn't depend on compiler details. (As far as I understand, currently that line, converting `PathBuf` to `Vec<u8>`, is UB).
2019-08-11 15:18:38 -04:00
Mikail Bagishov
740f8db855
Add FIXME-s that some types should be transparent 2019-08-09 17:41:40 +03:00
Jeremy Soller
0498da9a3d
redox: convert to target_family unix 2019-08-06 16:18:23 -06:00
Jason Shin
1aa4a57827
Update src/libstd/path.rs to shorten the explanation for .to_str validation step
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-08-01 13:55:01 +10:00
Jason Shin
3b15b1664e Explaining the reason why validation is performed in to_str of path.rs 2019-08-01 12:42:52 +10:00
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
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
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
Josh Stone
0730a01c5c Use for_each to extend collections
This updates the `Extend` implementations to use `for_each` for many
collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`,
`TokenStream`, `VecDeque`, and `Wtf8Buf`.

Folding with `for_each` enables better performance than a `for`-loop for
some iterators, especially if they can just forward to internal
iterators, like `Chain` and `FlatMap` do.
2019-04-05 14:51:07 -07:00
Mazdak Farrokhzad
379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Jethro Beekman
f229422cc1 SGX target: fix std unit tests 2019-03-25 11:31:19 -07:00
Scott McMurray
df4ea90b39 Use lifetime contravariance to elide more lifetimes in core+alloc+std 2019-03-09 19:10:28 -08:00
Taiki Endo
93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
bors
00aae71f50 Auto merge of #58302 - SimonSapin:tryfrom, r=alexcrichton
Stabilize TryFrom and TryInto with a convert::Infallible empty enum

This is the plan proposed in https://github.com/rust-lang/rust/issues/33417#issuecomment-423073898
2019-02-25 20:24:10 +00: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
Aaron Stillwell
c9fbcc1f39 Fixed doc example for Path::with_capacity 2019-02-18 17:42:07 +00: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
Aaron Stillwell
35d8c4400d Changed feature gate for new PathBuf methods
Feature gate changed to `path_buf_capacity` as per advice from @Mark-Simulacrum
2019-02-17 17:14:10 +00:00
Aaron Stillwell
dbf60d9ca1 Fixes for implementation of PathBuf methods (aliases for OsString)
- Fixed incorrect `mut` usage
- Fixed style in accordance with tidy
- Marked all methods as unstable
- Changed feature identifier to path_buf_alias_os_string_methods
2019-02-17 16:41:05 +00:00
Aaron Stillwell
a23c40ec94 Add alias methods to PathBuf for underlying OsString
Implemented the following methods on PathBuf which
forward to the underlying OsString.

- capacity
- with_capacity
- clear
- reserve
- reserve_exact
- shrink_to_fit
- shrink_to
2019-02-17 15:17:46 +00:00
Nathan
4ad8770b26 Fix documentation for std::path::PathBuf::pop
Closes #58474.
2019-02-15 12:20:46 -05:00
Simon Sapin
85f13f0d42 Add a convert::Infallible empty enum, make string::ParseError an alias 2019-02-13 18:00:18 +01:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad
e598ea83c8
Update src/libstd/path.rs
Co-Authored-By: steveklabnik <steve@steveklabnik.com>
2019-01-10 17:08:42 -05:00
Steve Klabnik
f282f6b1f7 make note of one more normalization that Paths do
Fixes #29008
2019-01-10 15:30:36 -05:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Otavio Salvador
8c40aedb8f Fix feature gate to point to 1.32.0 for path_from_str
When the feature has been added back (#55148) the feature gate has not
been adjusted accordingly. We have it enabled for 1.32.0, currently in
Beta, so adjust it.

Refs: #44431.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2018-12-21 11:33:59 -02:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Bastian Gruber
450a8a6f35 Add extra comment slash 2018-12-04 10:10:07 +01:00
Bastian Gruber
7933628de5 Remove trailing whitespace 2018-11-21 13:57:56 +01:00
Bastian Gruber
e8dafbaf10 Adjust doc comments 2018-11-21 13:06:22 +01:00
Bastian Gruber
5c747eb326 Update style of comments 2018-11-21 09:59:01 +01:00
Bastian Gruber
88a708dd6a Update comments 2018-11-21 09:59:01 +01:00
Bastian Gruber
072bca3ff5 Remove 'unsafe' comments 2018-11-21 09:59:01 +01:00
Bastian Gruber
700c83bc05 Document From implementations 2018-11-21 09:59:01 +01:00
Simon Sapin
a0df4204c4 Implement FromStr for PathBuf
Initially landed in https://github.com/rust-lang/rust/pull/48292
and reverted in https://github.com/rust-lang/rust/pull/50401.
This time, use `std::string::ParseError` as suggested in
https://github.com/rust-lang/rust/issues/44431#issuecomment-428112632
2018-10-17 15:54:00 +02:00
Corey Farwell
ec18991492 Add links to std::char::REPLACEMENT_CHARACTER from docs.
There are a few places where we mention the replacement character in the
docs, and it could be helpful for users to utilize the constant which is
available in the standard library, so let’s link to it!
2018-08-11 15:42:35 -04:00
Colin Wallace
4f3ab4986e libstd: Prefer Option::map/etc over match where applicable 2018-07-23 22:00:51 -07:00