Commit Graph

185 Commits

Author SHA1 Message Date
Marijn Schouten fdc80af5c5 fix OsString::from_encoded_bytes_unchecked description 2025-01-21 14:36:18 +01:00
ltdk e37daf0c86 Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
crystalstall 591bf63439 chore: remove redundant words in comment
Signed-off-by: crystalstall <crystalruby@qq.com>
2025-01-06 15:47:49 +08:00
Michael Howell 40b0026a2f docs: inline std::ffi::c_str types to std::ffi
Rustdoc has no way to show that an item is stable,
but only at a different path. `std::ffi::c_str::NulError` is
not stable, but `std::ffi::NulError` is.

To avoid marking these types as unstable when someone just
wants to follow a link from `CString`, inline them into their
stable paths.
2024-12-26 08:58:17 -07:00
Boxy 174ad448c7 replace placeholder version 2024-11-27 12:10:21 +00:00
binarycat 7e79f91390 implement OsString::truncate 2024-11-20 15:16:05 -06:00
Zachary S e0c1c8bc50 Make CloneToUninit dyn-compatible 2024-11-12 15:08:41 -06:00
Eduardo Sánchez Muñoz 9fe9041cc8 Implement From<&mut {slice}> for Box/Rc/Arc<{slice}> 2024-10-29 21:24:12 +01:00
Josh Stone f4d9d1a0ea Use &raw in the standard library
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can
start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!`
and `ptr::addr_of_mut!` can stop allowing the unstable feature.

I intentionally did not change any documentation or tests, but the rest
of those macro uses are all now using `&raw const` or `&raw mut` in the
standard library.
2024-09-25 17:03:20 -07:00
Michael Goulet c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
GnomedDev afe7907914 [Clippy] Swap redundant_clone to use diagnostic items instead of paths 2024-09-19 13:13:20 +01:00
GnomedDev 5e4716888a [Clippy] Swap option_as_ref_deref to use diagnostic items instead of paths 2024-09-19 13:13:19 +01:00
Ryosuke Takahashi 49a93df77d fix: correct {Path,OsStr}::to_string_lossy() docs 2024-09-05 00:48:00 +09:00
Pavel Grigorenko dbc13fb309 Sparkle some attributes over CloneToUninit stuff 2024-07-29 20:44:42 +03:00
Pavel Grigorenko afabc583f7 impl CloneToUninit for Path and OsStr 2024-07-29 20:44:39 +03:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Pavel Grigorenko b74f426e07 Fix some #[cfg_attr(not(doc), repr(..))]
Now that #90435 seems to have been resolved.
2024-07-22 01:10:06 +03:00
Jubilee Young ce35265105 std: Unsafe-wrap OSStr{,ing}::from_encoded_bytes_unchecked 2024-07-14 16:59:12 -07:00
Jubilee Young 4572ed6389 std: deny(unsafe_op_in_unsafe_fn) but allow sites
This provides a list of locations to hunt down issues in.
2024-07-14 16:44:01 -07:00
ash aa46a3368e PathBuf::as_mut_vec removed and verified for UEFI and Windows platforms #126333 2024-06-25 07:36:34 -06:00
ash b08cd69684 inner truncate methods for UEFI platforms 2024-06-25 07:36:34 -06:00
schvv31n 2bdc53b153 fixed memory leaks in PathBuf::leak & OsString::leak tests 2024-06-06 23:18:01 +01:00
schvv31n fd5777c4c5 impl OsString::leak & PathBuf::leak 2024-06-04 11:53:59 +01:00
Ralf Jung c47978a241 PathBuf: replace transmuting by accessor functions 2024-04-26 18:09:09 +02:00
Matthias Krüger 21deaed4a1 Rollup merge of #122201 - coolreader18:doc-clone_from, r=dtolnay
Document overrides of `clone_from()` in core/std

As mentioned in https://github.com/rust-lang/rust/pull/96979#discussion_r1379502413

Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".

I reused some of the wording over and over for similar impls, but I'm not sure that the wording is actually *good*. Would appreciate feedback about that.

Also, now some of these seem to provide pretty specific guarantees about behavior (e.g. will reuse the exact same allocation iff the len is the same), but I was basing it off of the docs for [`Box::clone_from`](https://doc.rust-lang.org/1.75.0/std/boxed/struct.Box.html#method.clone_from-1) - I'm not sure if providing those strong guarantees is actually good or not.
2024-04-17 18:01:37 +02:00
Matthias Krüger 1b44889ec2 Rollup merge of #112136 - clarfonthey:ffi-c_str, r=cuviper
Add std::ffi::c_str module

ACP: rust-lang/libs-team#134

`std::ffi` docs before change:
![Structs: VaList, VaListImpl, CStr, CString, FromBytesWithNulError, FromVecWithNulError, IntoStringError, NulError, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/b2cf3534-30f9-4ef0-a655-bacdc3a19e17)

`std::ffi` docs after change:
![Re-exports: self::c_str::{FromBytesWithNulError, FromBytesUntilNulError, FromVecWithNulError, NulError, IntoStringError} ; Modules: c_str ; Structs: VaList, VaListImpl, CStr, CString, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/23aa6964-da7a-4942-bbf7-42bde2146f9e)

(note: I'm omitting the `c_int`, etc. stuff from the screenshots since it's the same in both. this doesn't just delete those types)
2024-03-10 10:58:14 +01:00
Noa c0e913fdd7 Document overrides of clone_from()
Specifically, when an override doesn't just forward to an inner type,
document the behavior and that it's preferred over simply assigning
a clone of source. Also, change instances where the second parameter is
"other" to "source".
2024-03-08 12:27:24 -06:00
Ralf Jung 1a2bc1102d Rust is a proper name: rust → Rust 2024-03-07 07:49:22 +01:00
Guillaume Gomez d8404084c0 Rollup merge of #120051 - riverbl:os-str-display, r=m-ou-se
Add `display` method to `OsStr`

Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public (see https://github.com/rust-lang/libs-team/issues/326#issuecomment-1894160023).

- ACP: https://github.com/rust-lang/libs-team/issues/326
- Tracking issue: #120048
2024-02-28 16:04:49 +01:00
Esteban Küber e5b3c7ef14 Add rustc_confusables annotations to some stdlib APIs
Help with common API confusion, like asking for `push` when the data structure really has `append`.

```
error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope
  --> $DIR/rustc_confusables_std_cases.rs:17:7
   |
LL |     x.size();
   |       ^^^^
   |
help: you might have meant to use `len`
   |
LL |     x.len();
   |       ~~~
help: there is a method with a similar name
   |
LL |     x.resize();
   |       ~~~~~~
```

#59450
2024-02-22 18:04:55 +00:00
ltdk 1ea6cd715e Add std::ffi::c_str modules 2024-02-22 02:09:26 -05:00
Jan Verbeek 51a7396ad3 Move OsStr::slice_encoded_bytes validation to platform modules
On Windows and UEFI this improves performance and error messaging.

On other platforms we optimize the fast path a bit more.

This also prepares for later relaxing the checks on certain platforms.
2024-01-21 19:51:49 +01:00
riverbl a0fcc8ebc0 Add display method to OsStr
Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode.

Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`.

This change also makes the `std::ffi::os_str` module public.
2024-01-18 20:38:31 +00:00
surechen 40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Jan Verbeek 729851ef9e Add substring API for OsStr 2023-12-02 15:22:29 +01:00
Mark Rousskov 787d32324c Bump version placeholders 2023-10-03 20:26:36 -04:00
Ed Page 30292bb68e fix(std): Rename os_str_bytes to encoded_bytes 2023-09-01 19:33:16 -05:00
Ed Page 9aee1de612 feat(std): Stabilize 'os_str_bytes' feature
Closes #111544
2023-09-01 11:13:45 -05:00
Mark Rousskov c8522adb97 Replace version placeholders with 1.73.0 2023-08-22 06:57:00 -04:00
Ralf Jung fe1a034f16 actually this doesn't even affect doctests. nice. 2023-08-14 22:55:29 +02:00
Ralf Jung f887f5a9c6 std: add some missing repr(transparent) 2023-08-14 10:40:59 +02:00
Matthias Krüger efd68db768 Rollup merge of #113701 - aswild:std-ffi-frombytesuntilnul, r=dtolnay
Re-export core::ffi::FromBytesUntilNulError in std::ffi

Like the other CStr and CString error types, make a re-export for std::ffi::FromBytesUntilNulError.

This seems to have slipped through the cracks in the cstr_from_bytes_until_nul implementation and core_c_str migration.

Tracking Issue: #95027
2023-07-31 22:51:13 +02:00
Matthias Krüger 0877d11e8d Rollup merge of #113442 - epage:osstring, r=cuviper
Allow limited access to `OsString` bytes

This extends #109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in #111544.
2023-07-22 11:48:53 +02:00
Allen Wild fda3d2abaa Re-export core::ffi::FromBytesUntilNulError in std::ffi
Like the other CStr and CString error types, make a re-export for
std::ffi::FromBytesUntilNulError.

This seems to have slipped through the cracks in the
cstr_from_bytes_until_nul implementation and core_c_str migration.

Tracking Issue: #95027
2023-07-14 11:08:57 -04:00
Mark Rousskov 0d93d787ba Replace version placeholder to 1.72 2023-07-12 21:24:05 -04:00
Ed Page ee604fccd9 Allow limited access to OsString bytes
This extends #109698 to allow no-cost conversion between `Vec<u8>` and `OsString`
as suggested in feedback from `os_str_bytes` crate in #111544.
2023-07-07 09:46:48 -05:00
Matthias Krüger 4efdb5c001 Rollup merge of #98202 - aticu:impl_tryfrom_osstr_for_str, r=Amanieu
Implement `TryFrom<&OsStr>` for `&str`

Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing.

Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`.

As this is a trait implementation, it is insta-stable, if I'm not mistaken?
Either way this will need an FCP.
I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off.

`@rustbot` modify labels: +T-libs-api

API Change Proposal: rust-lang/rust#99031 (accepted)
2023-06-14 18:10:27 +02:00
aticu e3a1a11ed2 Implement TryFrom<&OsStr> for &str 2023-06-12 10:46:49 +02:00
Ed Page e6a35c4953 docs: Add missing period 2023-05-19 19:41:41 -05:00
Ed Page 5d177afe95 docs: Clarify OsStr is self-synchronizing 2023-05-17 09:34:25 -05:00