Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cdd02e9

Browse files
committed
Auto merge of rust-lang#124452 - matthiaskrgr:rollup-psvo04i, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#123942 (`x vendor`) - rust-lang#124165 (add test for incremental ICE: slice-pattern-const.rs rust-lang#83085) - rust-lang#124210 (Abort a process when FD ownership is violated) - rust-lang#124242 (bootstrap: Describe build_steps modules) - rust-lang#124406 (Remove unused `[patch]` for clippy_lints) - rust-lang#124429 (bootstrap: Document `struct Builder` and its fields) - rust-lang#124447 (Unconditionally call `really_init` on GNU/Linux) r? `@ghost` `@rustbot` modify labels: rollup
2 parents aed2187 + 0b5e173 commit cdd02e9

File tree

25 files changed

+489
-32
lines changed

25 files changed

+489
-32
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,3 @@ strip = true
112112
rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
113113
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
114114
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
115-
116-
[patch."https://github.com/rust-lang/rust-clippy"]
117-
clippy_lints = { path = "src/tools/clippy/clippy_lints" }

library/core/src/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,7 @@ pub const unsafe fn typed_swap<T>(x: *mut T, y: *mut T) {
27672767
#[unstable(feature = "core_intrinsics", issue = "none")]
27682768
#[inline(always)]
27692769
#[cfg_attr(not(bootstrap), rustc_intrinsic)] // just make it a regular fn in bootstrap
2770-
pub(crate) const fn ub_checks() -> bool {
2770+
pub const fn ub_checks() -> bool {
27712771
cfg!(debug_assertions)
27722772
}
27732773

library/core/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
#![feature(str_split_inclusive_remainder)]
194194
#![feature(str_split_remainder)]
195195
#![feature(strict_provenance)]
196+
#![feature(ub_checks)]
196197
#![feature(unchecked_shifts)]
197198
#![feature(utf16_extra)]
198199
#![feature(utf16_extra_const)]
@@ -370,7 +371,8 @@ pub mod hint;
370371
pub mod intrinsics;
371372
pub mod mem;
372373
pub mod ptr;
373-
mod ub_checks;
374+
#[unstable(feature = "ub_checks", issue = "none")]
375+
pub mod ub_checks;
374376

375377
/* Core language traits */
376378

library/core/src/ub_checks.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ use crate::intrinsics::{self, const_eval_select};
4646
/// variables cannot be optimized out in MIR, an innocent-looking `let` can produce enough
4747
/// debuginfo to have a measurable compile-time impact on debug builds.
4848
#[allow_internal_unstable(const_ub_checks)] // permit this to be called in stably-const fn
49+
#[macro_export]
50+
#[unstable(feature = "ub_checks", issue = "none")]
4951
macro_rules! assert_unsafe_precondition {
5052
($kind:ident, $message:expr, ($($name:ident:$ty:ty = $arg:expr),*$(,)?) => $e:expr $(,)?) => {
5153
{
@@ -75,11 +77,13 @@ macro_rules! assert_unsafe_precondition {
7577
}
7678
};
7779
}
78-
pub(crate) use assert_unsafe_precondition;
80+
#[unstable(feature = "ub_checks", issue = "none")]
81+
pub use assert_unsafe_precondition;
7982

8083
/// Checking library UB is always enabled when UB-checking is done
8184
/// (and we use a reexport so that there is no unnecessary wrapper function).
82-
pub(crate) use intrinsics::ub_checks as check_library_ub;
85+
#[unstable(feature = "ub_checks", issue = "none")]
86+
pub use intrinsics::ub_checks as check_library_ub;
8387

8488
/// Determines whether we should check for language UB.
8589
///

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
#![feature(str_internals)]
357357
#![feature(strict_provenance)]
358358
#![feature(strict_provenance_atomic_ptr)]
359+
#![feature(ub_checks)]
359360
// tidy-alphabetical-end
360361
//
361362
// Library features (alloc):

library/std/src/os/fd/owned.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ impl Drop for OwnedFd {
176176
// something like EINTR), we might close another valid file descriptor
177177
// opened after we closed ours.
178178
#[cfg(not(target_os = "hermit"))]
179-
let _ = libc::close(self.fd);
179+
{
180+
crate::sys::fs::debug_assert_fd_is_open(self.fd);
181+
let _ = libc::close(self.fd);
182+
}
180183
#[cfg(target_os = "hermit")]
181184
let _ = hermit_abi::close(self.fd);
182185
}

library/std/src/sys/pal/unix/args.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ mod imp {
9898
}
9999

100100
#[inline(always)]
101-
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
102-
// On Linux-GNU, we rely on `ARGV_INIT_ARRAY` below to initialize
103-
// `ARGC` and `ARGV`. But in Miri that does not actually happen so we
104-
// still initialize here.
105-
#[cfg(any(miri, not(all(target_os = "linux", target_env = "gnu"))))]
106-
really_init(_argc, _argv);
101+
pub unsafe fn init(argc: isize, argv: *const *const u8) {
102+
// on GNU/Linux if we are main then we will init argv and argc twice, it "duplicates work"
103+
// BUT edge-cases are real: only using .init_array can break most emulators, dlopen, etc.
104+
really_init(argc, argv);
107105
}
108106

109107
/// glibc passes argc, argv, and envp to functions in .init_array, as a non-standard extension.

library/std/src/sys/pal/unix/fs.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,40 @@ impl Iterator for ReadDir {
864864
}
865865
}
866866

867+
/// Aborts the process if a file desceriptor is not open, if debug asserts are enabled
868+
///
869+
/// Many IO syscalls can't be fully trusted about EBADF error codes because those
870+
/// might get bubbled up from a remote FUSE server rather than the file descriptor
871+
/// in the current process being invalid.
872+
///
873+
/// So we check file flags instead which live on the file descriptor and not the underlying file.
874+
/// The downside is that it costs an extra syscall, so we only do it for debug.
875+
#[inline]
876+
pub(crate) fn debug_assert_fd_is_open(fd: RawFd) {
877+
use crate::sys::os::errno;
878+
879+
// this is similar to assert_unsafe_precondition!() but it doesn't require const
880+
if core::ub_checks::check_library_ub() {
881+
if unsafe { libc::fcntl(fd, libc::F_GETFD) } == -1 && errno() == libc::EBADF {
882+
rtabort!("IO Safety violation: owned file descriptor already closed");
883+
}
884+
}
885+
}
886+
867887
impl Drop for Dir {
868888
fn drop(&mut self) {
889+
// dirfd isn't supported everywhere
890+
#[cfg(not(any(
891+
miri,
892+
target_os = "redox",
893+
target_os = "nto",
894+
target_os = "vita",
895+
target_os = "hurd",
896+
)))]
897+
{
898+
let fd = unsafe { libc::dirfd(self.0) };
899+
debug_assert_fd_is_open(fd);
900+
}
869901
let r = unsafe { libc::closedir(self.0) };
870902
assert!(
871903
r == 0 || crate::io::Error::last_os_error().is_interrupted(),

src/bootstrap/bootstrap.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,8 @@ def check_vendored_status(self):
10351035
if self.use_vendored_sources:
10361036
vendor_dir = os.path.join(self.rust_root, 'vendor')
10371037
if not os.path.exists(vendor_dir):
1038-
sync_dirs = "--sync ./src/tools/cargo/Cargo.toml " \
1039-
"--sync ./src/tools/rust-analyzer/Cargo.toml " \
1040-
"--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
1041-
"--sync ./compiler/rustc_codegen_gcc/Cargo.toml " \
1042-
"--sync ./src/bootstrap/Cargo.toml "
10431038
eprint('ERROR: vendoring required, but vendor directory does not exist.')
1044-
eprint(' Run `cargo vendor {}` to initialize the '
1045-
'vendor directory.'.format(sync_dirs))
1039+
eprint(' Run `x.py vendor` to initialize the vendor directory.')
10461040
eprint(' Alternatively, use the pre-vendored `rustc-src` dist component.')
10471041
eprint(' To get a stable/beta/nightly version, download it from: ')
10481042
eprint(' '

src/bootstrap/src/core/build_steps/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implementation of `make clean` in rustbuild.
1+
//! `./x.py clean`
22
//!
33
//! Responsible for cleaning out a build directory of all old and stale
44
//! artifacts to prepare for a fresh build. Currently doesn't remove the

0 commit comments

Comments
 (0)