Commit Graph

204 Commits

Author SHA1 Message Date
bjorn3 366cf883c7 Add comments 2026-03-24 10:01:46 +01:00
bjorn3 0b69ff5074 Defer codegen for the VaList Drop impl to actual uses
This allows compiling libcore with codegen backends that don't actually
implement VaList like cg_clif.
2026-03-20 11:48:36 +01:00
Peter Jaszkowiak bc4ceaddcd stabilize new RangeToInclusive type
stabilizes `core::range::RangeToInclusive`
add missing trait impls for new RangeToInclusive
add missing trait impls for new RangeFrom
2026-02-28 21:44:18 -07: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
Jana Dönszelmann 6c38e469b2 Rollup merge of #152675 - folkertdev:va-list-docs, r=tgross35
Improve `VaList` stdlib docs

tracking issue: https://github.com/rust-lang/rust/issues/44930

Some improvements to the `VaList` documentation, at least adding an example. We should link to the reference for c-variadic functions once stable. I've tried to call out explicitly that the type is meant for sending over the FFI boundary.

r? workingjubilee
cc @tgross35
2026-02-17 14:18:46 +01:00
Folkert de Vries 3b5874e570 Improve VaList stdlib docs 2026-02-16 14:50:14 +01:00
Folkert de Vries 981dacc34f feature-gate c-variadic definitions and calls in const contexts 2026-02-15 19:54:25 +01:00
Folkert de Vries 02c4af397e c-variadic functions in rustc_const_eval 2026-02-14 22:27:39 +01:00
Folkert de Vries ce693807f6 make Va::arg and VaList::drop const fns 2026-02-14 22:26:24 +01:00
Pavel Grigorenko 06398554bf Stabilize str_as_str 2026-01-24 21:32:31 +03:00
Folkert de Vries 922057cfa6 c-variadic: make VaList::drop call the rust va_end 2026-01-20 18:38:50 +01:00
Folkert de Vries dd9241d150 c_variadic: use Clone instead of LLVM va_copy 2026-01-20 18:38:50 +01: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
Folkert de Vries 023f38fe73 custom VaList layout for Hexagon 2025-12-15 20:00:05 +01:00
Folkert de Vries 376b284521 document VaList ABI for more targets 2025-12-04 10:51:38 +01:00
beetrees f7b3c1d3c0 Rework c_variadic 2025-12-04 10:51:34 +01:00
Matthias Krüger 2eeec770fe Rollup merge of #146925 - DiuDiu777:va-doc-fix, r=tgross35
Add doc for va_list APIs

I observed that [PR146521](https://github.com/rust-lang/rust/pull/146521) submitted two weeks ago resolved some documentation issues related to `VaListImpl`, similar to the previous [PR136969](https://github.com/rust-lang/rust/pull/136969).

This PR specifically adds requirements about argument availability for `VaListImpl::arg`, and also adds safety descriptions to the three associated intrinsic APIs.
2025-11-20 11:15:49 +01:00
Matthias Krüger 4e5c61e932 Rollup merge of #148504 - NeatNit:intlong, r=ibraheemdev
Fix link in c_longlong documentation

Ran across this mistake when reading [the documentation](https://doc.rust-lang.org/std/ffi/type.c_longlong.html). I went through the other `.md` files in this directory and didn't spot any other errors.

**I did not check the output of this change** - I couldn't figure out how to get `cargo doc` to work and I figured it's not worth the distraction. It can't really go wrong, can it?
2025-11-17 18:07:32 +01:00
Pavel Grigorenko a197ebdb07 {CStr,OsStr,Path}::as_$1 2025-11-11 23:08:15 +03:00
Bart Jacobs a56fc9c213 Some tweaks 2025-11-11 19:56:48 +01:00
Bart Jacobs 06e2e7aae1 CStr docs: Fix CStr vs &CStr confusion
The CStr docs used to say things about CStr that are only true for &CStr.

Also, it's the bytes that are being borrowed, not the reference. One could say that it's the reference that is doing the borrowing, rather than being borrowed.
2025-11-11 17:18:28 +01:00
Nitai Sasson 1b0a3d8bc8 Fix link in c_longlong documentation 2025-11-04 23:51:22 +02:00
Folkert de Vries 1866b3a8cf assert that #[rustc_pass_indirectly_in_non_rustic_abis] is respected 2025-11-04 09:56:21 +01:00
LemonJ 0d6a313e6e add doc for va_list APIs 2025-10-04 16:32:46 +08:00
León Orell Valerian Liehr 35e582f982 Library: Remove remaining private #[repr] workarounds
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2025-09-27 17:09:01 +02:00
joboet aa537824c4 core: simplify CStr::default()
Just use a `CStr`-literal...
2025-09-24 00:50:36 +02:00
Thalia Archibald 776c199c7b Fix std build for xtensa 2025-09-19 19:18:10 -06:00
Folkert de Vries 61a3593786 c-variadic: document core::ffi::VaArgSafe
and document `VaList::arg`.
2025-09-13 21:04:58 +02:00
ltdk 1c64d3e6d1 Constify conversion traits 2025-09-01 21:38:26 -04:00
Boxy 9ccc9f177e replace version placeholder 2025-08-06 13:22:38 +01:00
Matthias Krüger 08fa97173e Rollup merge of #143326 - hkBst:rm-deprecated-1, r=jhpratt
Remove deprecated `Error::description` impl from `c_str::FromBytesWithNulError`
2025-07-17 10:41:43 +02:00
Folkert de Vries 4ae22fba5b move the va_copy, va_arg and va_end to core::intrinsics 2025-07-05 09:18:49 +02:00
Marijn Schouten 674724c741 remove deprecated from core::ffi::c_str 2025-07-02 12:30:05 +00:00
Marijn Schouten 626ca82faf byte-addresses memory -> byte-addressed memory 2025-07-02 11:18:02 +00:00
MetaNova 1080b571ec Corrected spelling mistake in c_str.rs
Changed "you're" to "your" on line 470.
2025-06-24 15:30:32 -04:00
Guillaume Gomez 30550c048d Rollup merge of #137268 - bjoernager:c-string-eq-c-str, r=Amanieu
Allow comparisons between `CStr`, `CString`, and `Cow<CStr>`.

Closes: #137265

This PR adds the trait implementations proposed in the [ACP](https://github.com/rust-lang/libs-team/issues/517/) under the `c_string_eq_c_str` feature gate:

```rust
// core::ffi

impl PartialEq<&Self> for CStr;

impl PartialEq<CString> for CStr;

impl PartialEq<Cow<'_, Self>> for CStr;

// alloc::ffi

impl PartialEq<CStr> for CString;

impl PartialEq<&CStr> for CString;

impl PartialEq<Cow<'_, CStr>> for CString;

// alloc::borrow

impl PartialEq<CStr> for Cow<'_, CStr>;

impl PartialEq<&CStr> for Cow<'_, CStr>;

impl PartialEq<CString> for Cow<'_, CStr>;
```

As I understand it, stable traits cannot be unstably implemented for stable types, and we would thereby be forced to skip the FCP and directly stabilise these implementations (as is done in this PR).

(`@joshtriplett` mentioned that Crater may have to be run).
2025-06-24 15:39:37 +02:00
Tamir Duberstein a82062055a Delegate <CStr as Debug> to ByteStr
This allows UTF-8 characters to be printed without escapes, rather than
just ASCII.
2025-06-12 12:53:14 -04:00
Ralf Jung f388c987cf terminology: allocated object → allocation 2025-05-31 22:49:14 +02:00
Jacob Pratt ba042d7cb1 Rollup merge of #139994 - tamird:cstr-display, r=Amanieu
add `CStr::display`

The implementation delegates to `<ByteStr as Display>::fmt`.

Link: https://github.com/rust-lang/libs-team/issues/550
Link: https://github.com/rust-lang/rust/issues/139984.

r? ```@BurntSushi```
cc ```@Darksonn``` ```@tgross35``` ```@ojeda``` ```@joshtriplett```
2025-05-29 04:50:47 +02:00
Jacob Pratt c27b7c2214 Rollup merge of #141361 - folkertdev:varargs-cfg, r=workingjubilee
use `cfg_select!` to select the right `VaListImpl` definition

tracking issue: https://github.com/rust-lang/rust/issues/44930

Just a bit of cleanup really.

We could use `PhantomInvariantLifetime<'f>` (https://github.com/rust-lang/rust/issues/135806) to make it more precise what that `PhantomData<&'f mut &'f c_void>` marker is doing. I'm not sure how ready that feature is though, `@jhpratt` are these types good to use internally?

---

Some research into the lifetimes of `VaList` and `VaListImpl`:

It's easy to see why the lifetime of these types should not be extended, a `VaList` or `VaListImpl` escaping its function is a bad idea. I don't currently see why coercing the lifetime to a shorter lifetime is problematic though, but probably I just don't understand variance well enough to see it. The history does not provide much explanation:

- https://github.com/immunant/rust/commit/08140878fefaa4b16939b904bf825b7107069b42 original implementation
- https://github.com/immunant/rust/commit/b9ea653aee231114acbe6d4b3c7b1d692772d060 adds `VaListImpl<'f>`, but it is only covariant in `'f`
- https://github.com/rust-lang/rust/pull/62639 makes `VaListImpl<'f>` invariant over `'f` (because `VaList<'a, 'f>` is already invariant over `'f`, but I think that is just an implementation detail?)

Beyond that I don't see how the lifetime situation can be simplified significantly, e.g. this function really needs `'copy` to be unconstrained.

```rust
/// Copies the `va_list` at the current location.
pub unsafe fn with_copy<F, R>(&self, f: F) -> R
where
    F: for<'copy> FnOnce(VaList<'copy, 'f>) -> R,
{
    let mut ap = self.clone();
    let ret = f(ap.as_va_list());
    // SAFETY: the caller must uphold the safety contract for `va_end`.
    unsafe {
        va_end(&mut ap);
    }
    ret
}
```

`@rustbot` label +F-c_variadic
r? `@workingjubilee`
2025-05-25 04:00:57 +02:00
Tamir Duberstein 7b5a079368 Use C-string literals to reduce boilerplate
Reduce boilerplate in doctests by replacing fallible function calls with
literals.
2025-05-24 08:34:16 -04:00
Tamir Duberstein 947be5f431 add CStr::display
The implementation delegates to `<ByteStr as Display>::fmt`.

Link: https://github.com/rust-lang/libs-team/issues/550
Link: https://github.com/rust-lang/rust/issues/139984.
2025-05-24 08:24:52 -04:00
Folkert de Vries 89a8abc4be use cfg_select! to select the right VaListImpl definition 2025-05-23 12:51:04 +02:00
bors 6eef33bb39 Auto merge of #137198 - tgross35:cfg-match-rename, r=Amanieu
Rename `cfg_match!` to `cfg_select!`

[`@Nemo157` pointed out](https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605) that `cfg_match!` syntax does not actually align well with match syntax, which is a possible source of confusion. The comment points out that usage is instead more similar to ecosystem `select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

Tracking issue: https://github.com/rust-lang/rust/issues/115585

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-22 02:14:23 +00:00
Folkert de Vries d8a22a281c limit impls of VaArgSafe to just types that are actually safe
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-21 15:36:29 +02:00
Trevor Gross 999967a57d Rename cfg_match! to cfg_select!
At [1] it was pointed out that `cfg_match!` syntax does not actually
align well with match syntax, which is a possible source of confusion.
The comment points out that usage is instead more similar to ecosystem
`select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

Tracking issue: https://github.com/rust-lang/rust/issues/115585

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-20 21:16:23 +00:00
Pietro Albini a360940ac9 update version placeholders 2025-05-12 15:33:30 +02:00
Matthias Krüger 3af00f0889 Rollup merge of #140297 - shepmaster:cstr-lossy, r=joboet
Update example to use CStr::to_string_lossy
2025-04-27 11:54:58 +02:00
Matthias Krüger 9630242e5e Rollup merge of #137439 - clarfonthey:c-str-module, r=tgross35
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 302551388b, which ended up in 1.85.0.

Closes: https://github.com/rust-lang/rust/issues/112134

r? libs-api
2025-04-27 11:54:56 +02:00