Skip to content

Rollup of 11 pull requests #144622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c89fe80
Rename extended rustc tool macros
Kobzol Jun 18, 2025
d1683e7
Add metadata to `Cargo` and `RustAnalyzer` tools
Kobzol Jul 22, 2025
ca66698
Cleanup `ensure_if_default` to not require `Option` output
Kobzol Jul 22, 2025
1783af7
Add step metadata to `RustAnalyzerProcMacroSrv`
Kobzol Jul 22, 2025
533a78d
Rename `Builder::rustdoc` to `Builder::rustdoc_for_compiler`
Kobzol Jul 22, 2025
7a5f9cb
Implement `RustcPrivateCompilers` to unify building of `rustc_private…
Kobzol Jul 22, 2025
d5ac269
Add step metadata and a few tests for `Doc` steps
Kobzol Jul 22, 2025
6fecbb9
Refactor `Rustdoc`
Kobzol Jul 22, 2025
006a9bd
Fix `ToolRustc` build with `download-rustc`
Kobzol Jul 22, 2025
acb2379
Add step metadata and a simple test for codegen backends
Kobzol Jul 22, 2025
efbaa77
Port codegen backends to `RustcPrivateCompilers`
Kobzol Jul 22, 2025
3f53fba
Rename `link_compiler` to `target_compiler`
Kobzol Jul 22, 2025
7bf4a1a
Appease Clippy
Kobzol Jul 22, 2025
0b88bea
Move `dist-apple-various` from x86_64 to aarch64
shepmaster Jul 23, 2025
e497abc
Add stabilization template and revise docs
Jan 23, 2025
857f46e
Address review feedback
nikomatsakis Jan 23, 2025
7547b15
Address review feedback
jieyouxu Jun 19, 2025
64604ad
Revise content on lang feature processes
traviscross Jul 23, 2025
9c99623
Merge PR: Stabilization template, docs
traviscross Jul 25, 2025
d12ecde
constify with_exposed_provenance
RalfJung Jul 27, 2025
72927f6
Ensure correct aligement of rustc_hir::Lifetime on platforms with low…
FractalFir Jul 27, 2025
8d82365
Prepare for merging from rust-lang/rust
invalid-email-address Jul 28, 2025
645b85e
Merge ref '2b5e239c6b86' from rust-lang/rust
invalid-email-address Jul 28, 2025
466198c
Merge pull request #2519 from rust-lang/rustc-pull
tshepang Jul 28, 2025
66445e7
fix pauses
tshepang Jul 28, 2025
b707493
reword to avoid using a term used in a confusing manner, "error annot…
tshepang Jul 28, 2025
bfca77b
Merge pull request #2520 from rust-lang/tshepang/error-pattern
tshepang Jul 28, 2025
f29f073
add support for ./x check src/tools/linkchecker
pietroalbini Jul 13, 2025
c745614
bump linkchecker to edition 2024
pietroalbini Jul 13, 2025
984926e
add an argument parser to linkchecker
pietroalbini Jul 1, 2025
2b11851
Raw Pointers are Constant PatKinds too
BoxyUwU Jul 28, 2025
6693b39
add --link-targets-dir flag to linkchecker
pietroalbini Jul 1, 2025
c340233
fixed typo chunks->as_chunks
xonx4l Jul 28, 2025
68f08c5
Add `core::mem::DropGuard`
yoshuawuyts Jul 21, 2025
71920e2
fix `Atomic*::as_ptr` wording
usamoi Jul 28, 2025
7ca4d1f
coverage: Regression test for "function name is empty" bug
Zalathar Jul 29, 2025
830eec8
Rollup merge of #143883 - pietroalbini:pa-linkchecker-extra-target, r…
Zalathar Jul 29, 2025
b0af8ce
Rollup merge of #144236 - yoshuawuyts:drop-guard, r=Mark-Simulacrum
Zalathar Jul 29, 2025
7d68e7b
Rollup merge of #144303 - Kobzol:bootstrap-tool-cleanup, r=jieyouxu
Zalathar Jul 29, 2025
c992023
Rollup merge of #144367 - shepmaster:reduce-x86-macos-runner-usage, r…
Zalathar Jul 29, 2025
ca0ee6c
Rollup merge of #144539 - RalfJung:const_with_exposed_provenance, r=o…
Zalathar Jul 29, 2025
8eeef9c
Rollup merge of #144569 - tshepang:rdg-sync, r=Kobzol
Zalathar Jul 29, 2025
8ebb05f
Rollup merge of #144573 - BoxyUwU:patkind_constant_ptr_docs, r=lcnr
Zalathar Jul 29, 2025
f86e6ca
Rollup merge of #144575 - xonx4l:patch-6, r=scottmcm
Zalathar Jul 29, 2025
608e726
Rollup merge of #144578 - FractalFir:m68k_fix, r=compiler-errors
Zalathar Jul 29, 2025
e45e2a6
Rollup merge of #144582 - usamoi:docs, r=RalfJung
Zalathar Jul 29, 2025
3a81fc9
Rollup merge of #144616 - Zalathar:try-in-macro, r=jieyouxu
Zalathar Jul 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
5 changes: 5 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ impl From<Ident> for LifetimeSyntax {
/// `LifetimeSource::OutlivesBound` or `LifetimeSource::PreciseCapturing`
/// — there's no way to "elide" these lifetimes.
#[derive(Debug, Copy, Clone, HashStable_Generic)]
// Raise the aligement to at least 4 bytes - this is relied on in other parts of the compiler(for pointer tagging):
// https://github.com/rust-lang/rust/blob/ce5fdd7d42aba9a2925692e11af2bd39cf37798a/compiler/rustc_data_structures/src/tagged_ptr.rs#L163
// Removing this `repr(4)` will cause the compiler to not build on platforms like `m68k` Linux, where the aligement of u32 and usize is only 2.
// Since `repr(align)` may only raise aligement, this has no effect on platforms where the aligement is already sufficient.
#[repr(align(4))]
pub struct Lifetime {
#[stable_hasher(ignore)]
pub hir_id: HirId,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ pub enum PatKind<'tcx> {
/// * integer, bool, char or float (represented as a valtree), which will be handled by
/// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
/// much simpler.
/// * raw pointers derived from integers, other raw pointers will have already resulted in an
// error.
/// * `String`, if `string_deref_patterns` is enabled.
Constant {
value: mir::Const<'tcx>,
Expand Down
155 changes: 155 additions & 0 deletions library/core/src/mem/drop_guard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
use crate::fmt::{self, Debug};
use crate::mem::ManuallyDrop;
use crate::ops::{Deref, DerefMut};

/// Wrap a value and run a closure when dropped.
///
/// This is useful for quickly creating desructors inline.
///
/// # Examples
///
/// ```rust
/// # #![allow(unused)]
/// #![feature(drop_guard)]
///
/// use std::mem::DropGuard;
///
/// {
/// // Create a new guard around a string that will
/// // print its value when dropped.
/// let s = String::from("Chashu likes tuna");
/// let mut s = DropGuard::new(s, |s| println!("{s}"));
///
/// // Modify the string contained in the guard.
/// s.push_str("!!!");
///
/// // The guard will be dropped here, printing:
/// // "Chashu likes tuna!!!"
/// }
/// ```
#[unstable(feature = "drop_guard", issue = "144426")]
#[doc(alias = "ScopeGuard")]
#[doc(alias = "defer")]
pub struct DropGuard<T, F>
where
F: FnOnce(T),
{
inner: ManuallyDrop<T>,
f: ManuallyDrop<F>,
}

impl<T, F> DropGuard<T, F>
where
F: FnOnce(T),
{
/// Create a new instance of `DropGuard`.
///
/// # Example
///
/// ```rust
/// # #![allow(unused)]
/// #![feature(drop_guard)]
///
/// use std::mem::DropGuard;
///
/// let value = String::from("Chashu likes tuna");
/// let guard = DropGuard::new(value, |s| println!("{s}"));
/// ```
#[unstable(feature = "drop_guard", issue = "144426")]
#[must_use]
pub const fn new(inner: T, f: F) -> Self {
Self { inner: ManuallyDrop::new(inner), f: ManuallyDrop::new(f) }
}

/// Consumes the `DropGuard`, returning the wrapped value.
///
/// This will not execute the closure. This is implemented as an associated
/// function to prevent any potential conflicts with any other methods called
/// `into_inner` from the `Deref` and `DerefMut` impls.
///
/// It is typically preferred to call this function instead of `mem::forget`
/// because it will return the stored value and drop variables captured
/// by the closure instead of leaking their owned resources.
///
/// # Example
///
/// ```rust
/// # #![allow(unused)]
/// #![feature(drop_guard)]
///
/// use std::mem::DropGuard;
///
/// let value = String::from("Nori likes chicken");
/// let guard = DropGuard::new(value, |s| println!("{s}"));
/// assert_eq!(DropGuard::into_inner(guard), "Nori likes chicken");
/// ```
#[unstable(feature = "drop_guard", issue = "144426")]
#[inline]
pub fn into_inner(guard: Self) -> T {
// First we ensure that dropping the guard will not trigger
// its destructor
let mut guard = ManuallyDrop::new(guard);

// Next we manually read the stored value from the guard.
//
// SAFETY: this is safe because we've taken ownership of the guard.
let value = unsafe { ManuallyDrop::take(&mut guard.inner) };

// Finally we drop the stored closure. We do this *after* having read
// the value, so that even if the closure's `drop` function panics,
// unwinding still tries to drop the value.
//
// SAFETY: this is safe because we've taken ownership of the guard.
unsafe { ManuallyDrop::drop(&mut guard.f) };
value
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
impl<T, F> Deref for DropGuard<T, F>
where
F: FnOnce(T),
{
type Target = T;

fn deref(&self) -> &T {
&*self.inner
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
impl<T, F> DerefMut for DropGuard<T, F>
where
F: FnOnce(T),
{
fn deref_mut(&mut self) -> &mut T {
&mut *self.inner
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
impl<T, F> Drop for DropGuard<T, F>
where
F: FnOnce(T),
{
fn drop(&mut self) {
// SAFETY: `DropGuard` is in the process of being dropped.
let inner = unsafe { ManuallyDrop::take(&mut self.inner) };

// SAFETY: `DropGuard` is in the process of being dropped.
let f = unsafe { ManuallyDrop::take(&mut self.f) };

f(inner);
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
impl<T, F> Debug for DropGuard<T, F>
where
T: Debug,
F: FnOnce(T),
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
4 changes: 4 additions & 0 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ mod transmutability;
#[unstable(feature = "transmutability", issue = "99571")]
pub use transmutability::{Assume, TransmuteFrom};

mod drop_guard;
#[unstable(feature = "drop_guard", issue = "144426")]
pub use drop_guard::DropGuard;

// This one has to be a re-export (rather than wrapping the underlying intrinsic) so that we can do
// the special magic "types have equal size" check at the call site.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,10 @@ pub const fn dangling_mut<T>() -> *mut T {
#[must_use]
#[inline(always)]
#[stable(feature = "exposed_provenance", since = "1.84.0")]
#[rustc_const_unstable(feature = "const_exposed_provenance", issue = "144538")]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[allow(fuzzy_provenance_casts)] // this *is* the explicit provenance API one should use instead
pub fn with_exposed_provenance<T>(addr: usize) -> *const T {
pub const fn with_exposed_provenance<T>(addr: usize) -> *const T {
addr as *const T
}

Expand Down Expand Up @@ -1014,9 +1015,10 @@ pub fn with_exposed_provenance<T>(addr: usize) -> *const T {
#[must_use]
#[inline(always)]
#[stable(feature = "exposed_provenance", since = "1.84.0")]
#[rustc_const_unstable(feature = "const_exposed_provenance", issue = "144538")]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[allow(fuzzy_provenance_casts)] // this *is* the explicit provenance API one should use instead
pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T {
pub const fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T {
addr as *mut T
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ impl<T> [T] {
///
/// [`chunks`]: slice::chunks
/// [`rchunks_exact`]: slice::rchunks_exact
/// [`as_chunks`]: slice::chunks
/// [`as_chunks`]: slice::as_chunks
#[stable(feature = "chunks_exact", since = "1.31.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand Down
18 changes: 9 additions & 9 deletions library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,8 @@ impl AtomicBool {
/// Returning an `*mut` pointer from a shared reference to this atomic is safe because the
/// atomic types work with interior mutability. All modifications of an atomic change the value
/// through a shared reference, and can do so safely as long as they use atomic operations. Any
/// use of the returned raw pointer requires an `unsafe` block and still has to uphold the same
/// restriction in [Memory model for atomic accesses].
/// use of the returned raw pointer requires an `unsafe` block and still has to uphold the
/// requirements of the [memory model].
///
/// # Examples
///
Expand All @@ -1265,7 +1265,7 @@ impl AtomicBool {
/// # }
/// ```
///
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
/// [memory model]: self#memory-model-for-atomic-accesses
#[inline]
#[stable(feature = "atomic_as_ptr", since = "1.70.0")]
#[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")]
Expand Down Expand Up @@ -2489,8 +2489,8 @@ impl<T> AtomicPtr<T> {
/// Returning an `*mut` pointer from a shared reference to this atomic is safe because the
/// atomic types work with interior mutability. All modifications of an atomic change the value
/// through a shared reference, and can do so safely as long as they use atomic operations. Any
/// use of the returned raw pointer requires an `unsafe` block and still has to uphold the same
/// restriction in [Memory model for atomic accesses].
/// use of the returned raw pointer requires an `unsafe` block and still has to uphold the
/// requirements of the [memory model].
///
/// # Examples
///
Expand All @@ -2510,7 +2510,7 @@ impl<T> AtomicPtr<T> {
/// }
/// ```
///
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
/// [memory model]: self#memory-model-for-atomic-accesses
#[inline]
#[stable(feature = "atomic_as_ptr", since = "1.70.0")]
#[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")]
Expand Down Expand Up @@ -3623,8 +3623,8 @@ macro_rules! atomic_int {
/// Returning an `*mut` pointer from a shared reference to this atomic is safe because the
/// atomic types work with interior mutability. All modifications of an atomic change the value
/// through a shared reference, and can do so safely as long as they use atomic operations. Any
/// use of the returned raw pointer requires an `unsafe` block and still has to uphold the same
/// restriction in [Memory model for atomic accesses].
/// use of the returned raw pointer requires an `unsafe` block and still has to uphold the
/// requirements of the [memory model].
///
/// # Examples
///
Expand All @@ -3645,7 +3645,7 @@ macro_rules! atomic_int {
/// # }
/// ```
///
/// [Memory model for atomic accesses]: self#memory-model-for-atomic-accesses
/// [memory model]: self#memory-model-for-atomic-accesses
#[inline]
#[stable(feature = "atomic_as_ptr", since = "1.70.0")]
#[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")]
Expand Down
1 change: 1 addition & 0 deletions library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![feature(core_private_diy_float)]
#![feature(cstr_display)]
#![feature(dec2flt)]
#![feature(drop_guard)]
#![feature(duration_constants)]
#![feature(duration_constructors)]
#![feature(duration_constructors_lite)]
Expand Down
46 changes: 46 additions & 0 deletions library/coretests/tests/mem.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::mem::*;
use core::{array, ptr};
use std::cell::Cell;
#[cfg(panic = "unwind")]
use std::rc::Rc;

Expand Down Expand Up @@ -795,3 +796,48 @@ fn const_maybe_uninit_zeroed() {

assert_eq!(unsafe { (*UNINIT.0.cast::<[[u8; SIZE]; 1]>())[0] }, [0u8; SIZE]);
}

#[test]
fn drop_guards_only_dropped_by_closure_when_run() {
let value_drops = Cell::new(0);
let value = DropGuard::new((), |()| value_drops.set(1 + value_drops.get()));
let closure_drops = Cell::new(0);
let guard = DropGuard::new(value, |_| closure_drops.set(1 + closure_drops.get()));
assert_eq!(value_drops.get(), 0);
assert_eq!(closure_drops.get(), 0);
drop(guard);
assert_eq!(value_drops.get(), 1);
assert_eq!(closure_drops.get(), 1);
}

#[test]
fn drop_guard_into_inner() {
let dropped = Cell::new(false);
let value = DropGuard::new(42, |_| dropped.set(true));
let guard = DropGuard::new(value, |_| dropped.set(true));
let inner = DropGuard::into_inner(guard);
assert_eq!(dropped.get(), false);
assert_eq!(*inner, 42);
}

#[test]
#[cfg(panic = "unwind")]
fn drop_guard_always_drops_value_if_closure_drop_unwinds() {
// Create a value with a destructor, which we will validate ran successfully.
let mut value_was_dropped = false;
let value_with_tracked_destruction = DropGuard::new((), |_| value_was_dropped = true);

// Create a closure that will begin unwinding when dropped.
let drop_bomb = DropGuard::new((), |_| panic!());
let closure_that_panics_on_drop = move |_| {
let _drop_bomb = drop_bomb;
};

// This will run the closure, which will panic when dropped. This should
// run the destructor of the value we passed, which we validate.
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let guard = DropGuard::new(value_with_tracked_destruction, closure_that_panics_on_drop);
DropGuard::into_inner(guard);
}));
assert!(value_was_dropped);
}
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
#![feature(clone_to_uninit)]
#![feature(core_intrinsics)]
#![feature(core_io_borrowed_buf)]
#![feature(drop_guard)]
#![feature(duration_constants)]
#![feature(error_generic_member_access)]
#![feature(error_iter)]
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,9 @@ tool_check_step!(Compiletest {
allow_features: COMPILETEST_ALLOW_FEATURES,
default: false,
});

tool_check_step!(Linkchecker {
path: "src/tools/linkchecker",
mode: |_builder| Mode::ToolBootstrap,
default: false
});
Loading
Loading