Skip to content

Commit 88057ce

Browse files
authored
Merge pull request #4615 from rust-lang/rustup-2025-10-03
Automatic Rustup
2 parents 0173266 + 10879b0 commit 88057ce

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
42b384ec0dfcd528d99a4db0a337d9188a9eecaa
1+
3b8665c5ab3aeced9b01672404c3764583e722ca

tests/pass/static_align.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#![feature(static_align)]
2+
#![deny(non_upper_case_globals)]
3+
4+
use std::cell::Cell;
25

36
// When a static uses `align(N)`, its address should be a multiple of `N`.
47

@@ -8,7 +11,64 @@ static FOO: u64 = 0;
811
#[rustc_align_static(512)]
912
static BAR: u64 = 0;
1013

14+
struct HasDrop(*const HasDrop);
15+
16+
impl Drop for HasDrop {
17+
fn drop(&mut self) {
18+
assert_eq!(core::ptr::from_mut(self).cast_const(), self.0);
19+
}
20+
}
21+
22+
thread_local! {
23+
#[rustc_align_static(4096)]
24+
static LOCAL: u64 = 0;
25+
26+
#[allow(unused_mut, reason = "test attribute handling")]
27+
#[cfg_attr(true, rustc_align_static(4096))]
28+
static CONST_LOCAL: u64 = const { 0 };
29+
30+
#[cfg_attr(any(true), cfg_attr(true, rustc_align_static(4096)))]
31+
#[allow(unused_mut, reason = "test attribute handling")]
32+
static HASDROP_LOCAL: Cell<HasDrop> = Cell::new(HasDrop(core::ptr::null()));
33+
34+
/// I love doc comments.
35+
#[allow(unused_mut, reason = "test attribute handling")]
36+
#[cfg_attr(all(),
37+
cfg_attr(any(true),
38+
cfg_attr(true, rustc_align_static(4096))))]
39+
#[allow(unused_mut, reason = "test attribute handling")]
40+
/// I love doc comments.
41+
static HASDROP_CONST_LOCAL: Cell<HasDrop> = const { Cell::new(HasDrop(core::ptr::null())) };
42+
43+
#[cfg_attr(true,)]
44+
#[cfg_attr(false,)]
45+
#[cfg_attr(
46+
true,
47+
rustc_align_static(32),
48+
cfg_attr(true, allow(non_upper_case_globals, reason = "test attribute handling")),
49+
cfg_attr(false,)
50+
)]
51+
#[cfg_attr(false, rustc_align_static(0))]
52+
static more_attr_testing: u64 = 0;
53+
}
54+
55+
fn thread_local_ptr<T>(key: &'static std::thread::LocalKey<T>) -> *const T {
56+
key.with(|local| core::ptr::from_ref::<T>(local))
57+
}
58+
1159
fn main() {
1260
assert!(core::ptr::from_ref(&FOO).addr().is_multiple_of(256));
1361
assert!(core::ptr::from_ref(&BAR).addr().is_multiple_of(512));
62+
63+
assert!(thread_local_ptr(&LOCAL).addr().is_multiple_of(4096));
64+
assert!(thread_local_ptr(&CONST_LOCAL).addr().is_multiple_of(4096));
65+
assert!(thread_local_ptr(&HASDROP_LOCAL).addr().is_multiple_of(4096));
66+
assert!(thread_local_ptr(&HASDROP_CONST_LOCAL).addr().is_multiple_of(4096));
67+
assert!(thread_local_ptr(&more_attr_testing).addr().is_multiple_of(32));
68+
69+
// Test that address (and therefore alignment) is maintained during drop
70+
let hasdrop_ptr = thread_local_ptr(&HASDROP_LOCAL);
71+
core::mem::forget(HASDROP_LOCAL.replace(HasDrop(hasdrop_ptr.cast())));
72+
let hasdrop_const_ptr = thread_local_ptr(&HASDROP_CONST_LOCAL);
73+
core::mem::forget(HASDROP_CONST_LOCAL.replace(HasDrop(hasdrop_const_ptr.cast())));
1474
}

tests/pass/thread_local-panic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
thread_local! {
2+
static LOCAL: u64 = panic!();
3+
4+
}
5+
6+
fn main() {
7+
let _ = std::panic::catch_unwind(|| LOCAL.with(|_| {}));
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
thread 'main' ($TID) panicked at tests/pass/thread_local-panic.rs:LL:CC:
3+
explicit panic
4+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
5+
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

0 commit comments

Comments
 (0)