about summary refs log tree commit diff
path: root/library/std/src/ffi
AgeCommit message (Collapse)AuthorLines
2025-09-26Update CURRENT_RUSTC_VERSION post-bumpMark Rousskov-1/+1
2025-09-01Constify conversion traitsltdk-4/+8
2025-08-15stabilize const pathbuf osstring newKivooeo-1/+1
2025-07-01Update version placeholdersJosh Stone-1/+1
2025-06-07Rollup merge of #137992 - its-the-shrimp:stabilise_os_string_pathbuf_leak, ↵Jacob Pratt-1/+1
r=dtolnay Stabilise `os_string_pathbuf_leak` This PR stabilises `#[feature(os_string_pathbuf_leak)]`, which defines 2 new methods in the std: ```rs impl OsString { pub fn leak<'a>(self) -> &'a mut OsStr; } impl PathBuf { pub fn leak<'a>(self) -> &'a mut Path; } ``` ACP: https://github.com/rust-lang/libs-team/issues/389 Tracking issue: https://github.com/rust-lang/rust/issues/125965 Implementation: https://github.com/rust-lang/rust/pull/125966
2025-06-06Rollup merge of #140418 - tgross35:std-c-size_t, r=workingjubileeGuillaume Gomez-0/+2
Reexport types from `c_size_t` in `std` These are unstably available in `core` and should be in `std` too, but are not currently reexported. Resolve this here. Tracking issue: https://github.com/rust-lang/rust/issues/88345
2025-06-06Stabilised `os_string_pathbuf_leak`schvv31n-1/+1
2025-06-04Rollup merge of #141467 - cyrgani:const-empty-stringlikes, r=AmanieuMatthias Krüger-1/+2
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-05-26Rollup merge of #140936 - teor2345:wtf-surrogate-docs, r=workingjubileeJacob Pratt-3/+3
Clarify WTF-8 safety docs This PR is a follow-up to PR #140159, which clarifies ~~two things~~: - the WTF-8 safety comment [was confusing](https://github.com/rust-lang/rust/pull/140159#discussion_r2082766965), either surrogate condition is actually sufficient for safety, both are not required - ~~the private `os_str::Slice` type name is easily confused with `std::slice`~~ ~~Happy to bikeshed the `OsSlice` name, other alternatives are `OsStrSlice` and `StrSlice`. Now it's got a distinct name from `std::slice`, it's easy to search and replace.~~ cc ``@thaliaarchi`` ``@workingjubilee``
2025-05-24make `OsString::new` and `PathBuf::new` unstably constcyrgani-1/+2
2025-05-21Rollup merge of #141341 - folkertdev:limit-VaArgSafe-impls, r=workingjubileeMatthias Krüger-1/+1
limit impls of `VaArgSafe` to just types that are actually safe tracking issue: https://github.com/rust-lang/rust/issues/44930 Retrieving 8- or 16-bit integer arguments from a `VaList` is not safe, because such types are subject to upcasting. See https://github.com/rust-lang/rust/issues/61275#issuecomment-2193942535 for more detail. This PR also makes the instances of `VaArgSafe` visible in the documentation, and uses a private sealed trait to make sure users cannot create additional impls of `VaArgSafe`, which would almost certainly cause UB. r? `@workingjubilee`
2025-05-21limit impls of `VaArgSafe` to just types that are actually safeFolkert de Vries-1/+1
8 and 16-bit integers are subject to upcasting in C, and hence are not reliably safe. users should perform their own casting and deal with the consequences
2025-05-20Rollup merge of #141289 - compiler-errors:more-self, r=jhprattMatthias Krüger-1/+1
use `Self` alias in self types rather than manually substituting it Of the rougly 145 uses of `self: Ty` in the standard library, 5 of them don't use `Self` but instead choose to manually "substitute" the `impl`'s self type into the type. This leads to weird behavior sometimes (https://github.com/rust-lang/rust/issues/140611#issuecomment-2883761300) -- **to be clear**, none of these usages actually trigger any bugs, but it's possible that they may break in the future (or at least lead to lints), so let's just "fix" them proactively.
2025-05-20use Self alias in self types rather than manually substituting itMichael Goulet-1/+1
2025-05-15Fix confusing WTF surrogate safety docsteor-3/+3
2025-05-12update version placeholdersPietro Albini-1/+1
2025-05-02Rollup merge of #140159 - thaliaarchi:pathbuf-extension, r=workingjubileeStuart Cook-6/+16
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-04-30Make internal `OsString::truncate` and `extend_from_slice` unsafeThalia Archibald-6/+16
Communicate the safety invariants of these methods with `unsafe fn` rather than privacy.
2025-04-28Reexport types from `c_size_t` in `std`Trevor Gross-0/+2
These are unstably available in `core` and should be in `std` too, but are not currently reexported. Resolve this here.
2025-04-27Rollup merge of #137439 - clarfonthey:c-str-module, r=tgross35Matthias Krüger-1/+1
Stabilise `std::ffi::c_str` This finished FCP in #112134 but never actually got a stabilisation PR. Since the FCP in #120048 recently passed to add the `os_str` module, it would be nice to also merge this too, to ensure that both get added in the next version. Note: The added stability attributes which *somehow* were able to be omitted before (rustc bug?) were added based on the fact that they were added in 302551388b1942bb4216bb5a15d9d55cee3643a8, which ended up in 1.85.0. Closes: https://github.com/rust-lang/rust/issues/112134 r? libs-api
2025-04-09replace version placeholderBoxy-5/+5
2025-02-28Specialize constructing OsString from stringsThalia Archibald-1/+24
The WTF-8 version of `OsString` tracks whether it is known to be valid UTF-8 with its `is_known_utf8` field. Specialize `From<AsRef<OsStr>>` so this can be set for UTF-8 string types.
2025-02-28Specialize OsString::push for stringsThalia Archibald-1/+24
When concatenating two WTF-8 strings, surrogate pairs at the boundaries need to be joined. However, since UTF-8 strings cannot contain surrogate halves, this check can be skipped when one string is UTF-8. Specialize `OsString::push` to use a more efficient concatenation in this case. Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro.
2025-02-22Stabilise c_str_moduleltdk-1/+1
2025-02-20Stabilise `os_str_display`riverbl-7/+5
2025-01-21fix OsString::from_encoded_bytes_unchecked descriptionMarijn Schouten-2/+2
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-1/+1
2025-01-06chore: remove redundant words in commentcrystalstall-1/+1
Signed-off-by: crystalstall <crystalruby@qq.com>
2024-12-26docs: inline `std::ffi::c_str` types to `std::ffi`Michael Howell-5/+5
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-11-27replace placeholder versionBoxy-3/+3
2024-11-20implement OsString::truncatebinarycat-4/+8
2024-11-12Make `CloneToUninit` dyn-compatibleZachary S-6/+6
2024-10-29Implement `From<&mut {slice}>` for `Box/Rc/Arc<{slice}>`Eduardo Sánchez Muñoz-0/+27
2024-09-25Use `&raw` in the standard libraryJosh Stone-2/+1
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-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
2024-09-19[Clippy] Swap `redundant_clone` to use diagnostic items instead of pathsGnomedDev-0/+1
2024-09-19[Clippy] Swap `option_as_ref_deref` to use diagnostic items instead of pathsGnomedDev-0/+1
2024-09-05fix: correct {Path,OsStr}::to_string_lossy() docsRyosuke Takahashi-1/+1
2024-07-29Sparkle some attributes over `CloneToUninit` stuffPavel Grigorenko-0/+1
2024-07-29impl CloneToUninit for Path and OsStrPavel Grigorenko-0/+29
2024-07-29Reformat `use` declarations.Nicholas Nethercote-47/+31
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-22Fix some `#[cfg_attr(not(doc), repr(..))]`Pavel Grigorenko-4/+2
Now that #90435 seems to have been resolved.
2024-07-14std: Unsafe-wrap OSStr{,ing}::from_encoded_bytes_uncheckedJubilee Young-3/+2
2024-07-14std: deny(unsafe_op_in_unsafe_fn) but allow sitesJubilee Young-0/+1
This provides a list of locations to hunt down issues in.
2024-06-25`PathBuf::as_mut_vec` removed and verified for UEFI and Windows platforms ↵ash-5/+10
#126333
2024-06-25inner truncate methods for UEFI platformsash-0/+5
2024-06-06fixed memory leaks in PathBuf::leak & OsString::leak testsschvv31n-0/+2
2024-06-04impl OsString::leak & PathBuf::leakschvv31n-0/+26
2024-04-26PathBuf: replace transmuting by accessor functionsRalf Jung-0/+6
2024-04-17Rollup merge of #122201 - coolreader18:doc-clone_from, r=dtolnayMatthias Krüger-0/+4
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.