Skip to content

Commit 43ca9d1

Browse files
committed
Auto merge of #136747 - matthiaskrgr:rollup-qfiiv4n, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #135696 (std: move `io` module out of `pal`, get rid of `sys_common::io`) - #136099 (Optimize `Rc::<str>::default()` implementation) - #136200 (Generate correct terminate block under Wasm EH) - #136626 (create `initial_rustdoc` field in `Build`) - #136657 (Make empty-line-after an early clippy lint) - #136679 (ci: Use largedisk for loongarch) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 73bf794 + 45771e4 commit 43ca9d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+857
-802
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -1708,15 +1708,32 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
17081708
let mut cs_bx = Bx::build(self.cx, llbb);
17091709
let cs = cs_bx.catch_switch(None, None, &[cp_llbb]);
17101710

1711-
// The "null" here is actually a RTTI type descriptor for the
1712-
// C++ personality function, but `catch (...)` has no type so
1713-
// it's null. The 64 here is actually a bitfield which
1714-
// represents that this is a catch-all block.
17151711
bx = Bx::build(self.cx, cp_llbb);
17161712
let null =
17171713
bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space));
1718-
let sixty_four = bx.const_i32(64);
1719-
funclet = Some(bx.catch_pad(cs, &[null, sixty_four, null]));
1714+
1715+
// The `null` in first argument here is actually a RTTI type
1716+
// descriptor for the C++ personality function, but `catch (...)`
1717+
// has no type so it's null.
1718+
let args = if base::wants_msvc_seh(self.cx.sess()) {
1719+
// This bitmask is a single `HT_IsStdDotDot` flag, which
1720+
// represents that this is a C++-style `catch (...)` block that
1721+
// only captures programmatic exceptions, not all SEH
1722+
// exceptions. The second `null` points to a non-existent
1723+
// `alloca` instruction, which an LLVM pass would inline into
1724+
// the initial SEH frame allocation.
1725+
let adjectives = bx.const_i32(0x40);
1726+
&[null, adjectives, null] as &[_]
1727+
} else {
1728+
// Specifying more arguments than necessary usually doesn't
1729+
// hurt, but the `WasmEHPrepare` LLVM pass does not recognize
1730+
// anything other than a single `null` as a `catch (...)` block,
1731+
// leading to problems down the line during instruction
1732+
// selection.
1733+
&[null] as &[_]
1734+
};
1735+
1736+
funclet = Some(bx.catch_pad(cs, args));
17201737
} else {
17211738
llbb = Bx::append_block(self.cx, self.llfn, "terminate");
17221739
bx = Bx::build(self.cx, llbb);

compiler/rustc_lint/src/early.rs

+8
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast>
246246
}
247247
}
248248
ast_visit::walk_assoc_item(cx, item, ctxt);
249+
match ctxt {
250+
ast_visit::AssocCtxt::Trait => {
251+
lint_callback!(cx, check_trait_item_post, item);
252+
}
253+
ast_visit::AssocCtxt::Impl => {
254+
lint_callback!(cx, check_impl_item_post, item);
255+
}
256+
}
249257
});
250258
}
251259

compiler/rustc_lint/src/passes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ macro_rules! early_lint_methods {
162162
c: rustc_span::Span,
163163
d_: rustc_ast::NodeId);
164164
fn check_trait_item(a: &rustc_ast::AssocItem);
165+
fn check_trait_item_post(a: &rustc_ast::AssocItem);
165166
fn check_impl_item(a: &rustc_ast::AssocItem);
167+
fn check_impl_item_post(a: &rustc_ast::AssocItem);
166168
fn check_variant(a: &rustc_ast::Variant);
167169
fn check_attribute(a: &rustc_ast::Attribute);
168170
fn check_attributes(a: &[rustc_ast::Attribute]);

library/alloc/src/ffi/c_str.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,9 @@ impl Default for Rc<CStr> {
965965
/// This may or may not share an allocation with other Rcs on the same thread.
966966
#[inline]
967967
fn default() -> Self {
968-
let c_str: &CStr = Default::default();
969-
Rc::from(c_str)
968+
let rc = Rc::<[u8]>::from(*b"\0");
969+
// `[u8]` has the same layout as `CStr`, and it is `NUL` terminated.
970+
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) }
970971
}
971972
}
972973

library/alloc/src/rc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,9 @@ impl Default for Rc<str> {
23692369
/// This may or may not share an allocation with other Rcs on the same thread.
23702370
#[inline]
23712371
fn default() -> Self {
2372-
Rc::from("")
2372+
let rc = Rc::<[u8]>::default();
2373+
// `[u8]` has the same layout as `str`.
2374+
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const str) }
23732375
}
23742376
}
23752377

library/std/src/fs/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::os::unix::fs::symlink as junction_point;
1414
use crate::os::windows::fs::{OpenOptionsExt, junction_point, symlink_dir, symlink_file};
1515
use crate::path::Path;
1616
use crate::sync::Arc;
17-
use crate::sys_common::io::test::{TempDir, tmpdir};
17+
use crate::test_helpers::{TempDir, tmpdir};
1818
use crate::time::{Duration, Instant, SystemTime};
1919
use crate::{env, str, thread};
2020

library/std/src/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub mod prelude;
344344
mod stdio;
345345
mod util;
346346

347-
const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
347+
const DEFAULT_BUF_SIZE: usize = crate::sys::io::DEFAULT_BUF_SIZE;
348348

349349
pub(crate) use stdio::cleanup;
350350

library/std/src/lib.rs

+1-24
Original file line numberDiff line numberDiff line change
@@ -739,27 +739,4 @@ mod sealed {
739739

740740
#[cfg(test)]
741741
#[allow(dead_code)] // Not used in all configurations.
742-
pub(crate) mod test_helpers {
743-
/// Test-only replacement for `rand::thread_rng()`, which is unusable for
744-
/// us, as we want to allow running stdlib tests on tier-3 targets which may
745-
/// not have `getrandom` support.
746-
///
747-
/// Does a bit of a song and dance to ensure that the seed is different on
748-
/// each call (as some tests sadly rely on this), but doesn't try that hard.
749-
///
750-
/// This is duplicated in the `core`, `alloc` test suites (as well as
751-
/// `std`'s integration tests), but figuring out a mechanism to share these
752-
/// seems far more painful than copy-pasting a 7 line function a couple
753-
/// times, given that even under a perma-unstable feature, I don't think we
754-
/// want to expose types from `rand` from `std`.
755-
#[track_caller]
756-
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
757-
use core::hash::{BuildHasher, Hash, Hasher};
758-
let mut hasher = crate::hash::RandomState::new().build_hasher();
759-
core::panic::Location::caller().hash(&mut hasher);
760-
let hc64 = hasher.finish();
761-
let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>();
762-
let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap();
763-
rand::SeedableRng::from_seed(seed)
764-
}
765-
}
742+
pub(crate) mod test_helpers;

library/std/src/os/unix/fs/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
#[test]
44
fn read_vectored_at() {
55
let msg = b"preadv is working!";
6-
let dir = crate::sys_common::io::test::tmpdir();
6+
let dir = crate::test_helpers::tmpdir();
77

88
let filename = dir.join("preadv.txt");
99
{
@@ -31,7 +31,7 @@ fn read_vectored_at() {
3131
#[test]
3232
fn write_vectored_at() {
3333
let msg = b"pwritev is not working!";
34-
let dir = crate::sys_common::io::test::tmpdir();
34+
let dir = crate::test_helpers::tmpdir();
3535

3636
let filename = dir.join("preadv.txt");
3737
{

library/std/src/os/unix/net/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::os::android::net::{SocketAddrExt, UnixSocketExt};
77
use crate::os::linux::net::{SocketAddrExt, UnixSocketExt};
88
#[cfg(any(target_os = "android", target_os = "linux"))]
99
use crate::os::unix::io::AsRawFd;
10-
use crate::sys_common::io::test::tmpdir;
10+
use crate::test_helpers::tmpdir;
1111
use crate::thread;
1212
use crate::time::Duration;
1313

library/std/src/process/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ fn debug_print() {
549549
#[test]
550550
#[cfg(windows)]
551551
fn run_bat_script() {
552-
let tempdir = crate::sys_common::io::test::tmpdir();
552+
let tempdir = crate::test_helpers::tmpdir();
553553
let script_path = tempdir.join("hello.cmd");
554554

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

574574
crate::fs::write(&script_path, "@echo Hello, %~1!").unwrap();

library/std/src/sys/pal/hermit/io.rs library/std/src/sys/io/io_slice/iovec.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
use hermit_abi::{c_void, iovec};
1+
#[cfg(target_os = "hermit")]
2+
use hermit_abi::iovec;
3+
#[cfg(target_family = "unix")]
4+
use libc::iovec;
25

6+
use crate::ffi::c_void;
37
use crate::marker::PhantomData;
4-
use crate::os::hermit::io::{AsFd, AsRawFd};
58
use crate::slice;
9+
#[cfg(target_os = "solid_asp3")]
10+
use crate::sys::pal::abi::sockets::iovec;
611

712
#[derive(Copy, Clone)]
813
#[repr(transparent)]
@@ -80,8 +85,3 @@ impl<'a> IoSliceMut<'a> {
8085
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
8186
}
8287
}
83-
84-
pub fn is_terminal(fd: &impl AsFd) -> bool {
85-
let fd = fd.as_fd();
86-
hermit_abi::isatty(fd.as_raw_fd())
87-
}

library/std/src/sys/pal/unsupported/io.rs library/std/src/sys/io/io_slice/unsupported.rs

-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,3 @@ impl<'a> IoSliceMut<'a> {
5050
self.0
5151
}
5252
}
53-
54-
pub fn is_terminal<T>(_: &T) -> bool {
55-
false
56-
}

library/std/src/sys/pal/wasi/io.rs library/std/src/sys/io/io_slice/wasi.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![forbid(unsafe_op_in_unsafe_fn)]
2-
31
use crate::marker::PhantomData;
4-
use crate::os::fd::{AsFd, AsRawFd};
52
use crate::slice;
63

74
#[derive(Copy, Clone)]
@@ -77,8 +74,3 @@ impl<'a> IoSliceMut<'a> {
7774
unsafe { slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.buf_len) }
7875
}
7976
}
80-
81-
pub fn is_terminal(fd: &impl AsFd) -> bool {
82-
let fd = fd.as_fd();
83-
unsafe { libc::isatty(fd.as_raw_fd()) != 0 }
84-
}
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,82 @@
1-
use libc::c_void;
2-
3-
use super::abi::sockets::iovec;
41
use crate::marker::PhantomData;
52
use crate::slice;
3+
use crate::sys::c;
64

75
#[derive(Copy, Clone)]
86
#[repr(transparent)]
97
pub struct IoSlice<'a> {
10-
vec: iovec,
8+
vec: c::WSABUF,
119
_p: PhantomData<&'a [u8]>,
1210
}
1311

1412
impl<'a> IoSlice<'a> {
1513
#[inline]
1614
pub fn new(buf: &'a [u8]) -> IoSlice<'a> {
15+
assert!(buf.len() <= u32::MAX as usize);
1716
IoSlice {
18-
vec: iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c_void, iov_len: buf.len() },
17+
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_ptr() as *mut u8 },
1918
_p: PhantomData,
2019
}
2120
}
2221

2322
#[inline]
2423
pub fn advance(&mut self, n: usize) {
25-
if self.vec.iov_len < n {
24+
if (self.vec.len as usize) < n {
2625
panic!("advancing IoSlice beyond its length");
2726
}
2827

2928
unsafe {
30-
self.vec.iov_len -= n;
31-
self.vec.iov_base = self.vec.iov_base.add(n);
29+
self.vec.len -= n as u32;
30+
self.vec.buf = self.vec.buf.add(n);
3231
}
3332
}
3433

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

4140
#[repr(transparent)]
4241
pub struct IoSliceMut<'a> {
43-
vec: iovec,
42+
vec: c::WSABUF,
4443
_p: PhantomData<&'a mut [u8]>,
4544
}
4645

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

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

6262
unsafe {
63-
self.vec.iov_len -= n;
64-
self.vec.iov_base = self.vec.iov_base.add(n);
63+
self.vec.len -= n as u32;
64+
self.vec.buf = self.vec.buf.add(n);
6565
}
6666
}
6767

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

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

7878
#[inline]
7979
pub fn as_mut_slice(&mut self) -> &mut [u8] {
80-
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) }
80+
unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) }
8181
}
8282
}
83-
84-
pub fn is_terminal<T>(_: &T) -> bool {
85-
false
86-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use crate::os::fd::{AsFd, AsRawFd};
2+
3+
pub fn is_terminal(fd: &impl AsFd) -> bool {
4+
let fd = fd.as_fd();
5+
hermit_abi::isatty(fd.as_raw_fd())
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use crate::os::fd::{AsFd, AsRawFd};
2+
3+
pub fn is_terminal(fd: &impl AsFd) -> bool {
4+
let fd = fd.as_fd();
5+
unsafe { libc::isatty(fd.as_raw_fd()) != 0 }
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn is_terminal<T>(_: &T) -> bool {
2+
false
3+
}

0 commit comments

Comments
 (0)