Skip to content

Commit 43ca9d1

Browse files
committed
Auto merge of rust-lang#136747 - matthiaskrgr:rollup-qfiiv4n, r=matthiaskrgr
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
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

Lines changed: 23 additions & 6 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 24 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)