Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b719a60
Specify that split_ascii_whitespace uses the same definition as is_as…
SimonSapin May 12, 2025
5d7c518
Fix confusing WTF surrogate safety docs
teor2345 May 12, 2025
fcfcd6b
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`
Sa4dUs May 6, 2025
486f309
Remove unnecessary handling of ERROR_IO_PENDING
cberner May 7, 2025
f4fcaca
Add From<TryLockError> for io::Error
cberner May 20, 2025
87b0fac
Add data_ptr method to Mutex and RwLock
jplatte Apr 27, 2025
fb83dec
Add more docs to new data_ptr methods
jplatte May 21, 2025
dc6d970
Add ReentrantLock::data_ptr
jplatte May 21, 2025
b58a848
Disable autodiff bootstrapping
Sa4dUs May 10, 2025
2738601
Add some track_caller info to precondition panics
saethlin Aug 27, 2024
ea8398b
add CStr::display
tamird Apr 17, 2025
c81153f
intrinsics: reduce references to LLVM and update notes on where the i…
RalfJung May 24, 2025
cb0eb79
Path::with_extension: improve examples
tshepang May 24, 2025
ffde704
reduce clutter... too many imports
tshepang May 24, 2025
8797629
improve the `std::fs::create_dir_all` docs related to atomicity
fluiderson May 23, 2025
4c3aa3c
clean up old rintf leftovers
RalfJung May 25, 2025
d578eff
Implement normalize lexically
ChrisDenton Dec 23, 2024
0019894
increase perf of charsearcher for single ascii characters
bend-n May 24, 2025
1f1f72f
Rollup merge of #134696 - ChrisDenton:normalize-lexically, r=workingj…
jhpratt May 26, 2025
7b2da84
Rollup merge of #140936 - teor2345:wtf-surrogate-docs, r=workingjubilee
jhpratt May 26, 2025
82715e1
Rollup merge of #140952 - SimonSapin:ascii_whitespace_definition, r=d…
jhpratt May 26, 2025
422d0d5
Rollup merge of #141472 - fluiderson:dev, r=workingjubilee
jhpratt May 26, 2025
a230e7a
Rollup merge of #141516 - bend-n:okay, r=workingjubilee
jieyouxu May 26, 2025
6e70eb6
Call out possibility of invariant result
jhpratt May 26, 2025
556facc
Minor macro docs fixes
Sa4dUs May 26, 2025
d9183fc
Rollup merge of #141582 - RalfJung:cleanup, r=bjorn3
compiler-errors May 27, 2025
8a60737
Do not get proc_macro from the sysroot in rustc
bjorn3 May 27, 2025
de64aca
✨ feat: map_or_default for result and option
tkr-sh May 27, 2025
c4389da
Rollup merge of #141312 - cberner:filelock_from, r=joshtriplett
matthiaskrgr May 27, 2025
c3c5ff1
Auto merge of #129658 - saethlin:spare-a-crumb, r=jhpratt
bors May 27, 2025
7eb84f9
Rollup merge of #141659 - tkr-sh:map-or-default, r=Amanieu
tgross35 May 28, 2025
f869270
Auto merge of #141668 - tgross35:rollup-03gg6lf, r=tgross35
bors May 28, 2025
b43d184
coretests: simplify test_float macro to derive more things from the t…
RalfJung May 26, 2025
2303f50
coretests: add abs() and copysign() tests, and remove now-unnecessary…
RalfJung May 26, 2025
4ad0897
Test(fs): Fix test_eq_windows_file_type for Windows 7
PaulDance May 16, 2025
33bd15e
Add diagnostic items to sys::Mutex
Patrick-6 May 28, 2025
f5e3a6b
Make pthread Mutex internals less public
Patrick-6 May 28, 2025
e2a7b41
core: unstably expose atomic_compare_exchange so stdarch can use it
RalfJung May 28, 2025
0f9ab19
Rollup merge of #140369 - jplatte:mutex-rwlock-data-ptr, r=Amanieu
tgross35 May 28, 2025
dcb11c4
Rollup merge of #140697 - Sa4dUs:split-autodiff, r=ZuseZ4
tgross35 May 28, 2025
6662b01
Add comments to diagnostic items
Patrick-6 May 28, 2025
c11f2d3
Rollup merge of #141104 - PaulDance:fix-win7-test_eq_windows_file_typ…
jhpratt May 29, 2025
b5bafca
Rollup merge of #141477 - tshepang:patch-1, r=ChrisDenton
jhpratt May 29, 2025
683758c
Rollup merge of #141533 - RalfJung:rintf, r=bjorn3
jhpratt May 29, 2025
593dd85
Rollup merge of #141612 - jhpratt:phantom-docs, r=tgross35
jhpratt May 29, 2025
cbbddf6
Rollup merge of #141687 - RalfJung:atomic_compare_exchange, r=bjorn3
jhpratt May 29, 2025
835b73c
Rollup merge of #141690 - Patrick-6:intercept-mutex, r=m-ou-se
jhpratt May 29, 2025
45278f6
Rollup merge of #139994 - tamird:cstr-display, r=Amanieu
jhpratt May 29, 2025
8353439
Rollup merge of #141571 - RalfJung:float-tests, r=tgross35
jhpratt May 29, 2025
3be7537
Auto merge of #141717 - jhpratt:rollup-neu8nzl, r=jhpratt
bors May 29, 2025
96897df
Auto merge of #141595 - bjorn3:rustc_no_sysroot_proc_macro, r=onur-ozkan
bors May 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl Layout {
#[rustc_const_stable(feature = "const_alloc_layout_unchecked", since = "1.36.0")]
#[must_use]
#[inline]
#[track_caller]
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
assert_unsafe_precondition!(
check_library_ub,
Expand Down
1 change: 1 addition & 0 deletions core/src/ascii/ascii_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ impl AsciiChar {
/// something useful. It might be tightened before stabilization.)
#[unstable(feature = "ascii_char", issue = "110998")]
#[inline]
#[track_caller]
pub const unsafe fn digit_unchecked(d: u8) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down
1 change: 1 addition & 0 deletions core/src/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
#[inline]
#[must_use]
#[allow(unnecessary_transmutes)]
#[track_caller]
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
// SAFETY: the caller must guarantee that `i` is a valid char value.
unsafe {
Expand Down
24 changes: 24 additions & 0 deletions core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,30 @@ impl CStr {
// instead of doing it afterwards.
str::from_utf8(self.to_bytes())
}

/// Returns an object that implements [`Display`] for safely printing a [`CStr`] that may
/// contain non-Unicode data.
///
/// Behaves as if `self` were first lossily converted to a `str`, with invalid UTF-8 presented
/// as the Unicode replacement character: �.
///
/// [`Display`]: fmt::Display
///
/// # Examples
///
/// ```
/// #![feature(cstr_display)]
///
/// let cstr = c"Hello, world!";
/// println!("{}", cstr.display());
/// ```
#[unstable(feature = "cstr_display", issue = "139984")]
#[must_use = "this does not display the `CStr`; \
it returns an object that can be displayed"]
#[inline]
pub fn display(&self) -> impl fmt::Display {
crate::bstr::ByteStr::from_bytes(self.to_bytes())
}
}

// `.to_bytes()` representations are compared instead of the inner `[c_char]`s,
Expand Down
2 changes: 1 addition & 1 deletion core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ use crate::{intrinsics, ub_checks};
#[inline]
#[stable(feature = "unreachable", since = "1.27.0")]
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unreachable_unchecked() -> ! {
ub_checks::assert_unsafe_precondition!(
check_language_ub,
Expand Down
43 changes: 10 additions & 33 deletions core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Compiler intrinsics.
//!
//! The corresponding definitions are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>.
//! The corresponding const implementations are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
//! These are the imports making intrinsics available to Rust code. The actual implementations live in the compiler.
//! Some of these intrinsics are lowered to MIR in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_transform/src/lower_intrinsics.rs>.
//! The remaining intrinsics are implemented for the LLVM backend in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs>
//! and <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>,
//! and for const evaluation in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
//!
//! # Const intrinsics
//!
Expand All @@ -20,28 +23,14 @@
//!
//! The volatile intrinsics provide operations intended to act on I/O
//! memory, which are guaranteed to not be reordered by the compiler
//! across other volatile intrinsics. See the LLVM documentation on
//! [[volatile]].
//!
//! [volatile]: https://llvm.org/docs/LangRef.html#volatile-memory-accesses
//! across other volatile intrinsics. See [`read_volatile`][ptr::read_volatile]
//! and [`write_volatile`][ptr::write_volatile].
//!
//! # Atomics
//!
//! The atomic intrinsics provide common atomic operations on machine
//! words, with multiple possible memory orderings. They obey the same
//! semantics as C++11. See the LLVM documentation on [[atomics]].
//!
//! [atomics]: https://llvm.org/docs/Atomics.html
//!
//! A quick refresher on memory ordering:
//!
//! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
//! take place after the barrier.
//! * Release - a barrier for releasing a lock. Preceding reads and writes
//! take place before the barrier.
//! * Sequentially consistent - sequentially consistent operations are
//! guaranteed to happen in order. This is the standard mode for working
//! with atomic types and is equivalent to Java's `volatile`.
//! words, with multiple possible memory orderings. See the
//! [atomic types][crate::sync::atomic] docs for details.
//!
//! # Unwinding
//!
Expand Down Expand Up @@ -2296,12 +2285,6 @@ pub fn round_ties_even_f16(x: f16) -> f16;
#[rustc_nounwind]
pub fn round_ties_even_f32(x: f32) -> f32;

/// Provided for compatibility with stdarch. DO NOT USE.
#[inline(always)]
pub unsafe fn rintf32(x: f32) -> f32 {
round_ties_even_f32(x)
}

/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number with an even
/// least significant digit.
///
Expand All @@ -2311,12 +2294,6 @@ pub unsafe fn rintf32(x: f32) -> f32 {
#[rustc_nounwind]
pub fn round_ties_even_f64(x: f64) -> f64;

/// Provided for compatibility with stdarch. DO NOT USE.
#[inline(always)]
pub unsafe fn rintf64(x: f64) -> f64 {
round_ties_even_f64(x)
}

/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number with an even
/// least significant digit.
///
Expand Down Expand Up @@ -2634,7 +2611,7 @@ pub const fn three_way_compare<T: Copy>(lhs: T, rhss: T) -> crate::cmp::Ordering
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
#[rustc_nounwind]
#[rustc_intrinsic]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
pub const unsafe fn disjoint_bitor<T: ~const fallback::DisjointBitOr>(a: T, b: T) -> T {
// SAFETY: same preconditions as this function.
Expand Down
3 changes: 2 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ pub mod assert_matches {

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

#[unstable(feature = "contracts", issue = "128044")]
Expand Down
43 changes: 32 additions & 11 deletions core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,20 +1519,41 @@ pub(crate) mod builtin {
($file:expr $(,)?) => {{ /* compiler built-in */ }};
}

/// Automatic Differentiation macro which allows generating a new function to compute
/// the derivative of a given function. It may only be applied to a function.
/// The expected usage syntax is
/// `#[autodiff(NAME, MODE, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
/// where:
/// NAME is a string that represents a valid function name.
/// MODE is any of Forward, Reverse, ForwardFirst, ReverseFirst.
/// INPUT_ACTIVITIES consists of one valid activity for each input parameter.
/// OUTPUT_ACTIVITY must not be set if we implicitly return nothing (or explicitly return
/// `-> ()`). Otherwise it must be set to one of the allowed activities.
/// This macro uses forward-mode automatic differentiation to generate a new function.
/// It may only be applied to a function. The new function will compute the derivative
/// of the function to which the macro was applied.
///
/// The expected usage syntax is:
/// `#[autodiff_forward(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
///
/// - `NAME`: A string that represents a valid function name.
/// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
/// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
/// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
#[unstable(feature = "autodiff", issue = "124509")]
#[allow_internal_unstable(rustc_attrs)]
#[rustc_builtin_macro]
#[cfg(not(bootstrap))]
pub macro autodiff_forward($item:item) {
/* compiler built-in */
}

/// This macro uses reverse-mode automatic differentiation to generate a new function.
/// It may only be applied to a function. The new function will compute the derivative
/// of the function to which the macro was applied.
///
/// The expected usage syntax is:
/// `#[autodiff_reverse(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
///
/// - `NAME`: A string that represents a valid function name.
/// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
/// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
/// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
#[unstable(feature = "autodiff", issue = "124509")]
#[allow_internal_unstable(rustc_attrs)]
#[rustc_builtin_macro]
pub macro autodiff($item:item) {
#[cfg(not(bootstrap))]
pub macro autodiff_reverse($item:item) {
/* compiler built-in */
}

Expand Down
8 changes: 8 additions & 0 deletions core/src/marker/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ phantom_lifetime! {
///
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
///
/// Note: If `'a` is otherwise contravariant or invariant, the resulting type is invariant.
///
/// ## Layout
///
/// For all `'a`, the following are guaranteed:
Expand All @@ -146,6 +148,8 @@ phantom_lifetime! {
///
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
///
/// Note: If `'a` is otherwise covariant or invariant, the resulting type is invariant.
///
/// ## Layout
///
/// For all `'a`, the following are guaranteed:
Expand Down Expand Up @@ -180,6 +184,8 @@ phantom_type! {
///
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
///
/// Note: If `T` is otherwise contravariant or invariant, the resulting type is invariant.
///
/// ## Layout
///
/// For all `T`, the following are guaranteed:
Expand All @@ -196,6 +202,8 @@ phantom_type! {
///
/// [1]: https://doc.rust-lang.org/stable/reference/subtyping.html#variance
///
/// Note: If `T` is otherwise covariant or invariant, the resulting type is invariant.
///
/// ## Layout
///
/// For all `T`, the following are guaranteed:
Expand Down
12 changes: 6 additions & 6 deletions core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -705,7 +705,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -855,7 +855,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -1199,7 +1199,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_neg(self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -1327,7 +1327,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -1448,7 +1448,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down
2 changes: 2 additions & 0 deletions core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ where
#[rustc_const_stable(feature = "nonzero", since = "1.28.0")]
#[must_use]
#[inline]
#[track_caller]
pub const unsafe fn new_unchecked(n: T) -> Self {
match Self::new(n) {
Some(n) => n,
Expand Down Expand Up @@ -428,6 +429,7 @@ where
#[unstable(feature = "nonzero_from_mut", issue = "106290")]
#[must_use]
#[inline]
#[track_caller]
pub unsafe fn from_mut_unchecked(n: &mut T) -> &mut Self {
match Self::from_mut(n) {
Some(n) => n,
Expand Down
10 changes: 5 additions & 5 deletions core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ macro_rules! uint_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -791,7 +791,7 @@ macro_rules! uint_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -974,7 +974,7 @@ macro_rules! uint_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -1588,7 +1588,7 @@ macro_rules! uint_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down Expand Up @@ -1709,7 +1709,7 @@ macro_rules! uint_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[track_caller]
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
assert_unsafe_precondition!(
check_language_ub,
Expand Down
1 change: 1 addition & 0 deletions core/src/ops/index_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl IndexRange {
/// # Safety
/// - `start <= end`
#[inline]
#[track_caller]
pub(crate) const unsafe fn new_unchecked(start: usize, end: usize) -> Self {
ub_checks::assert_unsafe_precondition!(
check_library_ub,
Expand Down
Loading