Skip to content

Commit 59372f2

Browse files
committed
Auto merge of #141255 - matthiaskrgr:rollup-ravsgen, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #131200 (Handle `rustc_query_system` cases of `rustc::potential_query_instability` lint) - #141244 (windows: document that we rely on an undocumented property of GetUserProfileDirectoryW) - #141247 (skip compiler tools sanity checks on certain commands) - #141248 (fix data race in ReentrantLock fallback for targets without 64bit atomics) - #141249 (introduce common macro for `MutVisitor` and `Visitor` to dedup code) - #141253 (Warning added when dependency crate has async drop types, and the feature is disabled) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e5a2a6a + e95315d commit 59372f2

File tree

21 files changed

+182
-56
lines changed

21 files changed

+182
-56
lines changed

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(associated_type_defaults)]
1616
#![feature(box_patterns)]
1717
#![feature(if_let_guard)]
18+
#![feature(macro_metavar_expr)]
1819
#![feature(negative_impls)]
1920
#![feature(never_type)]
2021
#![feature(rustdoc_internals)]

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use thin_vec::ThinVec;
2020
use crate::ast::*;
2121
use crate::ptr::P;
2222
use crate::tokenstream::*;
23-
use crate::visit::{AssocCtxt, BoundKind, FnCtxt};
23+
use crate::visit::{AssocCtxt, BoundKind, FnCtxt, try_visit};
2424

2525
pub trait ExpectOne<A: Array> {
2626
fn expect_one(self, err: &'static str) -> A::Item;
@@ -388,6 +388,8 @@ pub trait MutVisitor: Sized {
388388
}
389389
}
390390

391+
super::common_visitor_and_walkers!((mut) MutVisitor);
392+
391393
/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
392394
/// when using a `flat_map_*` or `filter_map_*` method within a `visit_`
393395
/// method.
@@ -777,15 +779,6 @@ fn visit_defaultness<T: MutVisitor>(vis: &mut T, defaultness: &mut Defaultness)
777779
}
778780
}
779781

780-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
781-
fn visit_safety<T: MutVisitor>(vis: &mut T, safety: &mut Safety) {
782-
match safety {
783-
Safety::Unsafe(span) => vis.visit_span(span),
784-
Safety::Safe(span) => vis.visit_span(span),
785-
Safety::Default => {}
786-
}
787-
}
788-
789782
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
790783
fn visit_polarity<T: MutVisitor>(vis: &mut T, polarity: &mut ImplPolarity) {
791784
match polarity {
@@ -794,14 +787,6 @@ fn visit_polarity<T: MutVisitor>(vis: &mut T, polarity: &mut ImplPolarity) {
794787
}
795788
}
796789

797-
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
798-
fn visit_constness<T: MutVisitor>(vis: &mut T, constness: &mut Const) {
799-
match constness {
800-
Const::Yes(span) => vis.visit_span(span),
801-
Const::No => {}
802-
}
803-
}
804-
805790
fn walk_closure_binder<T: MutVisitor>(vis: &mut T, binder: &mut ClosureBinder) {
806791
match binder {
807792
ClosureBinder::NotPresent => {}
@@ -940,15 +925,6 @@ pub fn walk_flat_map_generic_param<T: MutVisitor>(
940925
smallvec![param]
941926
}
942927

943-
fn walk_label<T: MutVisitor>(vis: &mut T, Label { ident }: &mut Label) {
944-
vis.visit_ident(ident);
945-
}
946-
947-
fn walk_lifetime<T: MutVisitor>(vis: &mut T, Lifetime { id, ident }: &mut Lifetime) {
948-
vis.visit_id(id);
949-
vis.visit_ident(ident);
950-
}
951-
952928
fn walk_generics<T: MutVisitor>(vis: &mut T, generics: &mut Generics) {
953929
let Generics { params, where_clause, span } = generics;
954930
params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
@@ -1340,13 +1316,6 @@ fn walk_const_item<T: MutVisitor>(vis: &mut T, item: &mut ConstItem) {
13401316
walk_define_opaques(vis, define_opaque);
13411317
}
13421318

1343-
fn walk_fn_header<T: MutVisitor>(vis: &mut T, header: &mut FnHeader) {
1344-
let FnHeader { safety, coroutine_kind, constness, ext: _ } = header;
1345-
visit_constness(vis, constness);
1346-
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
1347-
visit_safety(vis, safety);
1348-
}
1349-
13501319
pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
13511320
let Crate { attrs, items, spans, id, is_placeholder: _ } = krate;
13521321
vis.visit_id(id);

compiler/rustc_ast/src/visit.rs

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,75 @@ pub trait Visitor<'ast>: Sized {
315315
}
316316
}
317317

318+
#[macro_export]
319+
macro_rules! common_visitor_and_walkers {
320+
($(($mut: ident))? $Visitor:ident$(<$lt:lifetime>)?) => {
321+
// this is only used by the MutVisitor. We include this symmetry here to make writing other functions easier
322+
$(${ignore($lt)}
323+
#[expect(unused, rustc::pass_by_value)]
324+
#[inline]
325+
)?
326+
fn visit_span<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, span: &$($lt)? $($mut)? Span) $(-> <V as Visitor<$lt>>::Result)? {
327+
$(
328+
let _ = stringify!($mut);
329+
visitor.visit_span(span);
330+
)?
331+
$(${ignore($lt)}V::Result::output())?
332+
}
333+
334+
// this is only used by the MutVisitor. We include this symmetry here to make writing other functions easier
335+
$(${ignore($lt)}
336+
#[expect(unused, rustc::pass_by_value)]
337+
#[inline]
338+
)?
339+
fn visit_id<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, id: &$($lt)? $($mut)? NodeId) $(-> <V as Visitor<$lt>>::Result)? {
340+
$(
341+
let _ = stringify!($mut);
342+
visitor.visit_id(id);
343+
)?
344+
$(${ignore($lt)}V::Result::output())?
345+
}
346+
347+
// this is only used by the MutVisitor. We include this symmetry here to make writing other functions easier
348+
fn visit_safety<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, safety: &$($lt)? $($mut)? Safety) $(-> <V as Visitor<$lt>>::Result)? {
349+
match safety {
350+
Safety::Unsafe(span) => visit_span(vis, span),
351+
Safety::Safe(span) => visit_span(vis, span),
352+
Safety::Default => { $(${ignore($lt)}V::Result::output())? }
353+
}
354+
}
355+
356+
fn visit_constness<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, constness: &$($lt)? $($mut)? Const) $(-> <V as Visitor<$lt>>::Result)? {
357+
match constness {
358+
Const::Yes(span) => visit_span(vis, span),
359+
Const::No => {
360+
$(<V as Visitor<$lt>>::Result::output())?
361+
}
362+
}
363+
}
364+
365+
pub fn walk_label<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, Label { ident }: &$($lt)? $($mut)? Label) $(-> <V as Visitor<$lt>>::Result)? {
366+
visitor.visit_ident(ident)
367+
}
368+
369+
pub fn walk_fn_header<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, header: &$($lt)? $($mut)? FnHeader) $(-> <V as Visitor<$lt>>::Result)? {
370+
let FnHeader { safety, coroutine_kind, constness, ext: _ } = header;
371+
try_visit!(visit_constness(visitor, constness));
372+
if let Some(coroutine_kind) = coroutine_kind {
373+
try_visit!(visitor.visit_coroutine_kind(coroutine_kind));
374+
}
375+
visit_safety(visitor, safety)
376+
}
377+
378+
pub fn walk_lifetime<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, Lifetime { id, ident }: &$($lt)? $($mut)? Lifetime) $(-> <V as Visitor<$lt>>::Result)? {
379+
try_visit!(visit_id(visitor, id));
380+
visitor.visit_ident(ident)
381+
}
382+
};
383+
}
384+
385+
common_visitor_and_walkers!(Visitor<'a>);
386+
318387
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
319388
let Crate { attrs, items, spans: _, id: _, is_placeholder: _ } = krate;
320389
walk_list!(visitor, visit_attribute, attrs);
@@ -334,15 +403,6 @@ pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) -> V::R
334403
V::Result::output()
335404
}
336405

337-
pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, Label { ident }: &'a Label) -> V::Result {
338-
visitor.visit_ident(ident)
339-
}
340-
341-
pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) -> V::Result {
342-
let Lifetime { id: _, ident } = lifetime;
343-
visitor.visit_ident(ident)
344-
}
345-
346406
pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) -> V::Result
347407
where
348408
V: Visitor<'a>,
@@ -926,12 +986,6 @@ pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy)
926986
V::Result::output()
927987
}
928988

929-
pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result {
930-
let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header;
931-
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
932-
V::Result::output()
933-
}
934-
935989
pub fn walk_fn_decl<'a, V: Visitor<'a>>(
936990
visitor: &mut V,
937991
FnDecl { inputs, output }: &'a FnDecl,

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ fn configure_and_expand(
282282
resolver.resolve_crate(&krate);
283283

284284
CStore::from_tcx(tcx).report_incompatible_target_modifiers(tcx, &krate);
285+
CStore::from_tcx(tcx).report_incompatible_async_drop_feature(tcx, &krate);
285286
krate
286287
}
287288

compiler/rustc_metadata/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
metadata_as_needed_compatibility =
22
linking modifier `as-needed` is only compatible with `dylib` and `framework` linking kinds
33
4+
metadata_async_drop_types_in_dependency =
5+
found async drop types in dependecy `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`
6+
.help = if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used
7+
48
metadata_bad_panic_strategy =
59
the linked panic runtime `{$runtime}` is not compiled with this crate's panic strategy `{$strategy}`
610

compiler/rustc_metadata/src/creader.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,27 @@ impl CStore {
473473
}
474474
}
475475

476+
// Report about async drop types in dependency if async drop feature is disabled
477+
pub fn report_incompatible_async_drop_feature(&self, tcx: TyCtxt<'_>, krate: &Crate) {
478+
if tcx.features().async_drop() {
479+
return;
480+
}
481+
for (_cnum, data) in self.iter_crate_data() {
482+
if data.is_proc_macro_crate() {
483+
continue;
484+
}
485+
if data.has_async_drops() {
486+
let extern_crate = data.name();
487+
let local_crate = tcx.crate_name(LOCAL_CRATE);
488+
tcx.dcx().emit_warn(errors::AsyncDropTypesInDependency {
489+
span: krate.spans.inner_span.shrink_to_lo(),
490+
extern_crate,
491+
local_crate,
492+
});
493+
}
494+
}
495+
}
496+
476497
pub fn new(metadata_loader: Box<MetadataLoaderDyn>) -> CStore {
477498
CStore {
478499
metadata_loader,

compiler/rustc_metadata/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,13 @@ pub struct UnknownTargetModifierUnsafeAllowed {
811811
pub span: Span,
812812
pub flag_name: String,
813813
}
814+
815+
#[derive(Diagnostic)]
816+
#[diag(metadata_async_drop_types_in_dependency)]
817+
#[help]
818+
pub struct AsyncDropTypesInDependency {
819+
#[primary_span]
820+
pub span: Span,
821+
pub extern_crate: Symbol,
822+
pub local_crate: Symbol,
823+
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,10 @@ impl CrateMetadata {
19841984
self.root.header.hash
19851985
}
19861986

1987+
pub(crate) fn has_async_drops(&self) -> bool {
1988+
self.root.tables.adt_async_destructor.len > 0
1989+
}
1990+
19871991
fn num_def_ids(&self) -> usize {
19881992
self.root.tables.def_keys.size()
19891993
}

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,8 @@ fn panic_on_forbidden_read<D: Deps>(data: &DepGraphData<D>, dep_node_index: DepN
14331433
&& let Some(nodes) = &data.current.nodes_in_current_session
14341434
{
14351435
// Try to find it among the nodes allocated so far in this session
1436+
// This is OK, there's only ever one node result possible so this is deterministic.
1437+
#[allow(rustc::potential_query_instability)]
14361438
if let Some((node, _)) = nodes.lock().iter().find(|&(_, index)| *index == dep_node_index) {
14371439
dep_node = Some(*node);
14381440
}

compiler/rustc_query_system/src/dep_graph/serialized.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,8 @@ impl<D: Deps> EncoderState<D> {
784784
) {
785785
if let Some(record_stats) = &self.stats {
786786
let record_stats = record_stats.lock();
787+
// `stats` is sorted below so we can allow this lint here.
788+
#[allow(rustc::potential_query_instability)]
787789
let mut stats: Vec<_> = record_stats.values().collect();
788790
stats.sort_by_key(|s| -(s.node_counter as i64));
789791

compiler/rustc_query_system/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tidy-alphabetical-start
2-
#![allow(rustc::potential_query_instability, internal_features)]
2+
#![allow(internal_features)]
33
#![feature(assert_matches)]
44
#![feature(core_intrinsics)]
55
#![feature(dropck_eyepatch)]

compiler/rustc_query_system/src/query/job.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ pub fn break_query_cycles<I: Clone + Debug>(
510510
registry: &rayon_core::Registry,
511511
) {
512512
let mut wakelist = Vec::new();
513+
// It is OK per the comments:
514+
// - https://github.com/rust-lang/rust/pull/131200#issuecomment-2798854932
515+
// - https://github.com/rust-lang/rust/pull/131200#issuecomment-2798866392
516+
#[allow(rustc::potential_query_instability)]
513517
let mut jobs: Vec<QueryJobId> = query_map.keys().cloned().collect();
514518

515519
let mut found_cycle = false;

library/std/src/sync/reentrant_lock.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ cfg_if!(
136136
// we only ever read from the tid if `tls_addr` matches the current
137137
// TLS address. In that case, either the tid has been set by
138138
// the current thread, or by a thread that has terminated before
139-
// the current thread was created. In either case, no further
139+
// the current thread's `tls_addr` was allocated. In either case, no further
140140
// synchronization is needed (as per <https://github.com/rust-lang/miri/issues/3450>)
141141
tls_addr: Atomic<usize>,
142142
tid: UnsafeCell<u64>,
@@ -154,8 +154,12 @@ cfg_if!(
154154
// NOTE: This assumes that `owner` is the ID of the current
155155
// thread, and may spuriously return `false` if that's not the case.
156156
fn contains(&self, owner: ThreadId) -> bool {
157+
// We must call `tls_addr()` *before* doing the load to ensure that if we reuse an
158+
// earlier thread's address, the `tls_addr.load()` below happens-after everything
159+
// that thread did.
160+
let tls_addr = tls_addr();
157161
// SAFETY: See the comments in the struct definition.
158-
self.tls_addr.load(Ordering::Relaxed) == tls_addr()
162+
self.tls_addr.load(Ordering::Relaxed) == tls_addr
159163
&& unsafe { *self.tid.get() } == owner.as_u64().get()
160164
}
161165

library/std/src/sys/pal/windows/os.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ fn home_dir_crt() -> Option<PathBuf> {
202202
|buf, mut sz| {
203203
// GetUserProfileDirectoryW does not quite use the usual protocol for
204204
// negotiating the buffer size, so we have to translate.
205+
// FIXME(#141254): We rely on the *undocumented* property that this function will
206+
// always set the size, not just on failure.
205207
match c::GetUserProfileDirectoryW(
206208
ptr::without_provenance_mut(CURRENT_PROCESS_TOKEN),
207209
buf,

src/bootstrap/src/core/sanity.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ use std::ffi::{OsStr, OsString};
1313
use std::path::PathBuf;
1414
use std::{env, fs};
1515

16-
use crate::Build;
1716
#[cfg(not(test))]
1817
use crate::builder::Builder;
1918
use crate::builder::Kind;
2019
#[cfg(not(test))]
2120
use crate::core::build_steps::tool;
2221
use crate::core::config::Target;
2322
use crate::utils::exec::command;
23+
use crate::{Build, Subcommand};
2424

2525
pub struct Finder {
2626
cache: HashMap<OsString, Option<PathBuf>>,
@@ -205,6 +205,20 @@ than building it.
205205
.map(|s| s.to_string())
206206
.collect();
207207

208+
// Compiler tools like `cc` and `ar` are not configured for cross-targets on certain subcommands
209+
// because they are not needed.
210+
//
211+
// See `cc_detect::find` for more details.
212+
let skip_tools_checks = build.config.dry_run()
213+
|| matches!(
214+
build.config.cmd,
215+
Subcommand::Clean { .. }
216+
| Subcommand::Check { .. }
217+
| Subcommand::Suggest { .. }
218+
| Subcommand::Format { .. }
219+
| Subcommand::Setup { .. }
220+
);
221+
208222
// We're gonna build some custom C code here and there, host triples
209223
// also build some C++ shims for LLVM so we need a C++ compiler.
210224
for target in &build.targets {
@@ -278,15 +292,15 @@ than building it.
278292
}
279293
}
280294

281-
if !build.config.dry_run() {
295+
if !skip_tools_checks {
282296
cmd_finder.must_have(build.cc(*target));
283297
if let Some(ar) = build.ar(*target) {
284298
cmd_finder.must_have(ar);
285299
}
286300
}
287301
}
288302

289-
if !build.config.dry_run() {
303+
if !skip_tools_checks {
290304
for host in &build.hosts {
291305
cmd_finder.must_have(build.cxx(*host).unwrap());
292306

src/tools/miri/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ Definite bugs found:
580580
* [Weak-memory-induced memory leak in Windows thread-local storage](https://github.com/rust-lang/rust/pull/124281)
581581
* [A bug in the new `RwLock::downgrade` implementation](https://rust-lang.zulipchat.com/#narrow/channel/269128-miri/topic/Miri.20error.20library.20test) (caught by Miri before it landed in the Rust repo)
582582
* [Mockall reading unintialized memory when mocking `std::io::Read::read`, even if all expectations are satisfied](https://github.com/asomers/mockall/issues/647) (caught by Miri running Tokio's test suite)
583+
* [`ReentrantLock` not correctly dealing with reuse of addresses for TLS storage of different threads](https://github.com/rust-lang/rust/pull/141248)
583584

584585
Violations of [Stacked Borrows] found that are likely bugs (but Stacked Borrows is currently just an experiment):
585586

0 commit comments

Comments
 (0)