Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28fc2ba

Browse files
committedNov 24, 2024
Auto merge of #133423 - jieyouxu:rollup-m3gyoz6, r=jieyouxu
Rollup of 6 pull requests Successful merges: - #132730 (std: allow after-main use of synchronization primitives) - #133105 (only store valid proc macro item for doc link) - #133260 (Constify the `Deref`/`DerefMut` traits, too) - #133297 (Remove legacy bitcode for iOS) - #133298 (Mention that std::fs::remove_dir_all fails on files) - #133384 (add a test for target-feature-ABI warnings in closures and when calling extern fn) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 481b5fa + c50e19b commit 28fc2ba

File tree

26 files changed

+269
-120
lines changed

26 files changed

+269
-120
lines changed
 

‎compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -955,24 +955,7 @@ pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) ->
955955
}
956956
}
957957

958-
/// Embed the bitcode of an LLVM module in the LLVM module itself.
959-
///
960-
/// This is done primarily for iOS where it appears to be standard to compile C
961-
/// code at least with `-fembed-bitcode` which creates two sections in the
962-
/// executable:
963-
///
964-
/// * __LLVM,__bitcode
965-
/// * __LLVM,__cmdline
966-
///
967-
/// It appears *both* of these sections are necessary to get the linker to
968-
/// recognize what's going on. A suitable cmdline value is taken from the
969-
/// target spec.
970-
///
971-
/// Furthermore debug/O1 builds don't actually embed bitcode but rather just
972-
/// embed an empty section.
973-
///
974-
/// Basically all of this is us attempting to follow in the footsteps of clang
975-
/// on iOS. See #35968 for lots more info.
958+
/// Embed the bitcode of an LLVM module for LTO in the LLVM module itself.
976959
unsafe fn embed_bitcode(
977960
cgcx: &CodegenContext<LlvmCodegenBackend>,
978961
llcx: &llvm::Context,

‎compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,9 @@ struct CompiledModules {
432432

433433
fn need_bitcode_in_object(tcx: TyCtxt<'_>) -> bool {
434434
let sess = tcx.sess;
435-
let requested_for_rlib = sess.opts.cg.embed_bitcode
435+
sess.opts.cg.embed_bitcode
436436
&& tcx.crate_types().contains(&CrateType::Rlib)
437-
&& sess.opts.output_types.contains_key(&OutputType::Exe);
438-
let forced_by_target = sess.target.forces_embed_bitcode;
439-
requested_for_rlib || forced_by_target
437+
&& sess.opts.output_types.contains_key(&OutputType::Exe)
440438
}
441439

442440
fn need_pre_lto_bitcode_for_incr_comp(sess: &Session) -> bool {

‎compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
576576
// If this closure is marked `#[inline(always)]`, simply skip adding `#[target_feature]`.
577577
//
578578
// At this point, `unsafe` has already been checked and `#[target_feature]` only affects codegen.
579-
// Emitting both `#[inline(always)]` and `#[target_feature]` can potentially result in an
580-
// ICE, because LLVM errors when the function fails to be inlined due to a target feature
581-
// mismatch.
579+
// Due to LLVM limitations, emitting both `#[inline(always)]` and `#[target_feature]` is *unsound*:
580+
// the function may be inlined into a caller with fewer target features. Also see
581+
// <https://github.com/rust-lang/rust/issues/116573>.
582582
//
583583
// Using `#[inline(always)]` implies that this closure will most likely be inlined into
584584
// its parent function, which effectively inherits the features anyway. Boxing this closure

‎compiler/rustc_resolve/src/late.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4794,14 +4794,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
47944794
let res = self.r.resolve_rustdoc_path(path.as_str(), *ns, self.parent_scope);
47954795
if let Some(res) = res
47964796
&& let Some(def_id) = res.opt_def_id()
4797-
&& !def_id.is_local()
4798-
&& self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
4799-
&& matches!(
4800-
self.r.tcx.sess.opts.resolve_doc_links,
4801-
ResolveDocLinks::ExportedMetadata
4802-
)
4797+
&& self.is_invalid_proc_macro_item_for_doc(def_id)
48034798
{
4804-
// Encoding foreign def ids in proc macro crate metadata will ICE.
4799+
// Encoding def ids in proc macro crate metadata will ICE,
4800+
// because it will only store proc macros for it.
48054801
return None;
48064802
}
48074803
res
@@ -4810,6 +4806,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
48104806
res
48114807
}
48124808

4809+
fn is_invalid_proc_macro_item_for_doc(&self, did: DefId) -> bool {
4810+
if !matches!(self.r.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata)
4811+
|| !self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
4812+
{
4813+
return false;
4814+
}
4815+
let Some(local_did) = did.as_local() else { return true };
4816+
let Some(node_id) = self.r.def_id_to_node_id.get(local_did) else { return true };
4817+
!self.r.proc_macros.contains(node_id)
4818+
}
4819+
48134820
fn resolve_doc_links(&mut self, attrs: &[Attribute], maybe_exported: MaybeExported<'_>) {
48144821
match self.r.tcx.sess.opts.resolve_doc_links {
48154822
ResolveDocLinks::None => return,
@@ -4872,14 +4879,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
48724879
.traits_in_scope(None, &self.parent_scope, SyntaxContext::root(), None)
48734880
.into_iter()
48744881
.filter_map(|tr| {
4875-
if !tr.def_id.is_local()
4876-
&& self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
4877-
&& matches!(
4878-
self.r.tcx.sess.opts.resolve_doc_links,
4879-
ResolveDocLinks::ExportedMetadata
4880-
)
4881-
{
4882-
// Encoding foreign def ids in proc macro crate metadata will ICE.
4882+
if self.is_invalid_proc_macro_item_for_doc(tr.def_id) {
4883+
// Encoding def ids in proc macro crate metadata will ICE.
4884+
// because it will only store proc macros for it.
48834885
return None;
48844886
}
48854887
Some(tr.def_id)

‎compiler/rustc_target/src/spec/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,8 +2327,6 @@ pub struct TargetOptions {
23272327
/// If we give emcc .o files that are actually .bc files it
23282328
/// will 'just work'.
23292329
pub obj_is_bitcode: bool,
2330-
/// Whether the target requires that emitted object code includes bitcode.
2331-
pub forces_embed_bitcode: bool,
23322330
/// Content of the LLVM cmdline section associated with embedded bitcode.
23332331
pub bitcode_llvm_cmdline: StaticCow<str>,
23342332

@@ -2671,7 +2669,6 @@ impl Default for TargetOptions {
26712669
allow_asm: true,
26722670
has_thread_local: false,
26732671
obj_is_bitcode: false,
2674-
forces_embed_bitcode: false,
26752672
bitcode_llvm_cmdline: "".into(),
26762673
min_atomic_width: None,
26772674
max_atomic_width: None,
@@ -3412,7 +3409,6 @@ impl Target {
34123409
key!(main_needs_argc_argv, bool);
34133410
key!(has_thread_local, bool);
34143411
key!(obj_is_bitcode, bool);
3415-
key!(forces_embed_bitcode, bool);
34163412
key!(bitcode_llvm_cmdline);
34173413
key!(max_atomic_width, Option<u64>);
34183414
key!(min_atomic_width, Option<u64>);
@@ -3687,7 +3683,6 @@ impl ToJson for Target {
36873683
target_option_val!(main_needs_argc_argv);
36883684
target_option_val!(has_thread_local);
36893685
target_option_val!(obj_is_bitcode);
3690-
target_option_val!(forces_embed_bitcode);
36913686
target_option_val!(bitcode_llvm_cmdline);
36923687
target_option_val!(min_atomic_width);
36933688
target_option_val!(max_atomic_width);

‎library/core/src/ops/deref.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
#[doc(alias = "&*")]
134134
#[stable(feature = "rust1", since = "1.0.0")]
135135
#[rustc_diagnostic_item = "Deref"]
136+
#[cfg_attr(not(bootstrap), const_trait)]
136137
pub trait Deref {
137138
/// The resulting type after dereferencing.
138139
#[stable(feature = "rust1", since = "1.0.0")]
@@ -147,6 +148,7 @@ pub trait Deref {
147148
fn deref(&self) -> &Self::Target;
148149
}
149150

151+
#[cfg(bootstrap)]
150152
#[stable(feature = "rust1", since = "1.0.0")]
151153
impl<T: ?Sized> Deref for &T {
152154
type Target = T;
@@ -157,9 +159,21 @@ impl<T: ?Sized> Deref for &T {
157159
}
158160
}
159161

162+
#[cfg(not(bootstrap))]
163+
#[stable(feature = "rust1", since = "1.0.0")]
164+
impl<T: ?Sized> const Deref for &T {
165+
type Target = T;
166+
167+
#[rustc_diagnostic_item = "noop_method_deref"]
168+
fn deref(&self) -> &T {
169+
*self
170+
}
171+
}
172+
160173
#[stable(feature = "rust1", since = "1.0.0")]
161174
impl<T: ?Sized> !DerefMut for &T {}
162175

176+
#[cfg(bootstrap)]
163177
#[stable(feature = "rust1", since = "1.0.0")]
164178
impl<T: ?Sized> Deref for &mut T {
165179
type Target = T;
@@ -169,6 +183,16 @@ impl<T: ?Sized> Deref for &mut T {
169183
}
170184
}
171185

186+
#[cfg(not(bootstrap))]
187+
#[stable(feature = "rust1", since = "1.0.0")]
188+
impl<T: ?Sized> const Deref for &mut T {
189+
type Target = T;
190+
191+
fn deref(&self) -> &T {
192+
*self
193+
}
194+
}
195+
172196
/// Used for mutable dereferencing operations, like in `*v = 1;`.
173197
///
174198
/// In addition to being used for explicit dereferencing operations with the
@@ -258,23 +282,46 @@ impl<T: ?Sized> Deref for &mut T {
258282
/// *x = 'b';
259283
/// assert_eq!('b', x.value);
260284
/// ```
285+
#[cfg(not(bootstrap))]
286+
#[lang = "deref_mut"]
287+
#[doc(alias = "*")]
288+
#[stable(feature = "rust1", since = "1.0.0")]
289+
#[const_trait]
290+
pub trait DerefMut: ~const Deref {
291+
/// Mutably dereferences the value.
292+
#[stable(feature = "rust1", since = "1.0.0")]
293+
#[rustc_diagnostic_item = "deref_mut_method"]
294+
fn deref_mut(&mut self) -> &mut Self::Target;
295+
}
296+
297+
/// Bootstrap
261298
#[lang = "deref_mut"]
262299
#[doc(alias = "*")]
263300
#[stable(feature = "rust1", since = "1.0.0")]
301+
#[cfg(bootstrap)]
264302
pub trait DerefMut: Deref {
265303
/// Mutably dereferences the value.
266304
#[stable(feature = "rust1", since = "1.0.0")]
267305
#[rustc_diagnostic_item = "deref_mut_method"]
268306
fn deref_mut(&mut self) -> &mut Self::Target;
269307
}
270308

309+
#[cfg(bootstrap)]
271310
#[stable(feature = "rust1", since = "1.0.0")]
272311
impl<T: ?Sized> DerefMut for &mut T {
273312
fn deref_mut(&mut self) -> &mut T {
274313
*self
275314
}
276315
}
277316

317+
#[cfg(not(bootstrap))]
318+
#[stable(feature = "rust1", since = "1.0.0")]
319+
impl<T: ?Sized> const DerefMut for &mut T {
320+
fn deref_mut(&mut self) -> &mut T {
321+
*self
322+
}
323+
}
324+
278325
/// Perma-unstable marker trait. Indicates that the type has a well-behaved [`Deref`]
279326
/// (and, if applicable, [`DerefMut`]) implementation. This is relied on for soundness
280327
/// of deref patterns.

‎library/std/src/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2804,8 +2804,9 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
28042804
///
28052805
/// See [`fs::remove_file`] and [`fs::remove_dir`].
28062806
///
2807-
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root path.
2807+
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root `path`.
28082808
/// As a result, the directory you are deleting must exist, meaning that this function is not idempotent.
2809+
/// Additionally, `remove_dir_all` will also fail if the `path` is not a directory.
28092810
///
28102811
/// Consider ignoring the error if validating the removal is not required for your use case.
28112812
///

‎library/std/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@
174174
//!
175175
//! - after-main use of thread-locals, which also affects additional features:
176176
//! - [`thread::current()`]
177-
//! - [`thread::scope()`]
178-
//! - [`sync::mpmc`]
179-
//! - [`sync::mpsc`]
180177
//! - before-main stdio file descriptors are not guaranteed to be open on unix platforms
181178
//!
182179
//!

‎library/std/src/sync/mpmc/array.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ impl<T> Channel<T> {
346346
}
347347

348348
// Block the current thread.
349-
let sel = cx.wait_until(deadline);
349+
// SAFETY: the context belongs to the current thread.
350+
let sel = unsafe { cx.wait_until(deadline) };
350351

351352
match sel {
352353
Selected::Waiting => unreachable!(),
@@ -397,7 +398,8 @@ impl<T> Channel<T> {
397398
}
398399

399400
// Block the current thread.
400-
let sel = cx.wait_until(deadline);
401+
// SAFETY: the context belongs to the current thread.
402+
let sel = unsafe { cx.wait_until(deadline) };
401403

402404
match sel {
403405
Selected::Waiting => unreachable!(),

‎library/std/src/sync/mpmc/context.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Context {
6969
inner: Arc::new(Inner {
7070
select: AtomicUsize::new(Selected::Waiting.into()),
7171
packet: AtomicPtr::new(ptr::null_mut()),
72-
thread: thread::current(),
72+
thread: thread::current_or_unnamed(),
7373
thread_id: current_thread_id(),
7474
}),
7575
}
@@ -112,8 +112,11 @@ impl Context {
112112
/// Waits until an operation is selected and returns it.
113113
///
114114
/// If the deadline is reached, `Selected::Aborted` will be selected.
115+
///
116+
/// # Safety
117+
/// This may only be called from the thread this `Context` belongs to.
115118
#[inline]
116-
pub fn wait_until(&self, deadline: Option<Instant>) -> Selected {
119+
pub unsafe fn wait_until(&self, deadline: Option<Instant>) -> Selected {
117120
loop {
118121
// Check whether an operation has been selected.
119122
let sel = Selected::from(self.inner.select.load(Ordering::Acquire));
@@ -126,7 +129,8 @@ impl Context {
126129
let now = Instant::now();
127130

128131
if now < end {
129-
thread::park_timeout(end - now);
132+
// SAFETY: guaranteed by caller.
133+
unsafe { self.inner.thread.park_timeout(end - now) };
130134
} else {
131135
// The deadline has been reached. Try aborting select.
132136
return match self.try_select(Selected::Aborted) {
@@ -135,7 +139,8 @@ impl Context {
135139
};
136140
}
137141
} else {
138-
thread::park();
142+
// SAFETY: guaranteed by caller.
143+
unsafe { self.inner.thread.park() };
139144
}
140145
}
141146
}

‎library/std/src/sync/mpmc/list.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ impl<T> Channel<T> {
444444
}
445445

446446
// Block the current thread.
447-
let sel = cx.wait_until(deadline);
447+
// SAFETY: the context belongs to the current thread.
448+
let sel = unsafe { cx.wait_until(deadline) };
448449

449450
match sel {
450451
Selected::Waiting => unreachable!(),

‎library/std/src/sync/mpmc/zero.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ impl<T> Channel<T> {
190190
drop(inner);
191191

192192
// Block the current thread.
193-
let sel = cx.wait_until(deadline);
193+
// SAFETY: the context belongs to the current thread.
194+
let sel = unsafe { cx.wait_until(deadline) };
194195

195196
match sel {
196197
Selected::Waiting => unreachable!(),
@@ -257,7 +258,8 @@ impl<T> Channel<T> {
257258
drop(inner);
258259

259260
// Block the current thread.
260-
let sel = cx.wait_until(deadline);
261+
// SAFETY: the context belongs to the current thread.
262+
let sel = unsafe { cx.wait_until(deadline) };
261263

262264
match sel {
263265
Selected::Waiting => unreachable!(),

‎library/std/src/sys/sync/once/queue.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const QUEUE_MASK: usize = !STATE_MASK;
9393
// use interior mutability.
9494
#[repr(align(4))] // Ensure the two lower bits are free to use as state bits.
9595
struct Waiter {
96-
thread: Cell<Option<Thread>>,
96+
thread: Thread,
9797
signaled: AtomicBool,
9898
next: Cell<*const Waiter>,
9999
}
@@ -238,7 +238,7 @@ fn wait(
238238
return_on_poisoned: bool,
239239
) -> StateAndQueue {
240240
let node = &Waiter {
241-
thread: Cell::new(Some(thread::current())),
241+
thread: thread::current_or_unnamed(),
242242
signaled: AtomicBool::new(false),
243243
next: Cell::new(ptr::null()),
244244
};
@@ -277,7 +277,8 @@ fn wait(
277277
// can park ourselves, the result could be this thread never gets
278278
// unparked. Luckily `park` comes with the guarantee that if it got
279279
// an `unpark` just before on an unparked thread it does not park.
280-
thread::park();
280+
// SAFETY: we retrieved this handle on the current thread above.
281+
unsafe { node.thread.park() }
281282
}
282283

283284
return state_and_queue.load(Acquire);
@@ -309,7 +310,7 @@ impl Drop for WaiterQueue<'_> {
309310
let mut queue = to_queue(current);
310311
while !queue.is_null() {
311312
let next = (*queue).next.get();
312-
let thread = (*queue).thread.take().unwrap();
313+
let thread = (*queue).thread.clone();
313314
(*queue).signaled.store(true, Release);
314315
thread.unpark();
315316
queue = next;

‎library/std/src/sys/sync/rwlock/queue.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ use crate::mem;
118118
use crate::ptr::{self, NonNull, null_mut, without_provenance_mut};
119119
use crate::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
120120
use crate::sync::atomic::{AtomicBool, AtomicPtr};
121-
use crate::thread::{self, Thread, ThreadId};
121+
use crate::thread::{self, Thread};
122122

123123
/// The atomic lock state.
124124
type AtomicState = AtomicPtr<()>;
@@ -217,9 +217,7 @@ impl Node {
217217
/// Prepare this node for waiting.
218218
fn prepare(&mut self) {
219219
// Fall back to creating an unnamed `Thread` handle to allow locking in TLS destructors.
220-
self.thread.get_or_init(|| {
221-
thread::try_current().unwrap_or_else(|| Thread::new_unnamed(ThreadId::new()))
222-
});
220+
self.thread.get_or_init(thread::current_or_unnamed);
223221
self.completed = AtomicBool::new(false);
224222
}
225223

‎library/std/src/thread/current.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ pub(crate) fn try_current() -> Option<Thread> {
165165
}
166166
}
167167

168+
/// Gets a handle to the thread that invokes it. If the handle stored in thread-
169+
/// local storage was already destroyed, this creates a new unnamed temporary
170+
/// handle to allow thread parking in nearly all situations.
171+
pub(crate) fn current_or_unnamed() -> Thread {
172+
let current = CURRENT.get();
173+
if current > DESTROYED {
174+
unsafe {
175+
let current = ManuallyDrop::new(Thread::from_raw(current));
176+
(*current).clone()
177+
}
178+
} else if current == DESTROYED {
179+
Thread::new_unnamed(id::get_or_init())
180+
} else {
181+
init_current(current)
182+
}
183+
}
184+
168185
/// Gets a handle to the thread that invokes it.
169186
///
170187
/// # Examples

‎library/std/src/thread/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ mod current;
186186

187187
#[stable(feature = "rust1", since = "1.0.0")]
188188
pub use current::current;
189-
pub(crate) use current::{current_id, drop_current, set_current, try_current};
189+
pub(crate) use current::{current_id, current_or_unnamed, drop_current, set_current, try_current};
190190

191191
mod spawnhook;
192192

@@ -1146,9 +1146,9 @@ pub fn park_timeout_ms(ms: u32) {
11461146
#[stable(feature = "park_timeout", since = "1.4.0")]
11471147
pub fn park_timeout(dur: Duration) {
11481148
let guard = PanicGuard;
1149-
// SAFETY: park_timeout is called on the parker owned by this thread.
1149+
// SAFETY: park_timeout is called on a handle owned by this thread.
11501150
unsafe {
1151-
current().0.parker().park_timeout(dur);
1151+
current().park_timeout(dur);
11521152
}
11531153
// No panic occurred, do not abort.
11541154
forget(guard);
@@ -1446,6 +1446,15 @@ impl Thread {
14461446
unsafe { self.0.parker().park() }
14471447
}
14481448

1449+
/// Like the public [`park_timeout`], but callable on any handle. This is
1450+
/// used to allow parking in TLS destructors.
1451+
///
1452+
/// # Safety
1453+
/// May only be called from the thread to which this handle belongs.
1454+
pub(crate) unsafe fn park_timeout(&self, dur: Duration) {
1455+
unsafe { self.0.parker().park_timeout(dur) }
1456+
}
1457+
14491458
/// Atomically makes the handle's token available if it is not already.
14501459
///
14511460
/// Every thread is equipped with some basic low-level blocking support, via

‎library/std/src/thread/scoped.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Builder, JoinInner, Result, Thread, current, park};
1+
use super::{Builder, JoinInner, Result, Thread, current_or_unnamed};
22
use crate::marker::PhantomData;
33
use crate::panic::{AssertUnwindSafe, catch_unwind, resume_unwind};
44
use crate::sync::Arc;
@@ -140,7 +140,7 @@ where
140140
let scope = Scope {
141141
data: Arc::new(ScopeData {
142142
num_running_threads: AtomicUsize::new(0),
143-
main_thread: current(),
143+
main_thread: current_or_unnamed(),
144144
a_thread_panicked: AtomicBool::new(false),
145145
}),
146146
env: PhantomData,
@@ -152,7 +152,8 @@ where
152152

153153
// Wait until all the threads are finished.
154154
while scope.data.num_running_threads.load(Ordering::Acquire) != 0 {
155-
park();
155+
// SAFETY: this is the main thread, the handle belongs to us.
156+
unsafe { scope.data.main_thread.park() };
156157
}
157158

158159
// Throw any panic from `f`, or the return value of `f` if no thread panicked.

‎src/doc/rustc/src/codegen-options/index.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,14 @@ files. It takes one of the following values:
119119
* `n`, `no`, `off` or `false`: omit bitcode from rlibs.
120120

121121
LLVM bitcode is required when rustc is performing link-time optimization (LTO).
122-
It is also required on some targets like iOS ones where vendors look for LLVM
123-
bitcode. Embedded bitcode will appear in rustc-generated object files inside of
124-
a section whose name is defined by the target platform. Most of the time this is
125-
`.llvmbc`.
122+
Embedded bitcode will appear in rustc-generated object files inside of a section
123+
whose name is defined by the target platform. Most of the time this is `.llvmbc`.
126124

127125
The use of `-C embed-bitcode=no` can significantly improve compile times and
128126
reduce generated file sizes if your compilation does not actually need bitcode
129-
(e.g. if you're not compiling for iOS or you're not performing LTO). For these
130-
reasons, Cargo uses `-C embed-bitcode=no` whenever possible. Likewise, if you
131-
are building directly with `rustc` we recommend using `-C embed-bitcode=no`
132-
whenever you are not using LTO.
127+
(e.g. if you're not performing LTO). For these reasons, Cargo uses `-C embed-bitcode=no`
128+
whenever possible. Likewise, if you are building directly with `rustc` we recommend
129+
using `-C embed-bitcode=no` whenever you are not using LTO.
133130

134131
If combined with `-C lto`, `-C embed-bitcode=no` will cause `rustc` to abort
135132
at start-up, because the combination is invalid.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ force-host
2+
//@ no-prefer-dynamic
3+
#![crate_type = "proc-macro"]
4+
5+
extern crate proc_macro;
6+
use proc_macro::TokenStream;
7+
8+
mod view {}
9+
10+
/// [`view`]
11+
#[proc_macro]
12+
pub fn f(_: TokenStream) -> TokenStream {
13+
todo!()
14+
}
15+
16+
/// [`f()`]
17+
#[proc_macro]
18+
pub fn g(_: TokenStream) -> TokenStream {
19+
todo!()
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ aux-build:in-proc-item-comment.rs
2+
//@ check-pass
3+
4+
// issue#132743
5+
6+
extern crate in_proc_item_comment;
7+
8+
pub use in_proc_item_comment::{f, g};

‎tests/ui/issues/issue-25901.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ struct A;
22
struct B;
33

44
static S: &'static B = &A;
5-
//~^ ERROR cannot perform deref coercion
5+
//~^ ERROR cannot call conditionally-const method
66

77
use std::ops::Deref;
88

‎tests/ui/issues/issue-25901.stderr

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
error[E0015]: cannot perform deref coercion on `A` in statics
1+
error[E0658]: cannot call conditionally-const method `<A as Deref>::deref` in statics
22
--> $DIR/issue-25901.rs:4:24
33
|
44
LL | static S: &'static B = &A;
55
| ^^
66
|
7-
= note: attempting to deref into `B`
8-
note: deref defined here
9-
--> $DIR/issue-25901.rs:10:5
10-
|
11-
LL | type Target = B;
12-
| ^^^^^^^^^^^
13-
note: impl defined here, but it is not `const`
14-
--> $DIR/issue-25901.rs:9:1
15-
|
16-
LL | impl Deref for A {
17-
| ^^^^^^^^^^^^^^^^
18-
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
19-
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
7+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
8+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2010

2111
error: aborting due to 1 previous error
2212

23-
For more information about this error, try `rustc --explain E0015`.
13+
For more information about this error, try `rustc --explain E0658`.

‎tests/ui/self/arbitrary-self-from-method-substs-ice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Foo {
1111
//~^ ERROR invalid generic `self` parameter type
1212
//~| ERROR destructor of `R` cannot be evaluated at compile-time
1313
self.0
14-
//~^ ERROR cannot call non-const fn `<R as Deref>::deref` in constant function
14+
//~^ ERROR cannot call conditionally-const method `<R as Deref>::deref` in constant function
1515
}
1616
}
1717

‎tests/ui/self/arbitrary-self-from-method-substs-ice.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
error[E0015]: cannot call non-const fn `<R as Deref>::deref` in constant functions
1+
error[E0658]: cannot call conditionally-const method `<R as Deref>::deref` in constant functions
22
--> $DIR/arbitrary-self-from-method-substs-ice.rs:13:9
33
|
44
LL | self.0
55
| ^^^^^^
66
|
7-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
7+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
8+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
810

911
error[E0493]: destructor of `R` cannot be evaluated at compile-time
1012
--> $DIR/arbitrary-self-from-method-substs-ice.rs:10:43
@@ -26,5 +28,5 @@ LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 {
2628

2729
error: aborting due to 3 previous errors
2830

29-
Some errors have detailed explanations: E0015, E0493, E0801.
30-
For more information about an error, try `rustc --explain E0015`.
31+
Some errors have detailed explanations: E0493, E0658, E0801.
32+
For more information about an error, try `rustc --explain E0493`.

‎tests/ui/simd-abi-checks.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#![feature(avx512_target_feature)]
66
#![feature(portable_simd)]
7+
#![feature(target_feature_11, simd_ffi)]
78
#![allow(improper_ctypes_definitions)]
89

910
use std::arch::x86_64::*;
@@ -50,6 +51,14 @@ unsafe fn test() {
5051
as_f64x8(arg);
5152
}
5253

54+
#[target_feature(enable = "avx")]
55+
unsafe fn in_closure() -> impl FnOnce() -> __m256 {
56+
#[inline(always)] // this disables target-feature inheritance
57+
|| g()
58+
//~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
59+
//~| WARNING this was previously accepted by the compiler
60+
}
61+
5362
fn main() {
5463
unsafe {
5564
f(g());
@@ -78,4 +87,24 @@ fn main() {
7887
//~| WARNING this was previously accepted by the compiler
7988
//~| WARNING this was previously accepted by the compiler
8089
}
90+
91+
unsafe {
92+
in_closure()();
93+
}
94+
95+
unsafe {
96+
#[expect(improper_ctypes)]
97+
extern "C" {
98+
fn some_extern() -> __m256;
99+
}
100+
some_extern();
101+
//~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
102+
//~| WARNING this was previously accepted by the compiler
103+
}
104+
}
105+
106+
#[no_mangle]
107+
#[target_feature(enable = "avx")]
108+
fn some_extern() -> __m256 {
109+
todo!()
81110
}

‎tests/ui/simd-abi-checks.stderr

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
2-
--> $DIR/simd-abi-checks.rs:55:11
2+
--> $DIR/simd-abi-checks.rs:64:11
33
|
44
LL | f(g());
55
| ^^^ function called here
@@ -10,7 +10,7 @@ LL | f(g());
1010
= note: `#[warn(abi_unsupported_vector_types)]` on by default
1111

1212
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
13-
--> $DIR/simd-abi-checks.rs:55:9
13+
--> $DIR/simd-abi-checks.rs:64:9
1414
|
1515
LL | f(g());
1616
| ^^^^^^ function called here
@@ -20,7 +20,7 @@ LL | f(g());
2020
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
2121

2222
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
23-
--> $DIR/simd-abi-checks.rs:63:14
23+
--> $DIR/simd-abi-checks.rs:72:14
2424
|
2525
LL | gavx(favx());
2626
| ^^^^^^ function called here
@@ -30,7 +30,7 @@ LL | gavx(favx());
3030
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
3131

3232
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
33-
--> $DIR/simd-abi-checks.rs:63:9
33+
--> $DIR/simd-abi-checks.rs:72:9
3434
|
3535
LL | gavx(favx());
3636
| ^^^^^^^^^^^^ function called here
@@ -40,7 +40,7 @@ LL | gavx(favx());
4040
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
4141

4242
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
43-
--> $DIR/simd-abi-checks.rs:75:19
43+
--> $DIR/simd-abi-checks.rs:84:19
4444
|
4545
LL | w(Wrapper(g()));
4646
| ^^^ function called here
@@ -50,7 +50,7 @@ LL | w(Wrapper(g()));
5050
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
5151

5252
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
53-
--> $DIR/simd-abi-checks.rs:75:9
53+
--> $DIR/simd-abi-checks.rs:84:9
5454
|
5555
LL | w(Wrapper(g()));
5656
| ^^^^^^^^^^^^^^^ function called here
@@ -59,8 +59,18 @@ LL | w(Wrapper(g()));
5959
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
6060
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
6161

62+
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
63+
--> $DIR/simd-abi-checks.rs:100:9
64+
|
65+
LL | some_extern();
66+
| ^^^^^^^^^^^^^ function called here
67+
|
68+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
69+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
70+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
71+
6272
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
63-
--> $DIR/simd-abi-checks.rs:26:1
73+
--> $DIR/simd-abi-checks.rs:27:1
6474
|
6575
LL | unsafe extern "C" fn g() -> __m256 {
6676
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -70,7 +80,7 @@ LL | unsafe extern "C" fn g() -> __m256 {
7080
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
7181

7282
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
73-
--> $DIR/simd-abi-checks.rs:20:1
83+
--> $DIR/simd-abi-checks.rs:21:1
7484
|
7585
LL | unsafe extern "C" fn f(_: __m256) {
7686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -80,7 +90,7 @@ LL | unsafe extern "C" fn f(_: __m256) {
8090
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
8191

8292
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
83-
--> $DIR/simd-abi-checks.rs:14:1
93+
--> $DIR/simd-abi-checks.rs:15:1
8494
|
8595
LL | unsafe extern "C" fn w(_: Wrapper) {
8696
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -89,11 +99,21 @@ LL | unsafe extern "C" fn w(_: Wrapper) {
8999
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
90100
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
91101

92-
warning: 9 warnings emitted
102+
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
103+
--> $DIR/simd-abi-checks.rs:57:8
104+
|
105+
LL | || g()
106+
| ^^^ function called here
107+
|
108+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
109+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
110+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
111+
112+
warning: 11 warnings emitted
93113

94114
Future incompatibility report: Future breakage diagnostic:
95115
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
96-
--> $DIR/simd-abi-checks.rs:55:11
116+
--> $DIR/simd-abi-checks.rs:64:11
97117
|
98118
LL | f(g());
99119
| ^^^ function called here
@@ -105,7 +125,7 @@ LL | f(g());
105125

106126
Future breakage diagnostic:
107127
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
108-
--> $DIR/simd-abi-checks.rs:55:9
128+
--> $DIR/simd-abi-checks.rs:64:9
109129
|
110130
LL | f(g());
111131
| ^^^^^^ function called here
@@ -117,7 +137,7 @@ LL | f(g());
117137

118138
Future breakage diagnostic:
119139
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
120-
--> $DIR/simd-abi-checks.rs:63:14
140+
--> $DIR/simd-abi-checks.rs:72:14
121141
|
122142
LL | gavx(favx());
123143
| ^^^^^^ function called here
@@ -129,7 +149,7 @@ LL | gavx(favx());
129149

130150
Future breakage diagnostic:
131151
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
132-
--> $DIR/simd-abi-checks.rs:63:9
152+
--> $DIR/simd-abi-checks.rs:72:9
133153
|
134154
LL | gavx(favx());
135155
| ^^^^^^^^^^^^ function called here
@@ -141,7 +161,7 @@ LL | gavx(favx());
141161

142162
Future breakage diagnostic:
143163
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
144-
--> $DIR/simd-abi-checks.rs:75:19
164+
--> $DIR/simd-abi-checks.rs:84:19
145165
|
146166
LL | w(Wrapper(g()));
147167
| ^^^ function called here
@@ -153,7 +173,7 @@ LL | w(Wrapper(g()));
153173

154174
Future breakage diagnostic:
155175
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
156-
--> $DIR/simd-abi-checks.rs:75:9
176+
--> $DIR/simd-abi-checks.rs:84:9
157177
|
158178
LL | w(Wrapper(g()));
159179
| ^^^^^^^^^^^^^^^ function called here
@@ -163,9 +183,21 @@ LL | w(Wrapper(g()));
163183
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
164184
= note: `#[warn(abi_unsupported_vector_types)]` on by default
165185

186+
Future breakage diagnostic:
187+
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
188+
--> $DIR/simd-abi-checks.rs:100:9
189+
|
190+
LL | some_extern();
191+
| ^^^^^^^^^^^^^ function called here
192+
|
193+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
194+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
195+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
196+
= note: `#[warn(abi_unsupported_vector_types)]` on by default
197+
166198
Future breakage diagnostic:
167199
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
168-
--> $DIR/simd-abi-checks.rs:26:1
200+
--> $DIR/simd-abi-checks.rs:27:1
169201
|
170202
LL | unsafe extern "C" fn g() -> __m256 {
171203
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -177,7 +209,7 @@ LL | unsafe extern "C" fn g() -> __m256 {
177209

178210
Future breakage diagnostic:
179211
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
180-
--> $DIR/simd-abi-checks.rs:20:1
212+
--> $DIR/simd-abi-checks.rs:21:1
181213
|
182214
LL | unsafe extern "C" fn f(_: __m256) {
183215
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -189,7 +221,7 @@ LL | unsafe extern "C" fn f(_: __m256) {
189221

190222
Future breakage diagnostic:
191223
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
192-
--> $DIR/simd-abi-checks.rs:14:1
224+
--> $DIR/simd-abi-checks.rs:15:1
193225
|
194226
LL | unsafe extern "C" fn w(_: Wrapper) {
195227
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -199,3 +231,15 @@ LL | unsafe extern "C" fn w(_: Wrapper) {
199231
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
200232
= note: `#[warn(abi_unsupported_vector_types)]` on by default
201233

234+
Future breakage diagnostic:
235+
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
236+
--> $DIR/simd-abi-checks.rs:57:8
237+
|
238+
LL | || g()
239+
| ^^^ function called here
240+
|
241+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
242+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
243+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
244+
= note: `#[warn(abi_unsupported_vector_types)]` on by default
245+

0 commit comments

Comments
 (0)
Please sign in to comment.