Commit Graph

255 Commits

Author SHA1 Message Date
Mikkel Paulson 098b1b98f5 make path separators available in const context
* consolidate various representations of separators in std::sys::path
  into a single macro_rules invocation per platform to save
  transcription errors
* make `std::path::is_separator()` const
* new constants `std::path::{SEPARATORS, SEPARATORS_STR}`
2026-03-04 12:03:06 -05:00
Mikkel Paulson 72de815eb2 reference local MAIN_SEPARATOR_STR
Change reference to imported MAIN_SEP_STR to local MAIN_SEPARATOR_STR,
removing an unnecessary import.
2026-03-04 10:01:43 -05:00
Melvin Wang bde5b584a6 Add Path::absolute method as alias for path::absolute
Add a convenience method Path::absolute() that delegates to the
existing free function std::path::absolute(), mirroring the pattern of
Path::canonicalize() delegating to fs::canonicalize().

Tracking issue: https://github.com/rust-lang/rust/issues/153328
2026-03-03 10:40:19 -08:00
Jonathan Brouwer 9f0a410096 Revert "Stabilize str_as_str" 2026-02-22 10:10:42 +01:00
Matthias Krüger a919df8b1b Rollup merge of #151603 - GrigorenkoPV:stabilize/str_as_str, r=jhpratt
Stabilize `str_as_str`

- Tracking issue: rust-lang/rust#130366
- Needs FCP
- `ByteStr` methods remain gated behind `bstr` feature gate (rust-lang/rust#134915)

Closes rust-lang/rust#130366
2026-02-21 13:03:28 +01:00
Pavel Grigorenko cd314dead1 Remove named lifetimes in some PartialOrd & PartialEq impls 2026-02-14 00:13:46 +03:00
xizheyin 88c296a19f std: introduce path normalize methods at top of std::path 2026-02-09 18:25:26 +08:00
Pavel Grigorenko 06398554bf Stabilize str_as_str 2026-01-24 21:32:31 +03:00
KaiTomotake d697b4d7ab Improve std::path::Path::join documentation
Adapt `PathBuf::push` documentation for `Path::join` and add it to `join`'s docs

Fix to comply with tidy

Remove unnecessary whitespace
2026-01-13 07:48:06 +09:00
Jonathan Brouwer 663d8432f1 Rollup merge of #145933 - GrigorenkoPV:thing_as_thing, r=Amanieu
Expand `str_as_str` to more types

Tracking issue: rust-lang/rust#130366
ACP: https://github.com/rust-lang/libs-team/issues/643

This PR expands `str_from_str` feature and adds analogous methods to more types. Namely:
- `&CStr`
- `&[T]`, `&mut [T]`
- `&OsStr`
- `&Path`
- `&ByteStr`, `&mut ByteStr` (tracking issue:  rust-lang/rust#134915) (technically was not part of ACP)
2025-12-18 18:37:13 +01:00
Zachary S 316d54a5bd Implement some conversions using Box::clone_from_ref 2025-11-19 13:34:03 -06:00
Pavel Grigorenko a197ebdb07 {CStr,OsStr,Path}::as_$1 2025-11-11 23:08:15 +03:00
Stuart Cook 1ad9e955a8 Rollup merge of #148084 - the8472:prefixless-path-components-iter, r=Mark-Simulacrum
Optimize path components iteration on platforms that don't have prefixes

```
OLD

path::bench_path_components_iter 140.20ns/iter +/- 6.08
path::bench_path_file_name 57.62ns/iter +/- 1.62

NEW

path::bench_path_components_iter 126.74ns/iter +/- 1.46
path::bench_path_file_name 47.48ns/iter +/- 2.49
```
2025-11-09 13:22:26 +11:00
Chris Denton 7e66d6c3b9 Implement Path::is_empty 2025-11-04 19:23:51 +00:00
The 8472 d263ab36de replace u8 iterator with slice matching 2025-10-25 14:46:59 +02:00
The 8472 ea3a4e714e skip some Path prefix-component logic on platforms that don't have prefixes 2025-10-25 14:46:59 +02:00
Matthias Krüger 61b9467af8 Rollup merge of #142506 - clarfonthey:path-trailing-sep, r=joboet
Add `Path::has_trailing_sep` and related methods

Implements rust-lang/libs-team#335.

Tracking issue: rust-lang/rust#142503

Notable differences from ACP:

* `trim_trailing_sep` was added to `Path` since it felt reasonable to ensure that the inverse operation was available.
* Per suggestion of `@kennytm,` added `push_trailing_sep` and `pop_trailing_sep` to `PathBuf` in addition to `set_trailing_sep`.

This also updates some of the docs on various `Path` methods to use the term "trailing separator" instead of "trailing slash" for consistency.
2025-09-30 20:46:44 +02:00
Mark Rousskov 4e9716fbc5 Update CURRENT_RUSTC_VERSION post-bump 2025-09-26 18:41:32 -04:00
Iris Shi 5a4e536036 Fix infinite recursion in Path::eq with String 2025-09-24 21:30:41 +08:00
Soroush Mirzaei 4b5d0e02ca docs(std): add error docs for path canonicalize 2025-09-07 11:17:59 -04:00
ltdk 7ce8e289db Add Path::has_trailing_sep and related methods 2025-09-04 20:07:10 -04:00
bendn 1e37c1fe2e fix 2025-09-04 18:33:47 +07:00
Stuart Cook 98f6887f35 Rollup merge of #145209 - hanna-kruppe:path_add_extension, r=tgross35
Stabilize `path_add_extension`

FCP in tracking issue rust-lang/rust#127292 finished in January. There was more discussion since then, but [libs-api decided to match `set_extension`][0] by keeping the return type as-is and adding a panic for invalid extensions. The latter was implemented in rust-lang/rust#140163, so this feature should be ready for stabilization. But if anyone's unsure, another FCP could be done to confirm.

Closes rust-lang/rust#127292

[0]: https://github.com/rust-lang/rust/issues/127292#issuecomment-2605197960
2025-09-04 10:01:52 +10:00
ltdk 1c64d3e6d1 Constify conversion traits 2025-09-01 21:38:26 -04:00
Marijn Schouten 845311a065 remove deprecated Error::description in impls 2025-08-26 06:36:53 +00:00
许杰友 Jieyou Xu (Joe) 9a5c00a673 Rollup merge of #145464 - Kivooeo:stabilize-const_pathbuf_osstring_new, r=ibraheemdev
Stabilize `const_pathbuf_osstring_new` feature

This closes [tracking issue](https://github.com/rust-lang/rust/issues/141520) and stabilises `{OsString, PathBuf}::new` in const
2025-08-19 19:45:32 +08:00
Stuart Cook 2beb54c451 Rollup merge of #140956 - Kixunil:impl-partialeq-str-for-path, r=Amanieu
`impl PartialEq<{str,String}> for {Path,PathBuf}`

This is a revival of #105877

Comparison of paths and strings is expected to be possible and needed e.g. in tests. This change adds the impls os `PartialEq` between strings and paths, both owned and unsized, in both directions.

ACP: https://github.com/rust-lang/libs-team/issues/151
2025-08-19 14:18:14 +10:00
Kivooeo b79ab4461d stabilize const pathbuf osstring new 2025-08-15 16:36:06 +00:00
Hanna Kruppe 52063ae248 stabilize path_add_extension 2025-08-13 19:03:13 +02:00
Jakub Beránek ff44871be5 Rollup merge of #144870 - Kivooeo:file_prefix-stabilize, r=tgross35
Stabilize `path_file_prefix` feature

This stabilises `Path::file_prefix`, following the FCP in [tracking issue ](https://github.com/rust-lang/rust/issues/86319)

(FCP ended almost a year ago, so if it's needed for proccess we could rerun it)

Closes: https://github.com/rust-lang/rust/issues/86319
2025-08-13 07:03:47 +02:00
The 8472 d8e8a5e8b4 add code example showing that file_prefix treats dotfiles as the name of a file, not an extension 2025-08-05 22:56:43 +02:00
Kivooeo 4c4b8b23c6 remove gate 2025-08-04 02:18:18 +05:00
Josh Triplett 1e2d58798f Avoid making the start of a doc code block conditional
Placing the opening triple-backquote inside a `cfg_attr` makes many
tools confused, including syntax highlighters (e.g. vim's) and rustfmt.

Instead, use a `cfg` inside the doc code block.
2025-07-25 22:02:09 -07:00
xizheyin 2765bd48f0 std: fix typo in std::path
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-07 15:20:22 +08:00
Matthias Krüger 0d5af18c14 Rollup merge of #141847 - xizheyin:141837, r=jhpratt
Explain `TOCTOU` on the top of `std::fs`, and reference it in functions

Fixes rust-lang/rust#141837

r? ``````@workingjubilee``````
2025-07-02 19:28:03 +02:00
Josh Stone 9ce8930da6 Update version placeholders 2025-07-01 10:54:33 -07:00
bors 8de4c7234d Auto merge of #141864 - Berrysoft:cygwin-path, r=ChrisDenton
Handle win32 separator for cygwin paths

This PR handles a issue that cygwin actually supports Win32 path, so we need to handle the Win32 prefix and separaters.

r? `@mati865`

cc `@jeremyd2019`

~~Not sure if I should handle the prefix like the windows target... Cygwin *does* support win32 paths directly going through the APIs, but I think it's not the recommended way.~~

Here I just use `cygwin_conv_path` because it handles both cygwin and win32 paths correctly and convert them into absolute POSIX paths.

UPDATE: Windows path prefix is handled.
2025-06-19 13:38:37 +00:00
Yotam Ofek 45bbb3dfbf Add documentation for PathBuf's FromIterator and Extend impls 2025-06-16 07:49:27 +00:00
王宇逸 3cb0cba054 Handle win32 separator & prefixes for cygwin paths 2025-06-16 09:24:07 +08:00
schvv31n eba3a61067 Stabilised os_string_pathbuf_leak 2025-06-06 12:06:42 -07:00
Matthias Krüger 88620b400e Rollup merge of #141467 - cyrgani:const-empty-stringlikes, r=Amanieu
make `OsString::new` and `PathBuf::new` unstably const

Since #129041, `String::into_bytes` is `const`, which allows making `OsString::new` and `PathBuf::new` unstably const now.
Not sure what the exact process for this is; does it need an ACP?
2025-06-04 07:54:33 +02:00
xizheyin e95751a9ff Explain TOCTOU on the top of std::fs, and ref it in functions
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-02 17:45:00 +08:00
Jacob Pratt ffdd3b16dc Rollup merge of #141477 - tshepang:patch-1, r=ChrisDenton
Path::with_extension: show that it adds an extension where one did no…

…t exist

I think the times I encountered this, I had to check first if files without extensions were added, since all examples only had files with existing extensions.

Also, this replaced example already has a similar example below.
2025-05-29 04:49:41 +02:00
Chris Denton c299e297ee Implement normalize lexically 2025-05-25 08:11:41 +00:00
cyrgani fab206bf58 make OsString::new and PathBuf::new unstably const 2025-05-24 22:33:11 +02:00
Tshepang Mbambo 248f4b2ad2 reduce clutter... too many imports 2025-05-24 22:17:55 +02:00
Tshepang Mbambo a3bd12b88a Path::with_extension: improve examples 2025-05-24 22:12:15 +02:00
Michael Goulet 7b5ea0e7f5 use Self alias in self types rather than manually substituting it 2025-05-20 16:03:04 +02:00
Martin Habovstiak aab1563d42 impl PartialEq<{str,String}> for {Path,PathBuf}
Comparison of paths and strings is expected to be possible and needed
e.g. in tests. This change adds the impls os `PartialEq` between strings
and paths, both owned and unsized, in both directions.

ACP: https://github.com/rust-lang/libs-team/issues/151
2025-05-13 23:41:18 +02:00
Stuart Cook 5a58c7a6ab Rollup merge of #140159 - thaliaarchi:pathbuf-extension, r=workingjubilee
Avoid redundant WTF-8 checks in `PathBuf`

Eliminate checks for WTF-8 boundaries in `PathBuf::set_extension` and `add_extension`, where joining WTF-8 surrogate halves is impossible. Don't convert the `str` to `OsStr`, because `OsString::push` specializes to skip the joining when given strings.

To assist in this, mark the internal methods `OsString::truncate` and `extend_from_slice` as `unsafe` to communicate their safety invariants better than with module privacy.

Similar to #137777.

cc `@joboet` `@ChrisDenton`
2025-05-02 22:17:00 +10:00