Skip to content

Commit 1ea26de

Browse files
committed
Auto merge of rust-lang#98152 - JohnTitor:rollup-osr17j6, r=JohnTitor
Rollup of 7 pull requests Successful merges: - rust-lang#97202 (os str capacity documentation) - rust-lang#97964 (Fix suggestions for `&a: T` parameters) - rust-lang#98053 (Fix generic impl rustdoc json output) - rust-lang#98059 (Inline `const_eval_select`) - rust-lang#98092 (Fix sidebar items expand collapse) - rust-lang#98119 (Refactor path segment parameter error) - rust-lang#98135 (Add regression test for rust-lang#93775) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0be896b + bf6f183 commit 1ea26de

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

core/src/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,7 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
23632363
#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
23642364
#[lang = "const_eval_select"]
23652365
#[rustc_do_not_const_check]
2366+
#[inline]
23662367
pub const unsafe fn const_eval_select<ARG, F, G, RET>(
23672368
arg: ARG,
23682369
_called_in_const: F,

std/src/ffi/os_str.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
4545
/// values, encoded in a less-strict variant of UTF-8. This is useful to
4646
/// understand when handling capacity and length values.
4747
///
48+
/// # Capacity of `OsString`
49+
///
50+
/// Capacity uses units of UTF-8 bytes for OS strings which were created from valid unicode, and
51+
/// uses units of bytes in an unspecified encoding for other contents. On a given target, all
52+
/// `OsString` and `OsStr` values use the same units for capacity, so the following will work:
53+
/// ```
54+
/// use std::ffi::{OsStr, OsString};
55+
///
56+
/// fn concat_os_strings(a: &OsStr, b: &OsStr) -> OsString {
57+
/// let mut ret = OsString::with_capacity(a.len() + b.len()); // This will allocate
58+
/// ret.push(a); // This will not allocate further
59+
/// ret.push(b); // This will not allocate further
60+
/// ret
61+
/// }
62+
/// ```
63+
///
4864
/// # Creating an `OsString`
4965
///
5066
/// **From a Rust string**: `OsString` implements
@@ -186,7 +202,7 @@ impl OsString {
186202
/// OS strings without reallocating. If `capacity` is 0, the string will not
187203
/// allocate.
188204
///
189-
/// See main `OsString` documentation information about encoding.
205+
/// See the main `OsString` documentation information about encoding and capacity units.
190206
///
191207
/// # Examples
192208
///
@@ -229,7 +245,7 @@ impl OsString {
229245

230246
/// Returns the capacity this `OsString` can hold without reallocating.
231247
///
232-
/// See `OsString` introduction for information about encoding.
248+
/// See the main `OsString` documentation information about encoding and capacity units.
233249
///
234250
/// # Examples
235251
///
@@ -251,6 +267,8 @@ impl OsString {
251267
///
252268
/// The collection may reserve more space to avoid frequent reallocations.
253269
///
270+
/// See the main `OsString` documentation information about encoding and capacity units.
271+
///
254272
/// # Examples
255273
///
256274
/// ```
@@ -272,6 +290,8 @@ impl OsString {
272290
/// greater than or equal to `self.len() + additional`. Does nothing if
273291
/// capacity is already sufficient.
274292
///
293+
/// See the main `OsString` documentation information about encoding and capacity units.
294+
///
275295
/// # Errors
276296
///
277297
/// If the capacity overflows, or the allocator reports a failure, then an error
@@ -313,6 +333,8 @@ impl OsString {
313333
///
314334
/// [`reserve`]: OsString::reserve
315335
///
336+
/// See the main `OsString` documentation information about encoding and capacity units.
337+
///
316338
/// # Examples
317339
///
318340
/// ```
@@ -340,6 +362,8 @@ impl OsString {
340362
///
341363
/// [`try_reserve`]: OsString::try_reserve
342364
///
365+
/// See the main `OsString` documentation information about encoding and capacity units.
366+
///
343367
/// # Errors
344368
///
345369
/// If the capacity overflows, or the allocator reports a failure, then an error
@@ -373,6 +397,8 @@ impl OsString {
373397

374398
/// Shrinks the capacity of the `OsString` to match its length.
375399
///
400+
/// See the main `OsString` documentation information about encoding and capacity units.
401+
///
376402
/// # Examples
377403
///
378404
/// ```
@@ -399,6 +425,8 @@ impl OsString {
399425
///
400426
/// If the current capacity is less than the lower limit, this is a no-op.
401427
///
428+
/// See the main `OsString` documentation information about encoding and capacity units.
429+
///
402430
/// # Examples
403431
///
404432
/// ```
@@ -773,6 +801,8 @@ impl OsStr {
773801
/// This number is simply useful for passing to other methods, like
774802
/// [`OsString::with_capacity`] to avoid reallocations.
775803
///
804+
/// See the main `OsString` documentation information about encoding and capacity units.
805+
///
776806
/// # Examples
777807
///
778808
/// ```

0 commit comments

Comments
 (0)