Skip to content

Commit 4d6712b

Browse files
committed
Merge from rustc
2 parents 32f57ef + 3be7537 commit 4d6712b

File tree

16 files changed

+285
-157
lines changed

16 files changed

+285
-157
lines changed

core/src/ffi/c_str.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,30 @@ impl CStr {
632632
// instead of doing it afterwards.
633633
str::from_utf8(self.to_bytes())
634634
}
635+
636+
/// Returns an object that implements [`Display`] for safely printing a [`CStr`] that may
637+
/// contain non-Unicode data.
638+
///
639+
/// Behaves as if `self` were first lossily converted to a `str`, with invalid UTF-8 presented
640+
/// as the Unicode replacement character: �.
641+
///
642+
/// [`Display`]: fmt::Display
643+
///
644+
/// # Examples
645+
///
646+
/// ```
647+
/// #![feature(cstr_display)]
648+
///
649+
/// let cstr = c"Hello, world!";
650+
/// println!("{}", cstr.display());
651+
/// ```
652+
#[unstable(feature = "cstr_display", issue = "139984")]
653+
#[must_use = "this does not display the `CStr`; \
654+
it returns an object that can be displayed"]
655+
#[inline]
656+
pub fn display(&self) -> impl fmt::Display {
657+
crate::bstr::ByteStr::from_bytes(self.to_bytes())
658+
}
635659
}
636660

637661
// `.to_bytes()` representations are compared instead of the inner `[c_char]`s,

core/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ pub mod assert_matches {
225225

226226
// We don't export this through #[macro_export] for now, to avoid breakage.
227227
#[unstable(feature = "autodiff", issue = "124509")]
228+
#[cfg(not(bootstrap))]
228229
/// Unstable module containing the unstable `autodiff` macro.
229230
pub mod autodiff {
230231
#[unstable(feature = "autodiff", issue = "124509")]
231-
pub use crate::macros::builtin::autodiff;
232+
pub use crate::macros::builtin::{autodiff_forward, autodiff_reverse};
232233
}
233234

234235
#[unstable(feature = "contracts", issue = "128044")]

core/src/macros/mod.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,20 +1519,41 @@ pub(crate) mod builtin {
15191519
($file:expr $(,)?) => {{ /* compiler built-in */ }};
15201520
}
15211521

1522-
/// Automatic Differentiation macro which allows generating a new function to compute
1523-
/// the derivative of a given function. It may only be applied to a function.
1524-
/// The expected usage syntax is
1525-
/// `#[autodiff(NAME, MODE, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1526-
/// where:
1527-
/// NAME is a string that represents a valid function name.
1528-
/// MODE is any of Forward, Reverse, ForwardFirst, ReverseFirst.
1529-
/// INPUT_ACTIVITIES consists of one valid activity for each input parameter.
1530-
/// OUTPUT_ACTIVITY must not be set if we implicitly return nothing (or explicitly return
1531-
/// `-> ()`). Otherwise it must be set to one of the allowed activities.
1522+
/// This macro uses forward-mode automatic differentiation to generate a new function.
1523+
/// It may only be applied to a function. The new function will compute the derivative
1524+
/// of the function to which the macro was applied.
1525+
///
1526+
/// The expected usage syntax is:
1527+
/// `#[autodiff_forward(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1528+
///
1529+
/// - `NAME`: A string that represents a valid function name.
1530+
/// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
1531+
/// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
1532+
/// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
1533+
#[unstable(feature = "autodiff", issue = "124509")]
1534+
#[allow_internal_unstable(rustc_attrs)]
1535+
#[rustc_builtin_macro]
1536+
#[cfg(not(bootstrap))]
1537+
pub macro autodiff_forward($item:item) {
1538+
/* compiler built-in */
1539+
}
1540+
1541+
/// This macro uses reverse-mode automatic differentiation to generate a new function.
1542+
/// It may only be applied to a function. The new function will compute the derivative
1543+
/// of the function to which the macro was applied.
1544+
///
1545+
/// The expected usage syntax is:
1546+
/// `#[autodiff_reverse(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1547+
///
1548+
/// - `NAME`: A string that represents a valid function name.
1549+
/// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
1550+
/// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
1551+
/// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
15321552
#[unstable(feature = "autodiff", issue = "124509")]
15331553
#[allow_internal_unstable(rustc_attrs)]
15341554
#[rustc_builtin_macro]
1535-
pub macro autodiff($item:item) {
1555+
#[cfg(not(bootstrap))]
1556+
pub macro autodiff_reverse($item:item) {
15361557
/* compiler built-in */
15371558
}
15381559

core/src/marker/variance.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ phantom_lifetime! {
131131
///
132132
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
133133
///
134+
/// Note: If `'a` is otherwise contravariant or invariant, the resulting type is invariant.
135+
///
134136
/// ## Layout
135137
///
136138
/// For all `'a`, the following are guaranteed:
@@ -146,6 +148,8 @@ phantom_lifetime! {
146148
///
147149
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
148150
///
151+
/// Note: If `'a` is otherwise covariant or invariant, the resulting type is invariant.
152+
///
149153
/// ## Layout
150154
///
151155
/// For all `'a`, the following are guaranteed:
@@ -180,6 +184,8 @@ phantom_type! {
180184
///
181185
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
182186
///
187+
/// Note: If `T` is otherwise contravariant or invariant, the resulting type is invariant.
188+
///
183189
/// ## Layout
184190
///
185191
/// For all `T`, the following are guaranteed:
@@ -196,6 +202,8 @@ phantom_type! {
196202
///
197203
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
198204
///
205+
/// Note: If `T` is otherwise covariant or invariant, the resulting type is invariant.
206+
///
199207
/// ## Layout
200208
///
201209
/// For all `T`, the following are guaranteed:

core/src/sync/atomic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3885,10 +3885,13 @@ unsafe fn atomic_sub<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
38853885
}
38863886
}
38873887

3888+
/// Publicly exposed for stdarch; nobody else should use this.
38883889
#[inline]
38893890
#[cfg(target_has_atomic)]
38903891
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
3891-
unsafe fn atomic_compare_exchange<T: Copy>(
3892+
#[unstable(feature = "core_intrinsics", issue = "none")]
3893+
#[doc(hidden)]
3894+
pub unsafe fn atomic_compare_exchange<T: Copy>(
38923895
dst: *mut T,
38933896
old: T,
38943897
new: T,

coretests/tests/ffi/cstr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ fn debug() {
1919
let s = c"abc\x01\x02\n\xE2\x80\xA6\xFF";
2020
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n\xe2\x80\xa6\xff""#);
2121
}
22+
23+
#[test]
24+
fn display() {
25+
let s = c"\xf0\x28\x8c\xbc";
26+
assert_eq!(format!("{}", s.display()), "�(��");
27+
}

coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(core_io_borrowed_buf)]
2424
#![feature(core_private_bignum)]
2525
#![feature(core_private_diy_float)]
26+
#![feature(cstr_display)]
2627
#![feature(dec2flt)]
2728
#![feature(duration_constants)]
2829
#![feature(duration_constructors)]

0 commit comments

Comments
 (0)