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

Commit 67512de

Browse files
committed
Auto merge of rust-lang#132468 - cuviper:beta-next, r=cuviper
[beta] backports - Bump libc to 0.2.161 rust-lang#131823 - Avoid use imports in `thread_local_inner!` rust-lang#131866 - Mark `simplify_aggregate_to_copy` mir-opt as unsound rust-lang#132356 r? cuviper
2 parents f41c7ed + 0f95b22 commit 67512de

19 files changed

+245
-69
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10791079
}
10801080
}
10811081

1082-
if let AggregateTy::Def(_, _) = ty
1082+
// unsound: https://github.com/rust-lang/rust/issues/132353
1083+
if tcx.sess.opts.unstable_opts.unsound_mir_opts
1084+
&& let AggregateTy::Def(_, _) = ty
10831085
&& let Some(value) =
10841086
self.simplify_aggregate_to_copy(rvalue, location, &fields, variant_index)
10851087
{

library/Cargo.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is automatically @generated by Cargo.
22
# It is not intended for manual editing.
3-
version = 3
3+
version = 4
44

55
[[package]]
66
name = "addr2line"
@@ -158,9 +158,9 @@ dependencies = [
158158

159159
[[package]]
160160
name = "libc"
161-
version = "0.2.159"
161+
version = "0.2.161"
162162
source = "registry+https://github.com/rust-lang/crates.io-index"
163-
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
163+
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
164164
dependencies = [
165165
"rustc-std-workspace-core",
166166
]

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
3939
addr2line = { version = "0.22.0", optional = true, default-features = false }
4040

4141
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
42-
libc = { version = "0.2.156", default-features = false, features = [
42+
libc = { version = "0.2.161", default-features = false, features = [
4343
'rustc-dep-of-std',
4444
], public = true }
4545

library/std/src/sys/thread_local/native/mod.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,21 @@ pub use lazy::Storage as LazyStorage;
4949
#[unstable(feature = "thread_local_internals", issue = "none")]
5050
#[rustc_macro_transparency = "semitransparent"]
5151
pub macro thread_local_inner {
52-
// used to generate the `LocalKey` value for const-initialized thread locals
52+
// NOTE: we cannot import `LocalKey`, `LazyStorage` or `EagerStorage` with a `use` because that
53+
// can shadow user provided type or type alias with a matching name. Please update the shadowing
54+
// test in `tests/thread.rs` if these types are renamed.
55+
56+
// Used to generate the `LocalKey` value for const-initialized thread locals.
5357
(@key $t:ty, const $init:expr) => {{
5458
const __INIT: $t = $init;
5559

5660
unsafe {
57-
use $crate::mem::needs_drop;
58-
use $crate::thread::LocalKey;
59-
use $crate::thread::local_impl::EagerStorage;
60-
61-
LocalKey::new(const {
62-
if needs_drop::<$t>() {
61+
$crate::thread::LocalKey::new(const {
62+
if $crate::mem::needs_drop::<$t>() {
6363
|_| {
6464
#[thread_local]
65-
static VAL: EagerStorage<$t> = EagerStorage::new(__INIT);
65+
static VAL: $crate::thread::local_impl::EagerStorage<$t>
66+
= $crate::thread::local_impl::EagerStorage::new(__INIT);
6667
VAL.get()
6768
}
6869
} else {
@@ -84,21 +85,19 @@ pub macro thread_local_inner {
8485
}
8586

8687
unsafe {
87-
use $crate::mem::needs_drop;
88-
use $crate::thread::LocalKey;
89-
use $crate::thread::local_impl::LazyStorage;
90-
91-
LocalKey::new(const {
92-
if needs_drop::<$t>() {
88+
$crate::thread::LocalKey::new(const {
89+
if $crate::mem::needs_drop::<$t>() {
9390
|init| {
9491
#[thread_local]
95-
static VAL: LazyStorage<$t, ()> = LazyStorage::new();
92+
static VAL: $crate::thread::local_impl::LazyStorage<$t, ()>
93+
= $crate::thread::local_impl::LazyStorage::new();
9694
VAL.get_or_init(init, __init)
9795
}
9896
} else {
9997
|init| {
10098
#[thread_local]
101-
static VAL: LazyStorage<$t, !> = LazyStorage::new();
99+
static VAL: $crate::thread::local_impl::LazyStorage<$t, !>
100+
= $crate::thread::local_impl::LazyStorage::new();
102101
VAL.get_or_init(init, __init)
103102
}
104103
}

library/std/src/sys/thread_local/os.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ pub macro thread_local_inner {
1515
$crate::thread::local_impl::thread_local_inner!(@key $t, { const INIT_EXPR: $t = $init; INIT_EXPR })
1616
},
1717

18-
// used to generate the `LocalKey` value for `thread_local!`
18+
// NOTE: we cannot import `Storage` or `LocalKey` with a `use` because that can shadow user
19+
// provided type or type alias with a matching name. Please update the shadowing test in
20+
// `tests/thread.rs` if these types are renamed.
21+
22+
// used to generate the `LocalKey` value for `thread_local!`.
1923
(@key $t:ty, $init:expr) => {{
2024
#[inline]
2125
fn __init() -> $t { $init }
2226

27+
// NOTE: this cannot import `LocalKey` or `Storage` with a `use` because that can shadow
28+
// user provided type or type alias with a matching name. Please update the shadowing test
29+
// in `tests/thread.rs` if these types are renamed.
2330
unsafe {
24-
use $crate::thread::LocalKey;
25-
use $crate::thread::local_impl::Storage;
26-
2731
// Inlining does not work on windows-gnu due to linking errors around
2832
// dllimports. See https://github.com/rust-lang/rust/issues/109797.
29-
LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
30-
static VAL: Storage<$t> = Storage::new();
33+
$crate::thread::LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
34+
static VAL: $crate::thread::local_impl::Storage<$t>
35+
= $crate::thread::local_impl::Storage::new();
3136
VAL.get(init, __init)
3237
})
3338
}

library/std/tests/thread.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ fn thread_local_containing_const_statements() {
3838
assert_eq!(REFCELL.take(), 1);
3939
}
4040

41+
#[test]
42+
fn thread_local_hygeiene() {
43+
// Previously `thread_local_inner!` had use imports for `LocalKey`, `Storage`, `EagerStorage`
44+
// and `LazyStorage`. The use imports will shadow a user-provided type or type alias if the
45+
// user-provided type or type alias has the same name. Make sure that this does not happen. See
46+
// <https://github.com/rust-lang/rust/issues/131863>.
47+
//
48+
// NOTE: if the internal implementation details change (i.e. get renamed), this test should be
49+
// updated.
50+
51+
#![allow(dead_code)]
52+
type LocalKey = ();
53+
type Storage = ();
54+
type LazyStorage = ();
55+
type EagerStorage = ();
56+
thread_local! {
57+
static A: LocalKey = const { () };
58+
static B: Storage = const { () };
59+
static C: LazyStorage = const { () };
60+
static D: EagerStorage = const { () };
61+
}
62+
}
63+
4164
#[test]
4265
// Include an ignore list on purpose, so that new platforms don't miss it
4366
#[cfg_attr(

tests/codegen/clone_as_copy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ revisions: DEBUGINFO NODEBUGINFO
2+
//@ compile-flags: -Zunsound-mir-opts
3+
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
24
//@ compile-flags: -O -Cno-prepopulate-passes
35
//@ [DEBUGINFO] compile-flags: -Cdebuginfo=full
46

tests/codegen/try_question_mark_nop.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//@ compile-flags: -O -Z merge-functions=disabled --edition=2021
22
//@ only-x86_64
33
// FIXME: Remove the `min-llvm-version`.
4-
//@ revisions: NINETEEN TWENTY
5-
//@[NINETEEN] min-llvm-version: 19
6-
//@[NINETEEN] ignore-llvm-version: 20-99
7-
//@[TWENTY] min-llvm-version: 20
4+
//@ min-llvm-version: 19
85

96
#![crate_type = "lib"]
107
#![feature(try_blocks)]
@@ -16,12 +13,9 @@ use std::ptr::NonNull;
1613
#[no_mangle]
1714
pub fn option_nop_match_32(x: Option<u32>) -> Option<u32> {
1815
// CHECK: start:
19-
// NINETEEN-NEXT: [[TRUNC:%.*]] = trunc nuw i32 %0 to i1
20-
// NINETEEN-NEXT: [[FIRST:%.*]] = select i1 [[TRUNC]], i32 %0
21-
// NINETEEN-NEXT: insertvalue { i32, i32 } poison, i32 [[FIRST]], 0
22-
// TWENTY-NEXT: insertvalue { i32, i32 } poison, i32 %0, 0
23-
// CHECK-NEXT: insertvalue { i32, i32 }
24-
// CHECK-NEXT: ret { i32, i32 }
16+
// CHECK-NEXT: [[REG1:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
17+
// CHECK-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %1, 1
18+
// CHECK-NEXT: ret { i32, i32 } [[REG2]]
2519
match x {
2620
Some(x) => Some(x),
2721
None => None,

tests/mir-opt/gvn_clone.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ compile-flags: -Zunsound-mir-opts
2+
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
13
//@ test-mir-pass: GVN
24
//@ compile-flags: -Zmir-enable-passes=+InstSimplify-before-inline
35

tests/mir-opt/gvn_clone.{impl#0}-clone.GVN.diff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
- // MIR for `<impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone` before GVN
2-
+ // MIR for `<impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone` after GVN
1+
- // MIR for `<impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone` before GVN
2+
+ // MIR for `<impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone` after GVN
33

4-
fn <impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone(_1: &AllCopy) -> AllCopy {
4+
fn <impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone(_1: &AllCopy) -> AllCopy {
55
debug self => _1;
66
let mut _0: AllCopy;
77
let mut _2: i32;

0 commit comments

Comments
 (0)