Skip to content

Commit

Permalink
Auto merge of rust-lang#136747 - matthiaskrgr:rollup-qfiiv4n, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#135696 (std: move `io` module out of `pal`, get rid of `sys_common::io`)
 - rust-lang#136099 (Optimize `Rc::<str>::default()` implementation)
 - rust-lang#136200 (Generate correct terminate block under Wasm EH)
 - rust-lang#136626 (create `initial_rustdoc` field in `Build`)
 - rust-lang#136657 (Make empty-line-after an early clippy lint)
 - rust-lang#136679 (ci: Use largedisk for loongarch)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 8, 2025
2 parents 73bf794 + 45771e4 commit 43ca9d1
Show file tree
Hide file tree
Showing 64 changed files with 857 additions and 802 deletions.
29 changes: 23 additions & 6 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,15 +1708,32 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let mut cs_bx = Bx::build(self.cx, llbb);
let cs = cs_bx.catch_switch(None, None, &[cp_llbb]);

// The "null" here is actually a RTTI type descriptor for the
// C++ personality function, but `catch (...)` has no type so
// it's null. The 64 here is actually a bitfield which
// represents that this is a catch-all block.
bx = Bx::build(self.cx, cp_llbb);
let null =
bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
let sixty_four = bx.const_i32(64);
funclet = Some(bx.catch_pad(cs, &[null, sixty_four, null]));

// The `null` in first argument here is actually a RTTI type
// descriptor for the C++ personality function, but `catch (...)`
// has no type so it's null.
let args = if base::wants_msvc_seh(self.cx.sess()) {
// This bitmask is a single `HT_IsStdDotDot` flag, which
// represents that this is a C++-style `catch (...)` block that
// only captures programmatic exceptions, not all SEH
// exceptions. The second `null` points to a non-existent
// `alloca` instruction, which an LLVM pass would inline into
// the initial SEH frame allocation.
let adjectives = bx.const_i32(0x40);
&[null, adjectives, null] as &[_]
} else {
// Specifying more arguments than necessary usually doesn't
// hurt, but the `WasmEHPrepare` LLVM pass does not recognize
// anything other than a single `null` as a `catch (...)` block,
// leading to problems down the line during instruction
// selection.
&[null] as &[_]
};

funclet = Some(bx.catch_pad(cs, args));
} else {
llbb = Bx::append_block(self.cx, self.llfn, "terminate");
bx = Bx::build(self.cx, llbb);
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast>
}
}
ast_visit::walk_assoc_item(cx, item, ctxt);
match ctxt {
ast_visit::AssocCtxt::Trait => {
lint_callback!(cx, check_trait_item_post, item);
}
ast_visit::AssocCtxt::Impl => {
lint_callback!(cx, check_impl_item_post, item);
}
}
});
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ macro_rules! early_lint_methods {
c: rustc_span::Span,
d_: rustc_ast::NodeId);
fn check_trait_item(a: &rustc_ast::AssocItem);
fn check_trait_item_post(a: &rustc_ast::AssocItem);
fn check_impl_item(a: &rustc_ast::AssocItem);
fn check_impl_item_post(a: &rustc_ast::AssocItem);
fn check_variant(a: &rustc_ast::Variant);
fn check_attribute(a: &rustc_ast::Attribute);
fn check_attributes(a: &[rustc_ast::Attribute]);
Expand Down
5 changes: 3 additions & 2 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,9 @@ impl Default for Rc<CStr> {
/// This may or may not share an allocation with other Rcs on the same thread.
#[inline]
fn default() -> Self {
let c_str: &CStr = Default::default();
Rc::from(c_str)
let rc = Rc::<[u8]>::from(*b"\0");
// `[u8]` has the same layout as `CStr`, and it is `NUL` terminated.
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) }
}
}

Expand Down
4 changes: 3 additions & 1 deletion library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,9 @@ impl Default for Rc<str> {
/// This may or may not share an allocation with other Rcs on the same thread.
#[inline]
fn default() -> Self {
Rc::from("")
let rc = Rc::<[u8]>::default();
// `[u8]` has the same layout as `str`.
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const str) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::os::unix::fs::symlink as junction_point;
use crate::os::windows::fs::{OpenOptionsExt, junction_point, symlink_dir, symlink_file};
use crate::path::Path;
use crate::sync::Arc;
use crate::sys_common::io::test::{TempDir, tmpdir};
use crate::test_helpers::{TempDir, tmpdir};
use crate::time::{Duration, Instant, SystemTime};
use crate::{env, str, thread};

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub mod prelude;
mod stdio;
mod util;

const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
const DEFAULT_BUF_SIZE: usize = crate::sys::io::DEFAULT_BUF_SIZE;

pub(crate) use stdio::cleanup;

Expand Down
25 changes: 1 addition & 24 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,27 +739,4 @@ mod sealed {

#[cfg(test)]
#[allow(dead_code)] // Not used in all configurations.
pub(crate) mod test_helpers {
/// Test-only replacement for `rand::thread_rng()`, which is unusable for
/// us, as we want to allow running stdlib tests on tier-3 targets which may
/// not have `getrandom` support.
///
/// Does a bit of a song and dance to ensure that the seed is different on
/// each call (as some tests sadly rely on this), but doesn't try that hard.
///
/// This is duplicated in the `core`, `alloc` test suites (as well as
/// `std`'s integration tests), but figuring out a mechanism to share these
/// seems far more painful than copy-pasting a 7 line function a couple
/// times, given that even under a perma-unstable feature, I don't think we
/// want to expose types from `rand` from `std`.
#[track_caller]
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
use core::hash::{BuildHasher, Hash, Hasher};
let mut hasher = crate::hash::RandomState::new().build_hasher();
core::panic::Location::caller().hash(&mut hasher);
let hc64 = hasher.finish();
let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>();
let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap();
rand::SeedableRng::from_seed(seed)
}
}
pub(crate) mod test_helpers;
4 changes: 2 additions & 2 deletions library/std/src/os/unix/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
#[test]
fn read_vectored_at() {
let msg = b"preadv is working!";
let dir = crate::sys_common::io::test::tmpdir();
let dir = crate::test_helpers::tmpdir();

let filename = dir.join("preadv.txt");
{
Expand Down Expand Up @@ -31,7 +31,7 @@ fn read_vectored_at() {
#[test]
fn write_vectored_at() {
let msg = b"pwritev is not working!";
let dir = crate::sys_common::io::test::tmpdir();
let dir = crate::test_helpers::tmpdir();

let filename = dir.join("preadv.txt");
{
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/unix/net/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::os::android::net::{SocketAddrExt, UnixSocketExt};
use crate::os::linux::net::{SocketAddrExt, UnixSocketExt};
#[cfg(any(target_os = "android", target_os = "linux"))]
use crate::os::unix::io::AsRawFd;
use crate::sys_common::io::test::tmpdir;
use crate::test_helpers::tmpdir;
use crate::thread;
use crate::time::Duration;

Expand Down
4 changes: 2 additions & 2 deletions library/std/src/process/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn debug_print() {
#[test]
#[cfg(windows)]
fn run_bat_script() {
let tempdir = crate::sys_common::io::test::tmpdir();
let tempdir = crate::test_helpers::tmpdir();
let script_path = tempdir.join("hello.cmd");

crate::fs::write(&script_path, "@echo Hello, %~1!").unwrap();
Expand All @@ -568,7 +568,7 @@ fn run_bat_script() {
#[test]
#[cfg(windows)]
fn run_canonical_bat_script() {
let tempdir = crate::sys_common::io::test::tmpdir();
let tempdir = crate::test_helpers::tmpdir();
let script_path = tempdir.join("hello.cmd");

crate::fs::write(&script_path, "@echo Hello, %~1!").unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use hermit_abi::{c_void, iovec};
#[cfg(target_os = "hermit")]
use hermit_abi::iovec;
#[cfg(target_family = "unix")]
use libc::iovec;

use crate::ffi::c_void;
use crate::marker::PhantomData;
use crate::os::hermit::io::{AsFd, AsRawFd};
use crate::slice;
#[cfg(target_os = "solid_asp3")]
use crate::sys::pal::abi::sockets::iovec;

#[derive(Copy, Clone)]
#[repr(transparent)]
Expand Down Expand Up @@ -80,8 +85,3 @@ impl<'a> IoSliceMut<'a> {
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
}
}

pub fn is_terminal(fd: &impl AsFd) -> bool {
let fd = fd.as_fd();
hermit_abi::isatty(fd.as_raw_fd())
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,3 @@ impl<'a> IoSliceMut<'a> {
self.0
}
}

pub fn is_terminal<T>(_: &T) -> bool {
false
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#![forbid(unsafe_op_in_unsafe_fn)]

use crate::marker::PhantomData;
use crate::os::fd::{AsFd, AsRawFd};
use crate::slice;

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -77,8 +74,3 @@ impl<'a> IoSliceMut<'a> {
unsafe { slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.buf_len) }
}
}

pub fn is_terminal(fd: &impl AsFd) -> bool {
let fd = fd.as_fd();
unsafe { libc::isatty(fd.as_raw_fd()) != 0 }
}
Original file line number Diff line number Diff line change
@@ -1,86 +1,82 @@
use libc::c_void;

use super::abi::sockets::iovec;
use crate::marker::PhantomData;
use crate::slice;
use crate::sys::c;

#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct IoSlice<'a> {
vec: iovec,
vec: c::WSABUF,
_p: PhantomData<&'a [u8]>,
}

impl<'a> IoSlice<'a> {
#[inline]
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
assert!(buf.len() <= u32::MAX as usize);
IoSlice {
vec: iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c_void, iov_len: buf.len() },
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_ptr() as *mut u8 },
_p: PhantomData,
}
}

#[inline]
pub fn advance(&mut self, n: usize) {
if self.vec.iov_len < n {
if (self.vec.len as usize) < n {
panic!("advancing IoSlice beyond its length");
}

unsafe {
self.vec.iov_len -= n;
self.vec.iov_base = self.vec.iov_base.add(n);
self.vec.len -= n as u32;
self.vec.buf = self.vec.buf.add(n);
}
}

#[inline]
pub const fn as_slice(&self) -> &'a [u8] {
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) }
unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) }
}
}

#[repr(transparent)]
pub struct IoSliceMut<'a> {
vec: iovec,
vec: c::WSABUF,
_p: PhantomData<&'a mut [u8]>,
}

impl<'a> IoSliceMut<'a> {
#[inline]
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> {
assert!(buf.len() <= u32::MAX as usize);
IoSliceMut {
vec: iovec { iov_base: buf.as_mut_ptr() as *mut c_void, iov_len: buf.len() },
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_mut_ptr() },
_p: PhantomData,
}
}

#[inline]
pub fn advance(&mut self, n: usize) {
if self.vec.iov_len < n {
if (self.vec.len as usize) < n {
panic!("advancing IoSliceMut beyond its length");
}

unsafe {
self.vec.iov_len -= n;
self.vec.iov_base = self.vec.iov_base.add(n);
self.vec.len -= n as u32;
self.vec.buf = self.vec.buf.add(n);
}
}

#[inline]
pub fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) }
unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) }
}

#[inline]
pub const fn into_slice(self) -> &'a mut [u8] {
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) }
}

#[inline]
pub fn as_mut_slice(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) }
}
}

pub fn is_terminal<T>(_: &T) -> bool {
false
}
6 changes: 6 additions & 0 deletions library/std/src/sys/io/is_terminal/hermit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::os::fd::{AsFd, AsRawFd};

pub fn is_terminal(fd: &impl AsFd) -> bool {
let fd = fd.as_fd();
hermit_abi::isatty(fd.as_raw_fd())
}
6 changes: 6 additions & 0 deletions library/std/src/sys/io/is_terminal/isatty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::os::fd::{AsFd, AsRawFd};

pub fn is_terminal(fd: &impl AsFd) -> bool {
let fd = fd.as_fd();
unsafe { libc::isatty(fd.as_raw_fd()) != 0 }
}
3 changes: 3 additions & 0 deletions library/std/src/sys/io/is_terminal/unsupported.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn is_terminal<T>(_: &T) -> bool {
false
}
Loading

0 comments on commit 43ca9d1

Please sign in to comment.