Skip to content

Commit 59372f2

Browse files
committed
Auto merge of rust-lang#141255 - matthiaskrgr:rollup-ravsgen, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#131200 (Handle `rustc_query_system` cases of `rustc::potential_query_instability` lint) - rust-lang#141244 (windows: document that we rely on an undocumented property of GetUserProfileDirectoryW) - rust-lang#141247 (skip compiler tools sanity checks on certain commands) - rust-lang#141248 (fix data race in ReentrantLock fallback for targets without 64bit atomics) - rust-lang#141249 (introduce common macro for `MutVisitor` and `Visitor` to dedup code) - rust-lang#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

0 commit comments

Comments
 (0)